summaryrefslogtreecommitdiff
path: root/vendor/symfony/service-contracts/Test
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/service-contracts/Test
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/service-contracts/Test')
-rw-r--r--vendor/symfony/service-contracts/Test/ServiceLocatorTest.php23
-rw-r--r--vendor/symfony/service-contracts/Test/ServiceLocatorTestCase.php96
2 files changed, 119 insertions, 0 deletions
diff --git a/vendor/symfony/service-contracts/Test/ServiceLocatorTest.php b/vendor/symfony/service-contracts/Test/ServiceLocatorTest.php
new file mode 100644
index 0000000..07d12b4
--- /dev/null
+++ b/vendor/symfony/service-contracts/Test/ServiceLocatorTest.php
@@ -0,0 +1,23 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Contracts\Service\Test;
13
14class_alias(ServiceLocatorTestCase::class, ServiceLocatorTest::class);
15
16if (false) {
17 /**
18 * @deprecated since PHPUnit 9.6
19 */
20 class ServiceLocatorTest
21 {
22 }
23}
diff --git a/vendor/symfony/service-contracts/Test/ServiceLocatorTestCase.php b/vendor/symfony/service-contracts/Test/ServiceLocatorTestCase.php
new file mode 100644
index 0000000..65a3fe3
--- /dev/null
+++ b/vendor/symfony/service-contracts/Test/ServiceLocatorTestCase.php
@@ -0,0 +1,96 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Contracts\Service\Test;
13
14use PHPUnit\Framework\TestCase;
15use Psr\Container\ContainerExceptionInterface;
16use Psr\Container\ContainerInterface;
17use Psr\Container\NotFoundExceptionInterface;
18use Symfony\Contracts\Service\ServiceLocatorTrait;
19
20abstract class ServiceLocatorTestCase extends TestCase
21{
22 protected function getServiceLocator(array $factories): ContainerInterface
23 {
24 return new class($factories) implements ContainerInterface {
25 use ServiceLocatorTrait;
26 };
27 }
28
29 public function testHas()
30 {
31 $locator = $this->getServiceLocator([
32 'foo' => fn () => 'bar',
33 'bar' => fn () => 'baz',
34 fn () => 'dummy',
35 ]);
36
37 $this->assertTrue($locator->has('foo'));
38 $this->assertTrue($locator->has('bar'));
39 $this->assertFalse($locator->has('dummy'));
40 }
41
42 public function testGet()
43 {
44 $locator = $this->getServiceLocator([
45 'foo' => fn () => 'bar',
46 'bar' => fn () => 'baz',
47 ]);
48
49 $this->assertSame('bar', $locator->get('foo'));
50 $this->assertSame('baz', $locator->get('bar'));
51 }
52
53 public function testGetDoesNotMemoize()
54 {
55 $i = 0;
56 $locator = $this->getServiceLocator([
57 'foo' => function () use (&$i) {
58 ++$i;
59
60 return 'bar';
61 },
62 ]);
63
64 $this->assertSame('bar', $locator->get('foo'));
65 $this->assertSame('bar', $locator->get('foo'));
66 $this->assertSame(2, $i);
67 }
68
69 public function testThrowsOnUndefinedInternalService()
70 {
71 $locator = $this->getServiceLocator([
72 'foo' => function () use (&$locator) { return $locator->get('bar'); },
73 ]);
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
80 $locator->get('foo');
81 }
82
83 public function testThrowsOnCircularReference()
84 {
85 $locator = $this->getServiceLocator([
86 'foo' => function () use (&$locator) { return $locator->get('bar'); },
87 'bar' => function () use (&$locator) { return $locator->get('baz'); },
88 'baz' => function () use (&$locator) { return $locator->get('bar'); },
89 ]);
90
91 $this->expectException(ContainerExceptionInterface::class);
92 $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
93
94 $locator->get('foo');
95 }
96}