2018-01-11 05:19:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Allocations;
|
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Tests\TestCase;
|
|
|
|
use Pterodactyl\Models\Allocation;
|
|
|
|
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
|
|
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
2020-06-25 03:38:13 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException;
|
2018-01-11 05:19:03 +00:00
|
|
|
|
|
|
|
class AllocationDeletionServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = m::mock(AllocationRepositoryInterface::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an allocation is deleted.
|
|
|
|
*/
|
|
|
|
public function testAllocationIsDeleted()
|
|
|
|
{
|
|
|
|
$model = factory(Allocation::class)->make();
|
|
|
|
|
|
|
|
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturn(1);
|
|
|
|
|
|
|
|
$response = $this->getService()->handle($model);
|
|
|
|
$this->assertEquals(1, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an exception gets thrown if an allocation is currently assigned to a server.
|
|
|
|
*/
|
|
|
|
public function testExceptionThrownIfAssignedToServer()
|
|
|
|
{
|
2020-06-25 03:38:13 +00:00
|
|
|
$this->expectException(ServerUsingAllocationException::class);
|
|
|
|
|
2018-01-11 05:19:03 +00:00
|
|
|
$model = factory(Allocation::class)->make(['server_id' => 123]);
|
|
|
|
|
|
|
|
$this->getService()->handle($model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the service with mocked injections.
|
|
|
|
*
|
|
|
|
* @return \Pterodactyl\Services\Allocations\AllocationDeletionService
|
|
|
|
*/
|
|
|
|
private function getService(): AllocationDeletionService
|
|
|
|
{
|
|
|
|
return new AllocationDeletionService($this->repository);
|
|
|
|
}
|
|
|
|
}
|