Skip to content

Commit ba10ce2

Browse files
committed
fix: ensure that server port env is set
1 parent 442dd8f commit ba10ce2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/Server.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class Server
88
{
9+
const ENV_SERVER_PORT = 'TEST_SERVER_PORT';
10+
911
/** @var \GuzzleHttp\Client */
1012
protected $client;
1113

@@ -40,6 +42,10 @@ public function setResponseBody(string $text, int $statusCode = 200)
4042

4143
public static function boot()
4244
{
45+
if (empty(getenv(self::ENV_SERVER_PORT))) {
46+
throw new \InvalidArgumentException(sprintf('`%s` environment variable is not set', self::ENV_SERVER_PORT));
47+
}
48+
4349
if (! file_exists(__DIR__.'/server/vendor')) {
4450
exec('cd "'.__DIR__.'/server"; composer install');
4551
}
@@ -60,7 +66,7 @@ public static function boot()
6066

6167
public static function getServerUrl(string $endPoint = ''): string
6268
{
63-
return 'localhost:'.getenv('TEST_SERVER_PORT').'/'.$endPoint;
69+
return sprintf('localhost:%s/%s', getenv('TEST_SERVER_PORT'), $endPoint);
6470
}
6571

6672
public static function serverHasBooted(): bool

0 commit comments

Comments
 (0)