Skip to content

Commit

Permalink
ContainerInterface entry references the container entry
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Jan 13, 2017
1 parent f4cee4c commit 0ca3620
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Container/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function compile(AbstractCompilerConfig $compilerConfig, array $definitio

private function getEntryPoints(AbstractCompilerConfig $compilerConfig): Traversable
{
yield ContainerInterface::class;
yield $compilerConfig->getContainerFqcn();
yield ContainerInterface::class;

foreach ($compilerConfig->getContainerConfigs() as $containerConfig) {
foreach ($containerConfig->createEntryPoints() as $entryPoint) {
Expand Down
7 changes: 5 additions & 2 deletions src/Container/DependencyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use WoohooLabs\Zen\Config\Hint\DefinitionHintInterface;
use WoohooLabs\Zen\Container\Definition\ClassDefinition;
use WoohooLabs\Zen\Container\Definition\DefinitionInterface;
use WoohooLabs\Zen\Container\Definition\ReferenceDefinition;
use WoohooLabs\Zen\Container\Definition\SelfDefinition;
use WoohooLabs\Zen\Exception\ContainerException;

Expand Down Expand Up @@ -55,8 +56,10 @@ public function __construct(AbstractCompilerConfig $compilerConfig, array $defin
$this->typeHintReader = new PhpDocReader();

$this->definitions = [
ContainerInterface::class => new SelfDefinition($this->compilerConfig->getContainerFqcn()),
$this->compilerConfig->getContainerFqcn() => new SelfDefinition($this->compilerConfig->getContainerFqcn())
$this->compilerConfig->getContainerFqcn() => new SelfDefinition($this->compilerConfig->getContainerFqcn()),
ContainerInterface::class => new ReferenceDefinition(
ContainerInterface::class,
$this->compilerConfig->getContainerFqcn())
];
}

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/Container/DependencyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function resolveConstructorDependencies()

$this->assertEquals(
[
ContainerInterface::class => new SelfDefinition(""),
"" => new SelfDefinition(""),
ContainerInterface::class => new ReferenceDefinition(ContainerInterface::class, ""),
ConstructorA::class => ClassDefinition::singleton(ConstructorA::class)
->addRequiredConstructorArgument(ConstructorB::class)
->addRequiredConstructorArgument(ConstructorC::class)
Expand Down Expand Up @@ -77,8 +77,8 @@ public function resolvePropertyDependencies()

$this->assertEquals(
[
ContainerInterface::class => new SelfDefinition(""),
"" => new SelfDefinition(""),
ContainerInterface::class => new ReferenceDefinition(ContainerInterface::class, ""),
AnnotationA::class => ClassDefinition::singleton(AnnotationA::class)
->addProperty("b", AnnotationB::class)
->addProperty("c", AnnotationC::class)
Expand Down Expand Up @@ -111,8 +111,8 @@ public function resolveAllDependencies()

$this->assertEquals(
[
ContainerInterface::class => new SelfDefinition(""),
"" => new SelfDefinition(""),
ContainerInterface::class => new ReferenceDefinition(ContainerInterface::class, ""),
MixedA::class => ClassDefinition::singleton(MixedA::class)
->addRequiredConstructorArgument(MixedB::class)
->addRequiredConstructorArgument(MixedC::class)
Expand Down Expand Up @@ -147,8 +147,8 @@ public function resolvePrototypeDependency()

$this->assertEquals(
[
ContainerInterface::class => new SelfDefinition(""),
"" => new SelfDefinition(""),
ContainerInterface::class => new ReferenceDefinition(ContainerInterface::class, ""),
ConstructorD::class => ClassDefinition::prototype(ConstructorD::class)
->resolveDependencies(),
],
Expand All @@ -172,8 +172,8 @@ public function resolveAliasedDependency()

$this->assertEquals(
[
ContainerInterface::class => new SelfDefinition(""),
"" => new SelfDefinition(""),
ContainerInterface::class => new ReferenceDefinition(ContainerInterface::class, ""),
ConstructorC::class => ClassDefinition::singleton(ConstructorC::class)
->addRequiredConstructorArgument(ConstructorD::class)
->resolveDependencies(),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Fixture/Container/ContainerWithEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ContainerWithEntry extends AbstractContainer
* @var string[]
*/
protected $entryPoints = [
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
\WoohooLabs\Zen\Tests\Unit\Fixture\Container\ContainerWithEntry::class => 'WoohooLabs__Zen__Tests__Unit__Fixture__Container__ContainerWithEntry',
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
];

protected function WoohooLabs__Zen__Tests__Unit__Double__StubDefinition()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Fixture/Container/ContainerWithEntryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ContainerWithEntryPoint extends AbstractContainer
* @var string[]
*/
protected $entryPoints = [
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
\WoohooLabs\Zen\Tests\Unit\Fixture\Container\ContainerWithEntryPoint::class => 'WoohooLabs__Zen__Tests__Unit__Fixture__Container__ContainerWithEntryPoint',
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
\WoohooLabs\Zen\Tests\Unit\Double\StubDefinition::class => 'WoohooLabs__Zen__Tests__Unit__Double__StubDefinition',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EmptyContainerWithNamespace extends AbstractContainer
* @var string[]
*/
protected $entryPoints = [
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
\WoohooLabs\Zen\Tests\Unit\Fixture\Container\EmptyContainerWithNamespace::class => 'WoohooLabs__Zen__Tests__Unit__Fixture__Container__EmptyContainerWithNamespace',
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EmptyContainerWithoutNamespace extends AbstractContainer
* @var string[]
*/
protected $entryPoints = [
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
\EmptyContainerWithoutNamespace::class => 'EmptyContainerWithoutNamespace',
\Interop\Container\ContainerInterface::class => 'Interop__Container__ContainerInterface',
];
}

0 comments on commit 0ca3620

Please sign in to comment.