Skip to content

Commit fe07cbc

Browse files
OskarStarknicolas-grekas
authored andcommitted
[Tests] Streamline
1 parent 11bbf19 commit fe07cbc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Test/ServiceLocatorTestCase.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
namespace Symfony\Contracts\Service\Test;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Container\ContainerExceptionInterface;
1516
use Psr\Container\ContainerInterface;
17+
use Psr\Container\NotFoundExceptionInterface;
1618
use Symfony\Contracts\Service\ServiceLocatorTrait;
1719

1820
abstract class ServiceLocatorTestCase extends TestCase
@@ -66,27 +68,29 @@ public function testGetDoesNotMemoize()
6668

6769
public function testThrowsOnUndefinedInternalService()
6870
{
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-
}
7371
$locator = $this->getServiceLocator([
7472
'foo' => function () use (&$locator) { return $locator->get('bar'); },
7573
]);
7674

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+
7780
$locator->get('foo');
7881
}
7982

8083
public function testThrowsOnCircularReference()
8184
{
82-
$this->expectException(\Psr\Container\ContainerExceptionInterface::class);
83-
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
8485
$locator = $this->getServiceLocator([
8586
'foo' => function () use (&$locator) { return $locator->get('bar'); },
8687
'bar' => function () use (&$locator) { return $locator->get('baz'); },
8788
'baz' => function () use (&$locator) { return $locator->get('bar'); },
8889
]);
8990

91+
$this->expectException(ContainerExceptionInterface::class);
92+
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
93+
9094
$locator->get('foo');
9195
}
9296
}

0 commit comments

Comments
 (0)