mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-18 22:33:44 +02:00
Add some additional test coverage and clean up modification service and suspension service
This commit is contained in:
80
tests/Integration/Services/Servers/SuspensionServiceTest.php
Normal file
80
tests/Integration/Services/Servers/SuspensionServiceTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Integration\Services\Servers;
|
||||
|
||||
use Mockery;
|
||||
use InvalidArgumentException;
|
||||
use Pterodactyl\Services\Servers\SuspensionService;
|
||||
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
|
||||
class SuspensionServiceTest extends IntegrationTestCase
|
||||
{
|
||||
/** @var \Mockery\MockInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Setup test instance.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->repository = Mockery::mock(DaemonServerRepository::class);
|
||||
$this->app->instance(DaemonServerRepository::class, $this->repository);
|
||||
}
|
||||
|
||||
public function testServerIsSuspendedAndUnsuspended()
|
||||
{
|
||||
$server = $this->createServerModel(['suspended' => false]);
|
||||
|
||||
$this->repository->expects('setServer')->twice()->andReturnSelf();
|
||||
$this->repository->expects('suspend')->with(false)->andReturnUndefined();
|
||||
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertTrue($server->suspended);
|
||||
|
||||
$this->repository->expects('suspend')->with(true)->andReturnUndefined();
|
||||
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertFalse($server->suspended);
|
||||
}
|
||||
|
||||
public function testNoActionIsTakenIfSuspensionStatusIsUnchanged()
|
||||
{
|
||||
$server = $this->createServerModel(['suspended' => false]);
|
||||
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertFalse($server->suspended);
|
||||
|
||||
$server->update(['suspended' => true]);
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertTrue($server->suspended);
|
||||
}
|
||||
|
||||
public function testExceptionIsThrownIfInvalidActionsArePassed()
|
||||
{
|
||||
$server = $this->createServerModel();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Expected one of: "suspend", "unsuspend". Got: "foo"');
|
||||
|
||||
$this->getService()->toggle($server, 'foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Pterodactyl\Services\Servers\SuspensionService
|
||||
*/
|
||||
private function getService()
|
||||
{
|
||||
return $this->app->make(SuspensionService::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user