diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f4974da9..6fab1429 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,18 +11,20 @@ - + + + - + - + - + - - + + diff --git a/tests/Selenium2Config.php b/tests/Selenium2Config.php index e2b3606e..f2be1bd3 100644 --- a/tests/Selenium2Config.php +++ b/tests/Selenium2Config.php @@ -24,7 +24,7 @@ class Selenium2Config extends AbstractConfig public function __construct() { - $this->seleniumMajorVersion = (int) explode('.', $_SERVER['SELENIUM_VERSION'] ?? '')[0]; + $this->seleniumMajorVersion = (int) explode('.', $this->getEnvVar('SELENIUM_VERSION') ?? '')[0]; } public static function getInstance(): self @@ -34,17 +34,24 @@ public static function getInstance(): self public function createDriver(): DriverInterface { - $browser = getenv('WEB_FIXTURES_BROWSER') ?: 'firefox'; - $seleniumHost = $_SERVER['DRIVER_URL']; + $browser = $this->getBrowserName(); + $seleniumHost = $this->getEnvVar('DRIVER_URL') ?? 'http://localhost:4444/wd/hub'; return new Selenium2Driver($browser, null, $seleniumHost); } + public function getBrowserName(): string + { + return $this->getEnvVar('WEB_FIXTURES_BROWSER') ?? 'firefox'; + } + public function mapRemoteFilePath($file): string { - if (!isset($_SERVER['TEST_MACHINE_BASE_PATH'])) { + // Auto-detect "TEST_MACHINE_BASE_PATH" from the test fixtures folder location, so only "DRIVER_MACHINE_BASE_PATH" + // has to be set, when only this folder is shared with the Selenium machine (e.g. "/fixtures/" in "docker-compose.yml"). + if (null === $this->getEnvVar('TEST_MACHINE_BASE_PATH')) { $webFixturesPath = dirname(__DIR__) . '/vendor/mink/driver-testsuite/web-fixtures'; - $_SERVER['TEST_MACHINE_BASE_PATH'] = realpath($webFixturesPath) . DIRECTORY_SEPARATOR; + putenv('TEST_MACHINE_BASE_PATH=' . realpath($webFixturesPath) . DIRECTORY_SEPARATOR); } return parent::mapRemoteFilePath($file); @@ -82,7 +89,7 @@ public function skipMessage($testCase, $test): ?string } if (array(JavascriptTest::class, 'testDragDropOntoHiddenItself') === $testCallback) { - $browser = $_SERVER['WEB_FIXTURES_BROWSER'] ?? null; + $browser = $this->getBrowserName(); if ($browser === 'firefox' && $this->getSeleniumMajorVersion() === 2) { return 'The Firefox browser compatible with Selenium 2.x does not fully implement drag-n-drop support.'; @@ -90,7 +97,7 @@ public function skipMessage($testCase, $test): ?string } if (array(EventsTest::class, 'testKeyboardEvents') === $testCallback) { - $browser = $_SERVER['WEB_FIXTURES_BROWSER'] ?? null; + $browser = $this->getBrowserName(); if ($browser === 'chrome' && $this->getSeleniumMajorVersion() === 2) { return 'The Chrome browser compatible with Selenium 2.x ignores key codes in synthetic keyboard events.';