Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/di-definitionInterface-api-consistency' of https…
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 30, 2012
2 parents bf30302 + 26f013f commit bfce451
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Di/Definition/ArrayDefinition.php
Expand Up @@ -89,11 +89,11 @@ public function getInstantiator($class)
public function hasMethods($class)
{
if (!isset($this->dataArray[$class])) {
return array();
return false;
}

if (!isset($this->dataArray[$class]['methods'])) {
return array();
return false;
}

return (count($this->dataArray[$class]['methods']) > 0);
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Di/Definition/ClassDefinition.php
Expand Up @@ -152,7 +152,7 @@ public function getInstantiator($class)
*/
public function hasMethods($class)
{
return ($this->methods);
return (count($this->methods) > 0);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions tests/ZendTest/Di/Definition/ArrayDefinitionTest.php
Expand Up @@ -15,7 +15,6 @@

class ArrayDefinitionTest extends TestCase
{

/**
* @var ArrayDefinition
*/
Expand All @@ -36,6 +35,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(
Expand All @@ -60,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'));
Expand All @@ -86,7 +94,4 @@ public function testArrayDefinitionGetInjectionMethodParameters()
{
$this->markTestIncomplete();
}



}
23 changes: 22 additions & 1 deletion tests/ZendTest/Di/Definition/BuilderDefinitionTest.php
Expand Up @@ -17,7 +17,6 @@

class BuilderDefinitionTest extends TestCase
{

public function testBuilderImplementsDefinition()
{
$builder = new BuilderDefinition();
Expand Down Expand Up @@ -51,6 +50,28 @@ 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');
Expand Down
30 changes: 30 additions & 0 deletions tests/ZendTest/Di/Definition/ClassDefinitionTest.php
@@ -0,0 +1,30 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
namespace ZendTest\Di\Definition;

use Zend\Di\Definition\ClassDefinition;
use PHPUnit_Framework_TestCase as TestCase;

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'));
}
}

0 comments on commit bfce451

Please sign in to comment.