Skip to content

Commit d53eea5

Browse files
andrewmydunglas
authored andcommitted
added configurable web server config (symfony#57)
* added configurable web server config * removed function in favor of null coalescing operator
1 parent 7a9ad38 commit d53eea5

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ The following environment variables can be set to change some Panther behaviors:
187187
* `PANTHER_WEB_SERVER_DIR`: to change the project's document root (default to `public/`)
188188
* `PANTHER_CHROME_DRIVER_BINARY`: to use another `chromedriver` binary, instead of relying on the ones already provided by Panther
189189
* `PANTHER_CHROME_ARGUMENTS`: to customize `chromedriver` arguments. You need to set `PANTHER_NO_HEADLESS` to fully customize.
190+
* `PANTHER_WEB_SERVER_PORT`: to change the web server's port (default to `9000`)
190191

191192
## Docker Integration
192193

src/PantherTestCaseTrait.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ protected static function startWebServer(?string $webServerDir = null, string $h
8787
self::$baseUri = "http://$hostname:$port";
8888
}
8989

90-
/**
91-
* @param array $kernelOptions An array of options to pass to the createKernel method
92-
*/
93-
protected static function createPantherClient(string $hostname = '127.0.0.1', int $port = 9000, array $kernelOptions = []): PantherClient
90+
protected static function createPantherClient(string $hostname = '127.0.0.1', ?int $port = null, array $kernelOptions = []): PantherClient
9491
{
92+
$port = (int) ($port ?? $_SERVER['PANTHER_WEB_SERVER_PORT'] ?? 9000);
93+
9594
self::startWebServer(null, $hostname, $port);
9695
if (null === self::$pantherClient) {
9796
self::$pantherClient = Client::createChromeClient(null, null, [], self::$baseUri);
@@ -104,15 +103,14 @@ protected static function createPantherClient(string $hostname = '127.0.0.1', in
104103
return self::$pantherClient;
105104
}
106105

107-
/**
108-
* @param array $kernelOptions An array of options to pass to the createKernel method
109-
*/
110-
protected static function createGoutteClient(string $hostname = '127.0.0.1', int $port = 9000, array $kernelOptions = []): GoutteClient
106+
protected static function createGoutteClient(string $hostname = '127.0.0.1', ?int $port = null, array $kernelOptions = []): GoutteClient
111107
{
112108
if (!\class_exists(GoutteClient::class)) {
113109
throw new \RuntimeException('Goutte is not installed. Run "composer req fabpot/goutte".');
114110
}
115111

112+
$port = (int) ($port ?? $_SERVER['PANTHER_WEB_SERVER_PORT'] ?? 9000);
113+
116114
self::startWebServer(null, $hostname, $port);
117115
if (null === self::$goutteClient) {
118116
$goutteClient = new GoutteClient();

tests/ClientTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,14 @@ public function testCookie(callable $clientFactory, string $type)
190190
$cookieJar->expire('foo');
191191
$this->assertNull($cookieJar->get('foo'));
192192
}
193+
194+
/**
195+
* @dataProvider clientFactoryProvider
196+
*/
197+
public function testServerPort(callable $clientFactory): void
198+
{
199+
$expectedPort = $_SERVER['PANTHER_WEB_SERVER_PORT'] ?? '9000';
200+
$client = $clientFactory();
201+
$this->assertEquals($expectedPort, \mb_substr(self::$baseUri, -4));
202+
}
193203
}

0 commit comments

Comments
 (0)