PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / service-contracts / Test / ServiceLocatorTest.php

ServiceLocatorTest.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at vendor/symfony/service-contracts/Test/ServiceLocatorTest.php

96 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Contracts\Service\Test;
13
14 use PHPUnit\Framework\TestCase;
15 use Psr\Container\ContainerInterface;
16 use Symfony\Contracts\Service\ServiceLocatorTrait;
17
18 abstract class ServiceLocatorTest extends TestCase
19 {
20 /**
21 * @return ContainerInterface
22 */
23 protected function getServiceLocator(array $factories)
24 {
25 return new class($factories) implements ContainerInterface {
26 use ServiceLocatorTrait;
27 };
28 }
29
30 public function testHas()
31 {
32 $locator = $this->getServiceLocator([
33 'foo' => function () { return 'bar'; },
34 'bar' => function () { return 'baz'; },
35 function () { return 'dummy'; },
36 ]);
37
38 $this->assertTrue($locator->has('foo'));
39 $this->assertTrue($locator->has('bar'));
40 $this->assertFalse($locator->has('dummy'));
41 }
42
43 public function testGet()
44 {
45 $locator = $this->getServiceLocator([
46 'foo' => function () { return 'bar'; },
47 'bar' => function () { return 'baz'; },
48 ]);
49
50 $this->assertSame('bar', $locator->get('foo'));
51 $this->assertSame('baz', $locator->get('bar'));
52 }
53
54 public function testGetDoesNotMemoize()
55 {
56 $i = 0;
57 $locator = $this->getServiceLocator([
58 'foo' => function () use (&$i) {
59 ++$i;
60
61 return 'bar';
62 },
63 ]);
64
65 $this->assertSame('bar', $locator->get('foo'));
66 $this->assertSame('bar', $locator->get('foo'));
67 $this->assertSame(2, $i);
68 }
69
70 public function testThrowsOnUndefinedInternalService()
71 {
72 if (!$this->getExpectedException()) {
73 $this->expectException(\Psr\Container\NotFoundExceptionInterface::class);
74 $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
75 }
76 $locator = $this->getServiceLocator([
77 'foo' => function () use (&$locator) { return $locator->get('bar'); },
78 ]);
79
80 $locator->get('foo');
81 }
82
83 public function testThrowsOnCircularReference()
84 {
85 $this->expectException(\Psr\Container\ContainerExceptionInterface::class);
86 $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
87 $locator = $this->getServiceLocator([
88 'foo' => function () use (&$locator) { return $locator->get('bar'); },
89 'bar' => function () use (&$locator) { return $locator->get('baz'); },
90 'baz' => function () use (&$locator) { return $locator->get('bar'); },
91 ]);
92
93 $locator->get('foo');
94 }
95 }
96