Skip to content

Commit

Permalink
Merge pull request #92 from zomberg/tests
Browse files Browse the repository at this point in the history
Added tests for AnnotationRegistry class.
  • Loading branch information
mikeSimonson authored Aug 31, 2016
2 parents 2e1b1f7 + f41917a commit f9cf507
Showing 1 changed file with 68 additions and 0 deletions.
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();
}
}

0 comments on commit f9cf507

Please sign in to comment.