changes
This commit is contained in:
@ -12,7 +12,9 @@
|
||||
namespace Symfony\Contracts\Service\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Symfony\Contracts\Service\ServiceLocatorTrait;
|
||||
|
||||
abstract class ServiceLocatorTestCase extends TestCase
|
||||
@ -66,27 +68,29 @@ abstract class ServiceLocatorTestCase extends TestCase
|
||||
|
||||
public function testThrowsOnUndefinedInternalService()
|
||||
{
|
||||
if (!$this->getExpectedException()) {
|
||||
$this->expectException(\Psr\Container\NotFoundExceptionInterface::class);
|
||||
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
|
||||
}
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => function () use (&$locator) { return $locator->get('bar'); },
|
||||
]);
|
||||
|
||||
if (!$this->getExpectedException()) {
|
||||
$this->expectException(NotFoundExceptionInterface::class);
|
||||
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
|
||||
}
|
||||
|
||||
$locator->get('foo');
|
||||
}
|
||||
|
||||
public function testThrowsOnCircularReference()
|
||||
{
|
||||
$this->expectException(\Psr\Container\ContainerExceptionInterface::class);
|
||||
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => function () use (&$locator) { return $locator->get('bar'); },
|
||||
'bar' => function () use (&$locator) { return $locator->get('baz'); },
|
||||
'baz' => function () use (&$locator) { return $locator->get('bar'); },
|
||||
]);
|
||||
|
||||
$this->expectException(ContainerExceptionInterface::class);
|
||||
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
|
||||
|
||||
$locator->get('foo');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user