Skip to content
Permalink
Browse files

Fix #582 Register `ContainerInterface` to point to the wrapper contai…

…ner if it was defined
  • Loading branch information...
mnapoli committed Apr 21, 2018
1 parent dfad09b commit 1a46970583b61645c02626f5e79106272a8bb7ee
Showing with 19 additions and 2 deletions.
  1. +1 −0 change-log.md
  2. +2 −2 src/Container.php
  3. +16 −0 tests/IntegrationTest/DefaultEntriesTest.php
@@ -4,6 +4,7 @@

- Fix [#526](https://github.com/PHP-DI/PHP-DI/issues/526): Support optional parameters in factories
- [#585](https://github.com/PHP-DI/PHP-DI/issues/585) Add support for PHP-Parser 4.0
- [#582](https://github.com/PHP-DI/PHP-DI/issues/582) Register `ContainerInterface` to point to the wrapper container if it was defined

## 6.0

@@ -106,10 +106,10 @@ public function __construct(
// Auto-register the container
$this->resolvedEntries = [
self::class => $this,
self::class => $this->delegateContainer,

This comment has been minimized.

Copy link
@drealecs

drealecs Apr 22, 2018

Contributor

I'm not sure that it's fine to return another class instance when you request the Container class. Considering how PHP-DI works, caller might expect to receive an object that is instaceof Container.

This comment has been minimized.

Copy link
@mnapoli

mnapoli Apr 23, 2018

Author Member

Oh right my bad! I thought about that for Factory and Invoker interfaces but didn't stop thinking about this one!

I'll fix that and release a patch right now, thanks.

ContainerInterface::class => $this->delegateContainer,
FactoryInterface::class => $this,
InvokerInterface::class => $this,
ContainerInterface::class => $this,
];
}
@@ -59,4 +59,20 @@ public function testContainerInterfaceIsRegistered(ContainerBuilder $builder)
$this->assertSame($container, $container->get(ContainerInterface::class));
}
/**
* @dataProvider provideContainer
*/
public function testWithAWrapperContainer(ContainerBuilder $builder)
{
$wrapperContainer = new Container;
$builder->wrapContainer($wrapperContainer);
$container = $builder->build();
$this->assertSame($wrapperContainer, $container->get(Container::class));
$this->assertSame($wrapperContainer, $container->get(ContainerInterface::class));
$this->assertSame($container, $container->get(InvokerInterface::class));
$this->assertSame($container, $container->get(FactoryInterface::class));
}
}

0 comments on commit 1a46970

Please sign in to comment.
You can’t perform that action at this time.