From e0a572800234a14e67029a924855839abea7f73e Mon Sep 17 00:00:00 2001 From: Alrik Zachert Date: Thu, 30 Aug 2012 11:35:06 +0200 Subject: [PATCH 1/2] update/add unit tests --- test/Definition/ArrayDefinitionTest.php | 10 +++++++ test/Definition/BuilderDefinitionTest.php | 23 +++++++++++++++ test/Definition/ClassDefinitionTest.php | 34 +++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 test/Definition/ClassDefinitionTest.php diff --git a/test/Definition/ArrayDefinitionTest.php b/test/Definition/ArrayDefinitionTest.php index be5528d2..4badea2d 100644 --- a/test/Definition/ArrayDefinitionTest.php +++ b/test/Definition/ArrayDefinitionTest.php @@ -36,6 +36,16 @@ public function testArrayDefinitionHasClasses() $this->assertFalse($this->definition->hasClass('My\Foo')); } + public function testArrayDefinitionHasMethods() + { + $this->assertTrue($this->definition->hasMethods('My\Mapper')); + $this->assertFalse($this->definition->hasMethods('My\EntityA')); + $this->assertTrue($this->definition->hasMethods('My\Mapper')); + $this->assertFalse($this->definition->hasMethods('My\RepositoryA')); + $this->assertFalse($this->definition->hasMethods('My\RepositoryB')); + $this->assertFalse($this->definition->hasMethods('My\Foo')); + } + public function testArrayDefinitionCanGetClassses() { $list = array( diff --git a/test/Definition/BuilderDefinitionTest.php b/test/Definition/BuilderDefinitionTest.php index 45acce5f..fc475672 100644 --- a/test/Definition/BuilderDefinitionTest.php +++ b/test/Definition/BuilderDefinitionTest.php @@ -51,6 +51,29 @@ public function testBuilderCanBuildClassWithMethods() ); } + public function testBuilderDefinitionHasMethodsThrowsRuntimeException() + { + $definition = new BuilderDefinition(); + + $this->setExpectedException('Zend\Di\Exception\RuntimeException'); + $definition->hasMethods('Foo'); + } + + public function testBuilderDefinitionHasMethods() + { + $class = new Builder\PhpClass(); + $class->setName('Foo'); + + $definition = new BuilderDefinition(); + $definition->addClass($class); + + $this->assertFalse($definition->hasMethods('Foo')); + + $class->createInjectionMethod('injectBar'); + + $this->assertTrue($definition->hasMethods('Foo')); + } + public function testBuilderCanBuildFromArray() { $ini = ConfigFactory::fromFile(__DIR__ . '/../_files/sample.ini'); diff --git a/test/Definition/ClassDefinitionTest.php b/test/Definition/ClassDefinitionTest.php new file mode 100644 index 00000000..e65bfd4d --- /dev/null +++ b/test/Definition/ClassDefinitionTest.php @@ -0,0 +1,34 @@ +assertInstanceOf('Zend\Di\Definition\DefinitionInterface', $definition); + } + + public function testClassDefinitionHasMethods() + { + $definition = new ClassDefinition('Foo'); + + $this->assertFalse($definition->hasMethods('Foo')); + + $definition->addMethod('doBar'); + + $this->assertTrue($definition->hasMethods('Foo')); + } +} + From ea65e9f26151200d70f91fe07199a51f0311e9bb Mon Sep 17 00:00:00 2001 From: Alrik Zachert Date: Thu, 30 Aug 2012 16:30:28 +0200 Subject: [PATCH 2/2] fixes white-space policy --- test/Definition/ArrayDefinitionTest.php | 19 +++++-------- test/Definition/BuilderDefinitionTest.php | 34 +++++++++++------------ test/Definition/ClassDefinitionTest.php | 30 +++++++++----------- 3 files changed, 36 insertions(+), 47 deletions(-) diff --git a/test/Definition/ArrayDefinitionTest.php b/test/Definition/ArrayDefinitionTest.php index 4badea2d..aa8bcdc5 100644 --- a/test/Definition/ArrayDefinitionTest.php +++ b/test/Definition/ArrayDefinitionTest.php @@ -15,7 +15,6 @@ class ArrayDefinitionTest extends TestCase { - /** * @var ArrayDefinition */ @@ -38,14 +37,14 @@ public function testArrayDefinitionHasClasses() public function testArrayDefinitionHasMethods() { - $this->assertTrue($this->definition->hasMethods('My\Mapper')); - $this->assertFalse($this->definition->hasMethods('My\EntityA')); - $this->assertTrue($this->definition->hasMethods('My\Mapper')); - $this->assertFalse($this->definition->hasMethods('My\RepositoryA')); - $this->assertFalse($this->definition->hasMethods('My\RepositoryB')); - $this->assertFalse($this->definition->hasMethods('My\Foo')); + $this->assertTrue($this->definition->hasMethods('My\Mapper')); + $this->assertFalse($this->definition->hasMethods('My\EntityA')); + $this->assertTrue($this->definition->hasMethods('My\Mapper')); + $this->assertFalse($this->definition->hasMethods('My\RepositoryA')); + $this->assertFalse($this->definition->hasMethods('My\RepositoryB')); + $this->assertFalse($this->definition->hasMethods('My\Foo')); } - + public function testArrayDefinitionCanGetClassses() { $list = array( @@ -70,7 +69,6 @@ public function testArrayDefinitionCanGetClassSupertypes() $this->assertContains('My\RepositoryA', $this->definition->getClassSupertypes('My\RepositoryB')); } - public function testArrayDefinitionCanGetInstantiator() { $this->assertEquals('__construct', $this->definition->getInstantiator('My\RepositoryA')); @@ -96,7 +94,4 @@ public function testArrayDefinitionGetInjectionMethodParameters() { $this->markTestIncomplete(); } - - - } diff --git a/test/Definition/BuilderDefinitionTest.php b/test/Definition/BuilderDefinitionTest.php index fc475672..5ecc6555 100644 --- a/test/Definition/BuilderDefinitionTest.php +++ b/test/Definition/BuilderDefinitionTest.php @@ -17,7 +17,6 @@ class BuilderDefinitionTest extends TestCase { - public function testBuilderImplementsDefinition() { $builder = new BuilderDefinition(); @@ -53,27 +52,26 @@ public function testBuilderCanBuildClassWithMethods() public function testBuilderDefinitionHasMethodsThrowsRuntimeException() { - $definition = new BuilderDefinition(); - - $this->setExpectedException('Zend\Di\Exception\RuntimeException'); - $definition->hasMethods('Foo'); + $definition = new BuilderDefinition(); + + $this->setExpectedException('Zend\Di\Exception\RuntimeException'); + $definition->hasMethods('Foo'); } - + public function testBuilderDefinitionHasMethods() { - $class = new Builder\PhpClass(); - $class->setName('Foo'); - - $definition = new BuilderDefinition(); - $definition->addClass($class); - - $this->assertFalse($definition->hasMethods('Foo')); - - $class->createInjectionMethod('injectBar'); - - $this->assertTrue($definition->hasMethods('Foo')); + $class = new Builder\PhpClass(); + $class->setName('Foo'); + + $definition = new BuilderDefinition(); + $definition->addClass($class); + + $this->assertFalse($definition->hasMethods('Foo')); + $class->createInjectionMethod('injectBar'); + + $this->assertTrue($definition->hasMethods('Foo')); } - + public function testBuilderCanBuildFromArray() { $ini = ConfigFactory::fromFile(__DIR__ . '/../_files/sample.ini'); diff --git a/test/Definition/ClassDefinitionTest.php b/test/Definition/ClassDefinitionTest.php index e65bfd4d..39625a7c 100644 --- a/test/Definition/ClassDefinitionTest.php +++ b/test/Definition/ClassDefinitionTest.php @@ -14,21 +14,17 @@ class ClassDefinitionTest extends TestCase { - public function testClassImplementsDefinition() - { - $definition = new ClassDefinition('Foo'); - $this->assertInstanceOf('Zend\Di\Definition\DefinitionInterface', $definition); - } - - public function testClassDefinitionHasMethods() - { - $definition = new ClassDefinition('Foo'); - - $this->assertFalse($definition->hasMethods('Foo')); - - $definition->addMethod('doBar'); - - $this->assertTrue($definition->hasMethods('Foo')); - } -} + public function testClassImplementsDefinition() + { + $definition = new ClassDefinition('Foo'); + $this->assertInstanceOf('Zend\Di\Definition\DefinitionInterface', $definition); + } + public function testClassDefinitionHasMethods() + { + $definition = new ClassDefinition('Foo'); + $this->assertFalse($definition->hasMethods('Foo')); + $definition->addMethod('doBar'); + $this->assertTrue($definition->hasMethods('Foo')); + } +}