| Conditions | 5 |
| Paths | 2 |
| Total Lines | 33 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | protected function browser(): KernelBrowser |
||
| 12 | { |
||
| 13 | if (!$this instanceof KernelTestCase) { |
||
| 14 | throw new \RuntimeException(\sprintf('The "%s" method can only be used on TestCases that extend "%s".', __METHOD__, KernelTestCase::class)); |
||
| 15 | } |
||
| 16 | |||
| 17 | $browser = KernelBrowser::create(function() { |
||
| 18 | $class = $_SERVER['KERNEL_BROWSER_CLASS'] ?? KernelBrowser::class; |
||
| 19 | |||
| 20 | if (!\is_a($class, KernelBrowser::class, true)) { |
||
| 21 | throw new \RuntimeException(\sprintf('"KERNEL_BROWSER_CLASS" env variable must reference a class that extends %s.', KernelBrowser::class)); |
||
| 22 | } |
||
| 23 | |||
| 24 | if ($this instanceof WebTestCase) { |
||
| 25 | static::ensureKernelShutdown(); |
||
| 26 | |||
| 27 | return new $class(static::createClient()); |
||
| 28 | } |
||
| 29 | |||
| 30 | // reboot kernel before starting browser |
||
| 31 | static::bootKernel(); |
||
| 32 | |||
| 33 | if (!static::$container->has('test.client')) { |
||
| 34 | throw new \RuntimeException('The Symfony test client is not enabled.'); |
||
| 35 | } |
||
| 36 | |||
| 37 | return new $class(static::$container->get('test.client')); |
||
| 38 | }); |
||
| 39 | |||
| 40 | BrowserExtension::registerBrowser($browser); |
||
| 41 | |||
| 42 | return $browser |
||
| 43 | ->setSourceDir($_SERVER['BROWSER_SOURCE_DIR'] ?? './var/browser/source') |
||
| 44 | ; |
||
| 47 |