Skip to content

Commit 720e119

Browse files
Improve DX when using the symfony binary (#592)
1 parent 7294951 commit 720e119

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ public function get($url): self
522522

523523
// Prepend the base URI to URIs without a host
524524
if (null !== $this->baseUri && (false !== $components = parse_url($url)) && !isset($components['host'])) {
525+
if (str_starts_with($url, '/') && str_ends_with($this->baseUri, '/')) {
526+
$url = substr($url, 1);
527+
} elseif (!str_starts_with($url, '/') && !str_ends_with($this->baseUri, '/')) {
528+
$url = '/'.$url;
529+
}
525530
$url = $this->baseUri.$url;
526531
}
527532

src/PantherTestCaseTrait.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ trait PantherTestCaseTrait
5555
'router' => '',
5656
'external_base_uri' => null,
5757
'readinessPath' => '',
58-
'browser' => PantherTestCase::CHROME,
5958
'env' => [],
6059
];
6160

@@ -100,7 +99,7 @@ public static function startWebServer(array $options = []): void
10099
return;
101100
}
102101

103-
if ($externalBaseUri = $options['external_base_uri'] ?? $_SERVER['PANTHER_EXTERNAL_BASE_URI'] ?? self::$defaultOptions['external_base_uri']) {
102+
if ($externalBaseUri = $options['external_base_uri'] ?? self::$defaultOptions['external_base_uri'] ?? $_SERVER['PANTHER_EXTERNAL_BASE_URI'] ?? $_SERVER['SYMFONY_PROJECT_DEFAULT_ROUTE_URL'] ?? null) {
104103
self::$baseUri = $externalBaseUri;
105104

106105
return;
@@ -161,7 +160,7 @@ public function takeScreenshotIfTestFailed(): void
161160
*/
162161
protected static function createPantherClient(array $options = [], array $kernelOptions = [], array $managerOptions = []): PantherClient
163162
{
164-
$browser = ($options['browser'] ?? self::$defaultOptions['browser'] ?? PantherTestCase::CHROME);
163+
$browser = ($options['browser'] ?? self::$defaultOptions['browser'] ?? null);
165164
$callGetClient = method_exists(self::class, 'getClient') && (new \ReflectionMethod(self::class, 'getClient'))->isStatic();
166165
if (null !== self::$pantherClient) {
167166
$browserManager = self::$pantherClient->getBrowserManager();
@@ -178,10 +177,21 @@ protected static function createPantherClient(array $options = [], array $kernel
178177

179178
self::startWebServer($options);
180179

181-
if (PantherTestCase::CHROME === $browser) {
182-
self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, null, $managerOptions, self::$baseUri);
183-
} else {
180+
if (PantherTestCase::FIREFOX === $browser) {
184181
self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri);
182+
} else {
183+
try {
184+
self::$pantherClients[0] = self::$pantherClient = Client::createChromeClient(null, null, $managerOptions, self::$baseUri);
185+
} catch (\RuntimeException $e) {
186+
if (PantherTestCase::CHROME === $browser) {
187+
throw $e;
188+
}
189+
self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri);
190+
}
191+
192+
if (null === $browser) {
193+
self::$defaultOptions['browser'] = self::$pantherClient->getBrowserManager() instanceof ChromeManager ? PantherTestCase::CHROME : PantherTestCase::FIREFOX;
194+
}
185195
}
186196

187197
if (is_a(self::class, KernelTestCase::class, true)) {

0 commit comments

Comments
 (0)