Passed
Pull Request — 1.x (#23)
by Wouter
01:49
created

HasPantherBrowser::_resetPantherBrowserClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Zenstruck\Browser\Test;
4
5
use Zenstruck\Browser\PantherBrowser;
6
7
trait HasPantherBrowser
8
{
9
    private static ?PantherClient $primaryPantherClient = null;
0 ignored issues
show
Bug introduced by
The type Zenstruck\Browser\Test\PantherClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
    /**
12
     * @internal
13
     * @after
14
     */
15
    final public static function _resetPantherBrowserClient(): void
16
    {
17
        self::$primaryPantherClient = null;
18
    }
19
20
    protected function browser(): PantherBrowser
21
    {
22
        $browser = PantherBrowser::create(function() {
23
            if (!$this instanceof PantherTestCase) {
0 ignored issues
show
Bug introduced by
The type Zenstruck\Browser\Test\PantherTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
                throw new \RuntimeException(\sprintf('The "%s" method can only be used on TestCases that extend "%s".', __METHOD__, PantherTestCase::class));
25
            }
26
27
            $class = $_SERVER['PANTHER_BROWSER_CLASS'] ?? PantherBrowser::class;
28
29
            if (!\is_a($class, PantherBrowser::class, true)) {
30
                throw new \RuntimeException(\sprintf('"PANTHER_BROWSER_CLASS" env variable must reference a class that extends %s.', PantherBrowser::class));
31
            }
32
33
            if (self::$primaryPantherClient) {
34
                return new $class(static::createAdditionalPantherClient());
35
            }
36
37
            self::$primaryPantherClient = static::createPantherClient(
38
                ['browser' => $_SERVER['PANTHER_BROWSER'] ?? static::CHROME]
0 ignored issues
show
Bug introduced by
The constant Zenstruck\Browser\Test\HasPantherBrowser::CHROME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
            );
40
41
            return new $class(self::$primaryPantherClient);
42
        });
43
44
        BrowserExtension::registerBrowser($browser);
45
46
        return $browser
47
            ->setSourceDir($_SERVER['BROWSER_SOURCE_DIR'] ?? './var/browser/source')
48
            ->setScreenshotDir($_SERVER['BROWSER_SCREENSHOT_DIR'] ?? './var/browser/screenshots')
49
            ->setConsoleLogDir($_SERVER['BROWSER_CONSOLE_LOG_DIR'] ?? './var/browser/console-logs')
50
        ;
51
    }
52
}
53