|
12 | 12 | namespace Symfony\Contracts\Service\Test; |
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase; |
| 15 | +use Psr\Container\ContainerExceptionInterface; |
15 | 16 | use Psr\Container\ContainerInterface; |
| 17 | +use Psr\Container\NotFoundExceptionInterface; |
16 | 18 | use Symfony\Contracts\Service\ServiceLocatorTrait; |
17 | 19 |
|
18 | 20 | abstract class ServiceLocatorTestCase extends TestCase |
@@ -66,27 +68,29 @@ public function testGetDoesNotMemoize() |
66 | 68 |
|
67 | 69 | public function testThrowsOnUndefinedInternalService() |
68 | 70 | { |
69 | | - if (!$this->getExpectedException()) { |
70 | | - $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); |
71 | | - $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
72 | | - } |
73 | 71 | $locator = $this->getServiceLocator([ |
74 | 72 | 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
75 | 73 | ]); |
76 | 74 |
|
| 75 | + if (!$this->getExpectedException()) { |
| 76 | + $this->expectException(NotFoundExceptionInterface::class); |
| 77 | + $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
| 78 | + } |
| 79 | + |
77 | 80 | $locator->get('foo'); |
78 | 81 | } |
79 | 82 |
|
80 | 83 | public function testThrowsOnCircularReference() |
81 | 84 | { |
82 | | - $this->expectException(\Psr\Container\ContainerExceptionInterface::class); |
83 | | - $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
84 | 85 | $locator = $this->getServiceLocator([ |
85 | 86 | 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
86 | 87 | 'bar' => function () use (&$locator) { return $locator->get('baz'); }, |
87 | 88 | 'baz' => function () use (&$locator) { return $locator->get('bar'); }, |
88 | 89 | ]); |
89 | 90 |
|
| 91 | + $this->expectException(ContainerExceptionInterface::class); |
| 92 | + $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
| 93 | + |
90 | 94 | $locator->get('foo'); |
91 | 95 | } |
92 | 96 | } |
0 commit comments