Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test circular exception 2 #162

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
use Yiisoft\Di\AbstractContainerConfigurator;
use Yiisoft\Di\CompositeContainer;
use Yiisoft\Di\Container;
use Yiisoft\Factory\Exceptions\CircularReferenceException;
use Yiisoft\Factory\Exceptions\InvalidConfigException;
use Yiisoft\Factory\Exceptions\NotFoundException;
use Yiisoft\Di\Support\ServiceProvider;
use Yiisoft\Di\Tests\Support\A;
use Yiisoft\Di\Tests\Support\B;
use Yiisoft\Di\Tests\Support\Car;
use Yiisoft\Di\Tests\Support\CarFactory;
use Yiisoft\Di\Tests\Support\ColorInterface;
use Yiisoft\Di\Tests\Support\ColorPink;
use Yiisoft\Di\Tests\Support\ConstructorTestClass;
use Yiisoft\Di\Tests\Support\Cycle\Chicken;
use Yiisoft\Di\Tests\Support\Cycle\Egg;
use Yiisoft\Di\Tests\Support\EngineFactory;
use Yiisoft\Di\Tests\Support\EngineInterface;
use Yiisoft\Di\Tests\Support\EngineMarkOne;
use Yiisoft\Di\Tests\Support\EngineMarkTwo;
Expand All @@ -27,10 +28,12 @@
use Yiisoft\Di\Tests\Support\PropertyTestClass;
use Yiisoft\Di\Tests\Support\TreeItem;
use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Di\Tests\Support\EngineFactory;
use Yiisoft\Factory\Exceptions\CircularReferenceException;
use Yiisoft\Factory\Exceptions\InvalidConfigException;
use Yiisoft\Factory\Exceptions\NotFoundException;
use Yiisoft\Injector\Injector;
use Yiisoft\Di\Tests\Support\ColorPink;
use Yiisoft\Di\Tests\Support\ColorInterface;
use Yiisoft\Yii\Debug\Proxy\ContainerProxy;
use Yiisoft\Yii\Debug\Proxy\ContainerProxyConfig;

/**
* ContainerTest contains tests for \Yiisoft\Di\Container
Expand Down Expand Up @@ -573,6 +576,33 @@ public function testContainerComplexDelegateLookup(): void
$this->assertSame('firstsecondthird', $compositeContainer->get('first-second-third'));
}

public function testCircularReferenceException(): void
{
$provider = new class() extends ServiceProvider {
public function register(Container $container): void
{
$container->set(ContainerInterface::class, static function (ContainerInterface $container) {
// E.g. wrapping container with proxy class
return $container;
});
$container->get(B::class);
}
};

$this->expectException(\RuntimeException::class);

new Container(
[
B::class => function () {
throw new \RuntimeException();
},
],
[
$provider,
]
);
}

private function getProxyContainer(ContainerInterface $container): ContainerInterface
{
return new class($container) extends AbstractContainerConfigurator implements ContainerInterface {
Expand Down