Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
added tests for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
arren-ru authored and idr0id committed Dec 1, 2017
1 parent 579e3a0 commit 5b79d47
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tests/src/Container/ConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ public function testClass()
$this->assertInstanceOf(Foo::class, $entry->getFoo());
}

public function testAlias()
{
// arrange
$container = new Container([
'foo' => ['class' => Foo::class],
ClassDependency::class => [
'args' => ['$foo']
],
]);
// act
/** @var ClassDependency $entry */
$entry = $container->get(ClassDependency::class);
// assert
$this->assertInstanceOf(ClassDependency::class, $entry);
$this->assertInstanceOf(Foo::class, $entry->getFoo());
}

public function testInterface()
{
// arrange
Expand Down
34 changes: 31 additions & 3 deletions tests/src/Container/DependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public function testClassDependency()
$entry = $container->get(ClassDependency::class);
// assert
$this->assertInstanceOf(ClassDependency::class, $entry);
$this->assertNull($entry->getFoo());
}

public function testAliasDependency()
{
// arrange
$container = new Container([
ClassDependency::class => ['args' => ['$foo']],
'foo' => ['class' => Foo::class],
]);
// act
$entry = $container->get(ClassDependency::class);
// assert
$this->assertInstanceOf(ClassDependency::class, $entry);
$this->assertInstanceOf(Foo::class, $entry->getFoo());
}

public function testInterfaceDependency()
Expand All @@ -36,6 +51,7 @@ public function testInterfaceDependency()
$entry = $container->get(InterfaceDependency::class);
// assert
$this->assertInstanceOf(InterfaceDependency::class, $entry);
$this->assertInstanceOf(Foo::class, $entry->getFoo());
}

/**
Expand All @@ -49,8 +65,20 @@ public function testUnresolvedDependencies()
ScalarDependency::class => [],
]);
// act
$entry = $container->get(ScalarDependency::class);
// assert
$this->assertInstanceOf(ScalarDependency::class, $entry);
$container->get(ScalarDependency::class);
}

/**
* @expectedException \Psr\Container\ContainerExceptionInterface
* @expectedExceptionMessage Unable to create instance of entry `Zp\PHPWire\Tests\Fixtures\ClassDependency`: Unable to invoke arguments to constructor: Requested a non-existent container entry `foo`
*/
public function testRequestNonExistent()
{
// arrange
$container = new Container([
ClassDependency::class => ['args' => ['$foo']],
]);
// act
$container->get(ClassDependency::class);
}
}

0 comments on commit 5b79d47

Please sign in to comment.