-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from zomberg/tests
Added tests for AnnotationRegistry class.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |