2020-10-08 04:56:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Integration\Services\Servers;
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
use Mockery\MockInterface;
|
2021-01-17 23:51:56 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2020-10-08 04:56:44 +00:00
|
|
|
use Pterodactyl\Services\Servers\SuspensionService;
|
|
|
|
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|
|
|
|
|
|
|
class SuspensionServiceTest extends IntegrationTestCase
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
private MockInterface $repository;
|
2020-10-08 04:56:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup test instance.
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2022-11-29 17:53:59 +00:00
|
|
|
$this->repository = \Mockery::mock(DaemonServerRepository::class);
|
2020-10-08 04:56:44 +00:00
|
|
|
$this->app->instance(DaemonServerRepository::class, $this->repository);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testServerIsSuspendedAndUnsuspended()
|
|
|
|
{
|
2021-01-17 23:51:56 +00:00
|
|
|
$server = $this->createServerModel();
|
2020-10-08 04:56:44 +00:00
|
|
|
|
2021-09-11 19:02:15 +00:00
|
|
|
$this->repository->expects('setServer->sync')->twice()->andReturnSelf();
|
2020-10-08 04:56:44 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
$this->getService()->toggle($server);
|
2020-10-08 04:56:44 +00:00
|
|
|
|
2021-09-11 19:02:15 +00:00
|
|
|
$this->assertTrue($server->refresh()->isSuspended());
|
2020-10-08 04:56:44 +00:00
|
|
|
|
|
|
|
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
|
|
|
|
|
2021-09-11 19:02:15 +00:00
|
|
|
$this->assertFalse($server->refresh()->isSuspended());
|
2020-10-08 04:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoActionIsTakenIfSuspensionStatusIsUnchanged()
|
|
|
|
{
|
2021-01-17 23:51:56 +00:00
|
|
|
$server = $this->createServerModel();
|
2020-10-08 04:56:44 +00:00
|
|
|
|
|
|
|
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
|
|
|
|
|
|
|
|
$server->refresh();
|
2021-01-17 23:51:56 +00:00
|
|
|
$this->assertFalse($server->isSuspended());
|
2020-10-08 04:56:44 +00:00
|
|
|
|
2021-01-17 23:51:56 +00:00
|
|
|
$server->update(['status' => Server::STATUS_SUSPENDED]);
|
2022-10-14 16:59:20 +00:00
|
|
|
$this->getService()->toggle($server);
|
2020-10-08 04:56:44 +00:00
|
|
|
|
|
|
|
$server->refresh();
|
2021-01-17 23:51:56 +00:00
|
|
|
$this->assertTrue($server->isSuspended());
|
2020-10-08 04:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testExceptionIsThrownIfInvalidActionsArePassed()
|
|
|
|
{
|
|
|
|
$server = $this->createServerModel();
|
|
|
|
|
2022-11-29 17:53:59 +00:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
2020-10-08 04:56:44 +00:00
|
|
|
$this->expectExceptionMessage('Expected one of: "suspend", "unsuspend". Got: "foo"');
|
|
|
|
|
|
|
|
$this->getService()->toggle($server, 'foo');
|
|
|
|
}
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
private function getService(): SuspensionService
|
2020-10-08 04:56:44 +00:00
|
|
|
{
|
|
|
|
return $this->app->make(SuspensionService::class);
|
|
|
|
}
|
|
|
|
}
|