Skip to content

Commit fde0660

Browse files
committed
Return tests to passing state
1 parent e96ead4 commit fde0660

File tree

3 files changed

+17
-45
lines changed

3 files changed

+17
-45
lines changed

tests/Integration/Services/Servers/BuildModificationServiceTest.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public function setUp(): void
2626
{
2727
parent::setUp();
2828

29-
$this->daemonServerRepository = Mockery::mock(DaemonServerRepository::class);
30-
$this->swap(DaemonServerRepository::class, $this->daemonServerRepository);
29+
$this->daemonServerRepository = $this->mock(DaemonServerRepository::class);
3130
}
3231

3332
/**
@@ -50,7 +49,7 @@ public function testAllocationsCanBeModifiedForTheServer()
5049
$allocations[2]->update(['server_id' => $server2->id]);
5150
$allocations[3]->update(['server_id' => $server2->id]);
5251

53-
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
52+
$this->daemonServerRepository->expects('setServer->sync')->andReturnUndefined();
5453

5554
$response = $this->getService()->handle($server, [
5655
// Attempt to add one new allocation, and an allocation assigned to another server. The
@@ -113,20 +112,7 @@ public function testServerBuildDataIsProperlyUpdatedOnWings()
113112
return $s->id === $server->id;
114113
}))->andReturnSelf();
115114

116-
$this->daemonServerRepository->expects('update')->with(Mockery::on(function ($data) {
117-
$this->assertEquals([
118-
'build' => [
119-
'memory_limit' => 256,
120-
'swap' => 128,
121-
'io_weight' => 600,
122-
'cpu_limit' => 150,
123-
'threads' => '1,2',
124-
'disk_space' => 1024,
125-
],
126-
], $data);
127-
128-
return true;
129-
}))->andReturnUndefined();
115+
$this->daemonServerRepository->expects('sync')->withNoArgs()->andReturnUndefined();
130116

131117
$response = $this->getService()->handle($server, [
132118
'oom_disabled' => false,
@@ -162,7 +148,7 @@ public function testConnectionExceptionIsIgnoredWhenUpdatingServerSettings()
162148
{
163149
$server = $this->createServerModel();
164150

165-
$this->daemonServerRepository->expects('setServer->update')->andThrows(
151+
$this->daemonServerRepository->expects('setServer->sync')->andThrows(
166152
new DaemonConnectionException(
167153
new RequestException('Bad request', new Request('GET', '/test'), new Response())
168154
)
@@ -186,7 +172,7 @@ public function testNoExceptionIsThrownIfOnlyRemovingAllocation()
186172
/** @var \Pterodactyl\Models\Allocation $allocation */
187173
$allocation = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id]);
188174

189-
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
175+
$this->daemonServerRepository->expects('setServer->sync')->andReturnUndefined();
190176

191177
$this->getService()->handle($server, [
192178
'remove_allocations' => [$allocation->id],
@@ -209,7 +195,7 @@ public function testAllocationInBothAddAndRemoveIsAdded()
209195
/** @var \Pterodactyl\Models\Allocation $allocation */
210196
$allocation = Allocation::factory()->create(['node_id' => $server->node_id]);
211197

212-
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
198+
$this->daemonServerRepository->expects('setServer->sync')->andReturnUndefined();
213199

214200
$this->getService()->handle($server, [
215201
'add_allocations' => [$allocation->id],
@@ -230,7 +216,7 @@ public function testUsingSameAllocationIdMultipleTimesDoesNotError()
230216
/** @var \Pterodactyl\Models\Allocation $allocation2 */
231217
$allocation2 = Allocation::factory()->create(['node_id' => $server->node_id]);
232218

233-
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
219+
$this->daemonServerRepository->expects('setServer->sync')->andReturnUndefined();
234220

235221
$this->getService()->handle($server, [
236222
'add_allocations' => [$allocation2->id, $allocation2->id],
@@ -253,7 +239,7 @@ public function testThatUpdatesAreRolledBackIfExceptionIsEncountered()
253239
/** @var \Pterodactyl\Models\Allocation $allocation */
254240
$allocation = Allocation::factory()->create(['node_id' => $server->node_id]);
255241

256-
$this->daemonServerRepository->expects('setServer->update')->andThrows(new DisplayException('Test'));
242+
$this->daemonServerRepository->expects('setServer->sync')->andThrows(new DisplayException('Test'));
257243

258244
$this->expectException(DisplayException::class);
259245

tests/Integration/Services/Servers/ServerCreationServiceTest.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public function testServerIsCreatedWithDeploymentObject()
6767
$allocations[0]->port,
6868
]);
6969

70-
/** @noinspection PhpParamsInspection */
7170
$egg = $this->cloneEggAndVariables(Egg::query()->findOrFail(1));
7271
// We want to make sure that the validator service runs as an admin, and not as a regular
7372
// user when saving variables.
@@ -94,19 +93,10 @@ public function testServerIsCreatedWithDeploymentObject()
9493
'BUNGEE_VERSION' => '123',
9594
'SERVER_JARFILE' => 'server2.jar',
9695
],
96+
'start_on_completion' => true,
9797
];
9898

99-
$this->daemonServerRepository->expects('setServer')->andReturnSelf();
100-
$this->daemonServerRepository->expects('create')->with(Mockery::on(function ($value) {
101-
$this->assertIsArray($value);
102-
// Just check for some keys to make sure we're getting the expected configuration
103-
// structure back. Other tests exist to confirm it is the correct structure.
104-
$this->assertArrayHasKey('uuid', $value);
105-
$this->assertArrayHasKey('environment', $value);
106-
$this->assertArrayHasKey('invocation', $value);
107-
108-
return true;
109-
}))->andReturnUndefined();
99+
$this->daemonServerRepository->expects('setServer->create')->with(true)->andReturnUndefined();
110100

111101
try {
112102
$this->getService()->handle(array_merge($data, [
@@ -115,7 +105,8 @@ public function testServerIsCreatedWithDeploymentObject()
115105
'SERVER_JARFILE' => 'server2.jar',
116106
],
117107
]), $deployment);
118-
$this->assertTrue(false, 'This statement should not be reached.');
108+
109+
$this->fail('This execution pathway should not be reached.');
119110
} catch (ValidationException $exception) {
120111
$this->assertCount(1, $exception->errors());
121112
$this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors());
@@ -133,11 +124,11 @@ public function testServerIsCreatedWithDeploymentObject()
133124
$this->assertSame('server2.jar', $response->variables[1]->server_value);
134125

135126
foreach ($data as $key => $value) {
136-
if (in_array($key, ['allocation_additional', 'environment'])) {
127+
if (in_array($key, ['allocation_additional', 'environment', 'start_on_completion'])) {
137128
continue;
138129
}
139130

140-
$this->assertSame($value, $response->{$key});
131+
$this->assertSame($value, $response->{$key}, "Failed asserting equality of '$key' in server response. Got: [{$response->{$key}}] Expected: [$value]");
141132
}
142133

143134
$this->assertCount(2, $response->allocations);

tests/Integration/Services/Servers/SuspensionServiceTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,15 @@ public function testServerIsSuspendedAndUnsuspended()
2929
{
3030
$server = $this->createServerModel();
3131

32-
$this->repository->expects('setServer')->twice()->andReturnSelf();
33-
$this->repository->expects('suspend')->with(false)->andReturnUndefined();
32+
$this->repository->expects('setServer->sync')->twice()->andReturnSelf();
3433

3534
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
3635

37-
$server->refresh();
38-
$this->assertTrue($server->isSuspended());
39-
40-
$this->repository->expects('suspend')->with(true)->andReturnUndefined();
36+
$this->assertTrue($server->refresh()->isSuspended());
4137

4238
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
4339

44-
$server->refresh();
45-
$this->assertFalse($server->isSuspended());
40+
$this->assertFalse($server->refresh()->isSuspended());
4641
}
4742

4843
public function testNoActionIsTakenIfSuspensionStatusIsUnchanged()

0 commit comments

Comments
 (0)