Fix tests

This commit is contained in:
Lance Pioch 2024-10-18 22:38:06 -04:00
parent 804ff64a71
commit 50ffaf4d01
3 changed files with 17 additions and 7 deletions

View File

@ -87,6 +87,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
'environment' => [ 'environment' => [
'BUNGEE_VERSION' => '123', 'BUNGEE_VERSION' => '123',
'SERVER_JARFILE' => 'server2.jar', 'SERVER_JARFILE' => 'server2.jar',
'SERVER_PORT' => '1234',
], ],
'start_on_completion' => true, 'start_on_completion' => true,
]; ];
@ -98,13 +99,14 @@ class ServerCreationServiceTest extends IntegrationTestCase
'environment' => [ 'environment' => [
'BUNGEE_VERSION' => '', 'BUNGEE_VERSION' => '',
'SERVER_JARFILE' => 'server2.jar', 'SERVER_JARFILE' => 'server2.jar',
'SERVER_PORT' => '1234',
], ],
]), $deployment); ]), $deployment);
$this->fail('This execution pathway should not be reached.'); $this->fail('This execution pathway should not be reached.');
} catch (ValidationException $exception) { } catch (ValidationException $exception) {
$this->assertCount(1, $exception->errors());
$this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors()); $this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors());
$this->assertArrayNotHasKey('environment.SERVER_JARFILE', $exception->errors());
$this->assertSame('The Bungeecord Version variable field is required.', $exception->errors()['environment.BUNGEE_VERSION'][0]); $this->assertSame('The Bungeecord Version variable field is required.', $exception->errors()['environment.BUNGEE_VERSION'][0]);
} }
@ -114,7 +116,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
$this->assertNotNull($response->uuid); $this->assertNotNull($response->uuid);
$this->assertSame($response->uuid_short, substr($response->uuid, 0, 8)); $this->assertSame($response->uuid_short, substr($response->uuid, 0, 8));
$this->assertSame($egg->id, $response->egg_id); $this->assertSame($egg->id, $response->egg_id);
$this->assertCount(2, $response->variables); $this->assertCount(3, $response->variables);
$this->assertSame('123', $response->variables[0]->server_value); $this->assertSame('123', $response->variables[0]->server_value);
$this->assertSame('server2.jar', $response->variables[1]->server_value); $this->assertSame('server2.jar', $response->variables[1]->server_value);
@ -167,6 +169,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
'environment' => [ 'environment' => [
'BUNGEE_VERSION' => '123', 'BUNGEE_VERSION' => '123',
'SERVER_JARFILE' => 'server2.jar', 'SERVER_JARFILE' => 'server2.jar',
'SERVER_PORT' => '1234',
], ],
]; ];

View File

@ -29,6 +29,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
'environment' => [ 'environment' => [
'BUNGEE_VERSION' => '$$', 'BUNGEE_VERSION' => '$$',
'SERVER_JARFILE' => 'server.jar', 'SERVER_JARFILE' => 'server.jar',
'SERVER_PORT' => '1234',
], ],
]); ]);
@ -54,11 +55,12 @@ class StartupModificationServiceTest extends IntegrationTestCase
'environment' => [ 'environment' => [
'BUNGEE_VERSION' => '1234', 'BUNGEE_VERSION' => '1234',
'SERVER_JARFILE' => 'test.jar', 'SERVER_JARFILE' => 'test.jar',
'SERVER_PORT' => '1234',
], ],
]); ]);
$this->assertInstanceOf(Server::class, $result); $this->assertInstanceOf(Server::class, $result);
$this->assertCount(2, $result->variables); $this->assertCount(3, $result->variables);
$this->assertSame($server->startup, $result->startup); $this->assertSame($server->startup, $result->startup);
$this->assertSame('1234', $result->variables[0]->server_value); $this->assertSame('1234', $result->variables[0]->server_value);
$this->assertSame('test.jar', $result->variables[1]->server_value); $this->assertSame('test.jar', $result->variables[1]->server_value);
@ -125,7 +127,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
], ],
]); ]);
$this->assertCount(2, $response->variables); $this->assertCount(3, $response->variables);
$this->assertSame('EXIST', $response->variables[0]->server_value); $this->assertSame('EXIST', $response->variables[0]->server_value);
$this->assertSame('test.jar', $response->variables[1]->server_value); $this->assertSame('test.jar', $response->variables[1]->server_value);
@ -135,12 +137,14 @@ class StartupModificationServiceTest extends IntegrationTestCase
'environment' => [ 'environment' => [
'BUNGEE_VERSION' => '1234', 'BUNGEE_VERSION' => '1234',
'SERVER_JARFILE' => 'test.jar', 'SERVER_JARFILE' => 'test.jar',
'SERVER_PORT' => '1111',
], ],
]); ]);
$this->assertCount(2, $response->variables); $this->assertCount(3, $response->variables);
$this->assertSame('1234', $response->variables[0]->server_value); $this->assertSame('1234', $response->variables[0]->server_value);
$this->assertSame('test.jar', $response->variables[1]->server_value); $this->assertSame('test.jar', $response->variables[1]->server_value);
$this->assertSame('1111', $response->variables[2]->server_value);
} }
/** /**

View File

@ -94,25 +94,28 @@ class VariableValidatorServiceTest extends IntegrationTestCase
$this->getService()->setUserLevel(User::USER_LEVEL_ADMIN)->handle($egg->id, [ $this->getService()->setUserLevel(User::USER_LEVEL_ADMIN)->handle($egg->id, [
'BUNGEE_VERSION' => '1.2.3', 'BUNGEE_VERSION' => '1.2.3',
'SERVER_JARFILE' => 'server.jar', 'SERVER_JARFILE' => 'server.jar',
'SERVER_PORT' => '1234',
]); ]);
$this->fail('This statement should not be reached.'); $this->fail('This statement should not be reached.');
} catch (ValidationException $exception) { } catch (ValidationException $exception) {
$this->assertCount(1, $exception->errors());
$this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors()); $this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors());
} }
$response = $this->getService()->setUserLevel(User::USER_LEVEL_ADMIN)->handle($egg->id, [ $response = $this->getService()->setUserLevel(User::USER_LEVEL_ADMIN)->handle($egg->id, [
'BUNGEE_VERSION' => '123', 'BUNGEE_VERSION' => '123',
'SERVER_JARFILE' => 'server.jar', 'SERVER_JARFILE' => 'server.jar',
'SERVER_PORT' => '1234',
]); ]);
$this->assertInstanceOf(Collection::class, $response); $this->assertInstanceOf(Collection::class, $response);
$this->assertCount(2, $response); $this->assertCount(3, $response);
$this->assertSame('BUNGEE_VERSION', $response->get(0)->key); $this->assertSame('BUNGEE_VERSION', $response->get(0)->key);
$this->assertSame('123', $response->get(0)->value); $this->assertSame('123', $response->get(0)->value);
$this->assertSame('SERVER_JARFILE', $response->get(1)->key); $this->assertSame('SERVER_JARFILE', $response->get(1)->key);
$this->assertSame('server.jar', $response->get(1)->value); $this->assertSame('server.jar', $response->get(1)->value);
$this->assertSame('SERVER_PORT', $response->get(2)->key);
$this->assertSame('1234', $response->get(2)->value);
} }
public function testNullableEnvironmentVariablesCanBeUsedCorrectly(): void public function testNullableEnvironmentVariablesCanBeUsedCorrectly(): void