Skip to content

Commit eccadee

Browse files
committed
Refactor host constant to static method in FixtureServerTrait
1 parent a24cf07 commit eccadee

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

tests/Unit/FixtureServerTrait.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
*/
1717
trait FixtureServerTrait
1818
{
19-
private const FIXTURE_HOST = '127.0.0.1';
19+
/**
20+
* PHP 8.1 and earlier do not allow constants inside traits — that was
21+
* relaxed in PHP 8.2. Expose the host as a static method instead so the
22+
* trait keeps working across the whole PHP 7.4 – 8.4 matrix.
23+
*/
24+
private static function fixtureHost(): string
25+
{
26+
return '127.0.0.1';
27+
}
2028

2129
/** @var resource|null */
2230
private static $serverProcess;
@@ -46,13 +54,13 @@ private static function bootFixtureServer(): void
4654
if (!is_file($fixture)) {
4755
self::fail('Fixture server file is missing: ' . $fixture);
4856
}
49-
self::$baseUrl = 'http://' . self::FIXTURE_HOST . ':' . $port;
57+
self::$baseUrl = 'http://' . self::fixtureHost() . ':' . $port;
5058

5159
self::killFixturePortListeners($port);
5260

5361
$cmd = sprintf(
5462
'PHP_CLI_SERVER_WORKERS=4 exec php -S %s:%d %s',
55-
self::FIXTURE_HOST,
63+
self::fixtureHost(),
5664
$port,
5765
escapeshellarg($fixture)
5866
);
@@ -69,7 +77,7 @@ private static function bootFixtureServer(): void
6977

7078
$deadline = microtime(true) + 5.0;
7179
while (microtime(true) < $deadline) {
72-
$sock = @fsockopen(self::FIXTURE_HOST, $port, $errno, $errstr, 0.2);
80+
$sock = @fsockopen(self::fixtureHost(), $port, $errno, $errstr, 0.2);
7381
if (is_resource($sock)) {
7482
fclose($sock);
7583
return;

0 commit comments

Comments
 (0)