Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Nov 29, 2015
1 parent 66bb799 commit 7f43e2a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/AbstractDefinitionCompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Interop\Container\Definition\Test;

use Assembly\ArrayDefinitionProvider;
use Interop\Container\Definition\Test\ArrayDefinitionProvider;
use Assembly\Reference;
use Interop\Container\ContainerInterface;
use Interop\Container\Definition\DefinitionProviderInterface;
use Interop\Container\Definition\Test\Fixtures\UnsupportedDefinition;

abstract class AbstractDefinitionCompatibilityTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -22,7 +23,7 @@ public function testInstanceConverter()
{
$referenceDefinition = new \Assembly\ObjectDefinition('foo', '\\stdClass');

$assemblyDefinition = new \Assembly\ObjectDefinition('bar', 'Interop\\Container\\Definition\\Fixtures\\Test');
$assemblyDefinition = new \Assembly\ObjectDefinition('bar', 'Interop\Container\Definition\Test\Fixtures\\Test');
$assemblyDefinition->addConstructorArgument(42);
$assemblyDefinition->addConstructorArgument(['hello' => 'world', 'foo' => new Reference('foo'), 'fooDirect' => $referenceDefinition]);

Expand All @@ -32,7 +33,7 @@ public function testInstanceConverter()
]));
$result = $container->get('bar');

$this->assertInstanceOf('Interop\\Container\\Definition\\Fixtures\\Test', $result);
$this->assertInstanceOf('Interop\Container\Definition\Test\Fixtures\\Test', $result);
$this->assertEquals(42, $result->cArg1);
$this->assertEquals('world', $result->cArg2['hello']);
$this->assertInstanceOf('stdClass', $result->cArg2['foo']);
Expand All @@ -47,7 +48,7 @@ public function testInstanceConverter()
*/
public function testParameterException()
{
$assemblyDefinition = new \Assembly\ObjectDefinition('foo', 'Interop\\Container\\Definition\\Fixtures\\Test');
$assemblyDefinition = new \Assembly\ObjectDefinition('foo', 'Interop\Container\Definition\Test\Fixtures\\Test');
$assemblyDefinition->addConstructorArgument(new \stdClass());

$this->getContainer(new ArrayDefinitionProvider([
Expand All @@ -60,7 +61,7 @@ public function testParameterException()
*/
public function testInstanceConverterPropertiesAndMethodCalls()
{
$assemblyDefinition = new \Assembly\ObjectDefinition('bar', 'Interop\\Container\\Definition\\Fixtures\\Test');
$assemblyDefinition = new \Assembly\ObjectDefinition('bar', 'Interop\Container\Definition\Test\Fixtures\\Test');
$assemblyDefinition->addMethodCall('setArg1', 42);
$assemblyDefinition->addPropertyAssignment('cArg2', 43);

Expand All @@ -69,7 +70,7 @@ public function testInstanceConverterPropertiesAndMethodCalls()
]));
$result = $container->get('bar');

$this->assertInstanceOf('Interop\\Container\\Definition\\Fixtures\\Test', $result);
$this->assertInstanceOf('Interop\Container\Definition\Test\Fixtures\\Test', $result);
$this->assertEquals(42, $result->cArg1);
$this->assertEquals(43, $result->cArg2);
}
Expand All @@ -90,7 +91,7 @@ public function testAliasConverter()
{
$aliasDefinition = new \Assembly\AliasDefinition('foo', 'bar');

$assemblyDefinition = new \Assembly\ObjectDefinition('bar', 'Interop\\Container\\Definition\\Fixtures\\Test');
$assemblyDefinition = new \Assembly\ObjectDefinition('bar', 'Interop\Container\Definition\Test\Fixtures\\Test');

$container = $this->getContainer(new ArrayDefinitionProvider([
'bar' => $assemblyDefinition,
Expand All @@ -104,7 +105,7 @@ public function testAliasConverter()

public function testFactoryConverter()
{
$factoryAssemblyDefinition = new \Assembly\ObjectDefinition('factory', 'Interop\\Container\\Definition\\Fixtures\\TestFactory');
$factoryAssemblyDefinition = new \Assembly\ObjectDefinition('factory', 'Interop\Container\Definition\Test\Fixtures\\TestFactory');
$factoryAssemblyDefinition->addConstructorArgument(42);

$assemblyDefinition = new \Assembly\FactoryCallDefinition('test', new Reference('factory'), 'getTest');
Expand All @@ -115,7 +116,7 @@ public function testFactoryConverter()
]));
$result = $container->get('test');

$this->assertInstanceOf('Interop\\Container\\Definition\\Fixtures\\Test', $result);
$this->assertInstanceOf('Interop\Container\Definition\Test\Fixtures\\Test', $result);
$this->assertEquals(42, $result->cArg1);
}

Expand All @@ -124,10 +125,11 @@ public function testFactoryConverter()
*/
public function testUnsupportedDefinitionConverter()
{
$definition = $this->getMock('Interop\\Container\\Definition\\DefinitionInterface');
$definition = new UnsupportedDefinition();

$this->getContainer(new ArrayDefinitionProvider([
$container = $this->getContainer(new ArrayDefinitionProvider([
'foo' => $definition,
]));
$container->get('foo');
}
}
20 changes: 20 additions & 0 deletions src/ArrayDefinitionProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Interop\Container\Definition\Test;

use Interop\Container\Definition\DefinitionProviderInterface;

class ArrayDefinitionProvider implements DefinitionProviderInterface
{
private $arrayDefinitions;

public function __construct(array $arrayDefinitions = [])
{
$this->arrayDefinitions = $arrayDefinitions;
}

public function getDefinitions()
{
return $this->arrayDefinitions;
}
}
21 changes: 21 additions & 0 deletions src/Fixtures/UnsupportedDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php


namespace Interop\Container\Definition\Test\Fixtures;


use Interop\Container\Definition\DefinitionInterface;

class UnsupportedDefinition implements DefinitionInterface
{

/**
* Returns the value that identifies the entry in the container.
*
* @return string
*/
public function getIdentifier()
{
return 'foo';
}
}

0 comments on commit 7f43e2a

Please sign in to comment.