Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Mar 14, 2024
1 parent 17c985a commit 9234ad9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Psr\Container\NotFoundExceptionInterface;
use RuntimeException;
use stdClass;
use Throwable;
use Yiisoft\Di\BuildingException;
use Yiisoft\Di\CompositeContainer;
use Yiisoft\Di\Container;
Expand Down Expand Up @@ -51,6 +52,7 @@
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Reference;
use Yiisoft\Injector\Injector;
use Yiisoft\Test\Support\Container\SimpleContainer;

/**
* ContainerTest contains tests for \Yiisoft\Di\Container
Expand Down Expand Up @@ -2001,4 +2003,31 @@ public function testNotFoundExceptionMessageWithDefinitions(array $definitions):
);
$container->get(SportCar::class);
}

public function testNotFoundExceptionWithNotYiiContainer(): void
{
$config = ContainerConfig::create()
->withDefinitions([
ContainerInterface::class => new SimpleContainer(),
SportCar::class => SportCar::class,
]);
$container = new Container($config);

$exception = null;
try {
$container->get(SportCar::class);
} catch (Throwable $e) {
$exception = $e;
}

$this->assertInstanceOf(NotFoundException::class, $exception);
$this->assertSame(
'No definition or class found or resolvable for "' . SportCar::class . '" while building it.',
$exception->getMessage()
);
$this->assertInstanceOf(
\Yiisoft\Test\Support\Container\Exception\NotFoundException::class,
$exception->getPrevious()
);
}
}

0 comments on commit 9234ad9

Please sign in to comment.