Path: blob/1.0-develop/tests/Integration/Services/Servers/SuspensionServiceTest.php
7460 views
<?php12namespace Pterodactyl\Tests\Integration\Services\Servers;34use Mockery\MockInterface;5use Pterodactyl\Models\Server;6use Pterodactyl\Services\Servers\SuspensionService;7use Pterodactyl\Tests\Integration\IntegrationTestCase;8use Pterodactyl\Repositories\Wings\DaemonServerRepository;910class SuspensionServiceTest extends IntegrationTestCase11{12private MockInterface $repository;1314/**15* Setup test instance.16*/17public function setUp(): void18{19parent::setUp();2021$this->repository = \Mockery::mock(DaemonServerRepository::class);22$this->app->instance(DaemonServerRepository::class, $this->repository);23}2425public function testServerIsSuspendedAndUnsuspended()26{27$server = $this->createServerModel();2829$this->repository->expects('setServer->sync')->twice()->andReturnSelf();3031$this->getService()->toggle($server);3233$this->assertTrue($server->refresh()->isSuspended());3435$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);3637$this->assertFalse($server->refresh()->isSuspended());38}3940public function testNoActionIsTakenIfSuspensionStatusIsUnchanged()41{42$server = $this->createServerModel();4344$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);4546$server->refresh();47$this->assertFalse($server->isSuspended());4849$server->update(['status' => Server::STATUS_SUSPENDED]);50$this->getService()->toggle($server);5152$server->refresh();53$this->assertTrue($server->isSuspended());54}5556public function testExceptionIsThrownIfInvalidActionsArePassed()57{58$server = $this->createServerModel();5960$this->expectException(\InvalidArgumentException::class);61$this->expectExceptionMessage('Expected one of: "suspend", "unsuspend". Got: "foo"');6263$this->getService()->toggle($server, 'foo');64}6566private function getService(): SuspensionService67{68return $this->app->make(SuspensionService::class);69}70}717273