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