forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationDeletionServiceTest.php
More file actions
76 lines (64 loc) · 2.28 KB
/
LocationDeletionServiceTest.php
File metadata and controls
76 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Tests\Unit\Services\Locations;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Services\Locations\LocationDeletionService;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
class LocationDeletionServiceTest extends TestCase
{
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
protected $nodeRepository;
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Services\Locations\LocationDeletionService
*/
protected $service;
/**
* Setup tests.
*/
public function setUp()
{
parent::setUp();
$this->nodeRepository = m::mock(NodeRepositoryInterface::class);
$this->repository = m::mock(LocationRepositoryInterface::class);
$this->service = new LocationDeletionService($this->repository, $this->nodeRepository);
}
/**
* Test that a location is deleted.
*/
public function testLocationIsDeleted()
{
$this->nodeRepository->shouldReceive('findCountWhere')->with([['location_id', '=', 123]])->once()->andReturn(0);
$this->repository->shouldReceive('delete')->with(123)->once()->andReturn(1);
$response = $this->service->handle(123);
$this->assertEquals(1, $response);
}
/**
* Test that an exception is thrown if nodes are attached to a location.
*/
public function testExceptionIsThrownIfNodesAreAttached()
{
$this->nodeRepository->shouldReceive('findCountWhere')->with([['location_id', '=', 123]])->once()->andReturn(1);
try {
$this->service->handle(123);
} catch (DisplayException $exception) {
$this->assertInstanceOf(HasActiveNodesException::class, $exception);
$this->assertEquals(trans('exceptions.locations.has_nodes'), $exception->getMessage());
}
}
}