Skip to content

Commit

Permalink
Test that create() overrides the previous entry
Browse files Browse the repository at this point in the history
`object()` extended the previous entry, `create()` doesn't.
  • Loading branch information
mnapoli committed Jan 4, 2017
1 parent f24d749 commit 14ae540
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/IntegrationTest/Definitions/ObjectDefinition/Class2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace DI\Test\IntegrationTest\Definitions\ObjectDefinition;

class Class2
{
public $bar;
public $bim;
}
22 changes: 20 additions & 2 deletions tests/IntegrationTest/Definitions/ObjectDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DI\ContainerBuilder;
use DI\Test\IntegrationTest\Definitions\ObjectDefinition\Class1;
use DI\Test\IntegrationTest\Definitions\ObjectDefinition\Class2;

/**
* Test object definitions.
Expand All @@ -14,10 +15,9 @@
*/
class ObjectDefinitionTest extends \PHPUnit_Framework_TestCase
{
public function test_object_without_autowiring()
public function test_create_simple_object()
{
$builder = new ContainerBuilder();
$builder->useAutowiring(false);
$builder->addDefinitions([
// with the same name
'stdClass' => \DI\create('stdClass'),
Expand All @@ -33,6 +33,24 @@ public function test_object_without_autowiring()
$this->assertInstanceOf(Class1::class, $container->get('object'));
}

public function test_create_overrides_the_previous_entry()
{
$builder = new ContainerBuilder();
$builder->addDefinitions([
'foo' => \DI\create(Class2::class)
->property('bar', 123),
]);
$builder->addDefinitions([
'foo' => \DI\create(Class2::class)
->property('bim', 456),
]);
$container = $builder->build();

$foo = $container->get('foo');
self::assertEquals(null, $foo->bar, 'The "bar" property is not set');
self::assertEquals(456, $foo->bim, 'The "bim" property is set');
}

public function test_multiple_method_call()
{
$builder = new ContainerBuilder();
Expand Down

0 comments on commit 14ae540

Please sign in to comment.