Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for AnnotationRegistry class. #92

Merged
merged 2 commits into from
Aug 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Doctrine\Tests\Common\Annotations;

use Doctrine\Common\Annotations\AnnotationRegistry;

class AnnotationRegistryTest extends \PHPUnit_Framework_TestCase
{
protected $class = 'Doctrine\Common\Annotations\AnnotationRegistry';

/**
* @runInSeparateProcess
*/
public function testReset()
{
$data = array('foo' => 'bar');

$this->setStaticField($this->class, 'autoloadNamespaces', $data);
$this->setStaticField($this->class, 'loaders', $data);

$this->assertEquals($data, $this->getStaticField($this->class, 'autoloadNamespaces'));
$this->assertEquals($data, $this->getStaticField($this->class, 'loaders'));

AnnotationRegistry::reset();

$this->assertEmpty($this->getStaticField($this->class, 'autoloadNamespaces'));
$this->assertEmpty($this->getStaticField($this->class, 'loaders'));
}

/**
* @runInSeparateProcess
*/
public function testRegisterAutoloadNamespaces()
{
$this->setStaticField($this->class, 'autoloadNamespaces', array('foo' => 'bar'));

AnnotationRegistry::registerAutoloadNamespaces(array('test' => 'bar'));
$this->assertEquals(array('foo' => 'bar', 'test' => 'bar'), $this->getStaticField($this->class, 'autoloadNamespaces'));
}

/**
* @runInSeparateProcess
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage A callable is expected in AnnotationRegistry::registerLoader().
*/
public function testRegisterLoaderNoCallable()
{
AnnotationRegistry::registerLoader('test');
}

protected function setStaticField($class, $field, $value)
{
$reflection = new \ReflectionProperty($class, $field);

$reflection->setAccessible(true);
$reflection->setValue(null, $value);
}

protected function getStaticField($class, $field)
{
$reflection = new \ReflectionProperty($class, $field);

$reflection->setAccessible(true);

return $reflection->getValue();
}
}