From c4160c90a317e289fe46ce233091214b4d993960 Mon Sep 17 00:00:00 2001 From: Vyacheslav Pavlov Date: Thu, 21 Jul 2016 11:57:10 +0300 Subject: [PATCH 1/2] Added tests for AnnotationRegistry class. --- .../Annotations/AnnotationRegistryTest.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php diff --git a/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php b/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php new file mode 100644 index 000000000..590476c63 --- /dev/null +++ b/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php @@ -0,0 +1,71 @@ + 'bar'); + + $originalAutoloadNamespaces = $this->getStaticField($this->class, 'autoloadNamespaces'); + $originalLoaders = $this->getStaticField($this->class, 'loaders'); + + $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')); + + // restore original values because some tests depend on this values + $this->setStaticField($this->class, 'autoloadNamespaces', $originalAutoloadNamespaces); + $this->setStaticField($this->class, 'loaders', $originalLoaders); + } + + public function testRegisterAutoloadNamespaces() + { + $originalAutoloadNamespaces = $this->getStaticField($this->class, 'autoloadNamespaces'); + $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')); + + // restore original value because some tests depend on this value + $this->setStaticField($this->class, 'autoloadNamespaces', $originalAutoloadNamespaces); + } + + /** + * @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(); + } +} \ No newline at end of file From f41917a0b4055773c29a79aa02b6c790a0b1e044 Mon Sep 17 00:00:00 2001 From: Vyacheslav Pavlov Date: Thu, 21 Jul 2016 12:44:36 +0300 Subject: [PATCH 2/2] Added @runInSeparateProcess for tests of static --- .../Annotations/AnnotationRegistryTest.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php b/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php index 590476c63..7ae5ed079 100644 --- a/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php @@ -8,13 +8,13 @@ class AnnotationRegistryTest extends \PHPUnit_Framework_TestCase { protected $class = 'Doctrine\Common\Annotations\AnnotationRegistry'; + /** + * @runInSeparateProcess + */ public function testReset() { $data = array('foo' => 'bar'); - $originalAutoloadNamespaces = $this->getStaticField($this->class, 'autoloadNamespaces'); - $originalLoaders = $this->getStaticField($this->class, 'loaders'); - $this->setStaticField($this->class, 'autoloadNamespaces', $data); $this->setStaticField($this->class, 'loaders', $data); @@ -25,25 +25,22 @@ public function testReset() $this->assertEmpty($this->getStaticField($this->class, 'autoloadNamespaces')); $this->assertEmpty($this->getStaticField($this->class, 'loaders')); - - // restore original values because some tests depend on this values - $this->setStaticField($this->class, 'autoloadNamespaces', $originalAutoloadNamespaces); - $this->setStaticField($this->class, 'loaders', $originalLoaders); } + /** + * @runInSeparateProcess + */ public function testRegisterAutoloadNamespaces() { - $originalAutoloadNamespaces = $this->getStaticField($this->class, 'autoloadNamespaces'); $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')); - - // restore original value because some tests depend on this value - $this->setStaticField($this->class, 'autoloadNamespaces', $originalAutoloadNamespaces); } /** + * @runInSeparateProcess + * * @expectedException \InvalidArgumentException * @expectedExceptionMessage A callable is expected in AnnotationRegistry::registerLoader(). */