Begin moving packs to new service mechanisms, refactor exceptions for services

This commit is contained in:
Dane Everitt 2017-08-18 22:19:06 -05:00
parent 46cb71e69d
commit 9d3dca87f2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
62 changed files with 492 additions and 303 deletions

View file

@ -99,6 +99,9 @@ class DatabaseControllerTest extends TestCase
$this->assertViewKeyEquals('hosts', 'getWithViewDetails', $view);
}
/**
* Test the view controller for displaying a specific database host.
*/
public function testViewController()
{
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn('getAllWithNodes');

View file

@ -71,7 +71,7 @@ class AssignmentServiceTest extends TestCase
//
// This can also be avoided if tests were run in isolated processes, or if that test
// came first, but neither of those are good solutions, so this is the next best option.
PHPMock::defineFunctionMock('\\Pterodactyl\\Services\\Allocations', 'gethostbyname');
PHPMock::defineFunctionMock('\\Pterodactyl\\Service\\Allocations', 'gethostbyname');
$this->node = factory(Node::class)->make();
$this->connection = m::mock(ConnectionInterface::class);
@ -180,7 +180,7 @@ class AssignmentServiceTest extends TestCase
'allocation_ports' => ['1024'],
];
$this->getFunctionMock('\\Pterodactyl\\Services\\Allocations', 'gethostbyname')
$this->getFunctionMock('\\Pterodactyl\\Service\\Allocations', 'gethostbyname')
->expects($this->once())->willReturn('192.168.1.1');
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();

View file

@ -81,7 +81,7 @@ class KeyServiceTest extends TestCase
*/
public function test_create_function()
{
$this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'random_bytes')
$this->getFunctionMock('\\Pterodactyl\\Service\\Api', 'random_bytes')
->expects($this->exactly(2))
->willReturnCallback(function ($bytes) {
return hex2bin(str_pad('', $bytes * 2, '0'));

View file

@ -84,7 +84,7 @@ class DatabaseManagementServiceTest extends TestCase
$this->encrypter = m::mock(Encrypter::class);
$this->repository = m::mock(DatabaseRepositoryInterface::class);
$this->getFunctionMock('\\Pterodactyl\\Services\\Database', 'str_random')
$this->getFunctionMock('\\Pterodactyl\\Service\\Database', 'str_random')
->expects($this->any())->willReturn('str_random');
$this->service = new DatabaseManagementService(

View file

@ -61,7 +61,7 @@ class CreationServiceTest extends TestCase
*/
public function testNodeIsCreatedAndDaemonSecretIsGenerated()
{
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'bin2hex')
$this->getFunctionMock('\\Pterodactyl\\Service\\Nodes', 'bin2hex')
->expects($this->once())->willReturn('hexResult');
$this->repository->shouldReceive('create')->with([

View file

@ -97,14 +97,14 @@ class UpdateServiceTest extends TestCase
*/
public function testNodeIsUpdatedAndDaemonSecretIsReset()
{
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'random_bytes')
$this->getFunctionMock('\\Pterodactyl\\Service\\Nodes', 'random_bytes')
->expects($this->once())->willReturnCallback(function ($bytes) {
$this->assertEquals(CreationService::DAEMON_SECRET_LENGTH, $bytes);
return '\00';
});
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'bin2hex')
$this->getFunctionMock('\\Pterodactyl\\Service\\Nodes', 'bin2hex')
->expects($this->once())->willReturn('hexResponse');
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()

View file

@ -155,7 +155,7 @@ class CreationServiceTest extends TestCase
$this->uuid = m::mock('overload:Ramsey\Uuid\Uuid');
$this->writer = m::mock(Writer::class);
$this->getFunctionMock('\\Pterodactyl\\Services\\Servers', 'bin2hex')
$this->getFunctionMock('\\Pterodactyl\\Service\\Servers', 'bin2hex')
->expects($this->any())->willReturn('randomstring');
$this->getFunctionMock('\\Ramsey\\Uuid\\Uuid', 'uuid4')

View file

@ -84,7 +84,7 @@ class DetailsModificationServiceTest extends TestCase
$this->repository = m::mock(ServerRepository::class);
$this->writer = m::mock(Writer::class);
$this->getFunctionMock('\\Pterodactyl\\Services\\Servers', 'bin2hex')
$this->getFunctionMock('\\Pterodactyl\\Service\\Servers', 'bin2hex')
->expects($this->any())->willReturn('randomString');
$this->service = new DetailsModificationService(

View file

@ -46,10 +46,10 @@ class UsernameGenerationServiceTest extends TestCase
$this->service = new UsernameGenerationService();
$this->getFunctionMock('\\Pterodactyl\\Services\\Servers', 'bin2hex')
$this->getFunctionMock('\\Pterodactyl\\Service\\Servers', 'bin2hex')
->expects($this->any())->willReturn('dddddddd');
$this->getFunctionMock('\\Pterodactyl\\Services\\Servers', 'str_random')
$this->getFunctionMock('\\Pterodactyl\\Service\\Servers', 'str_random')
->expects($this->any())->willReturnCallback(function ($count) {
return str_pad('', $count, 'a');
});

View file

@ -30,7 +30,7 @@ use Tests\TestCase;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Services\Services\Options\InstallScriptUpdateService;
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
use Pterodactyl\Exceptions\Services\ServiceOption\InvalidCopyFromException;
use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException;
class InstallScriptUpdateServiceTest extends TestCase
{

View file

@ -30,7 +30,7 @@ use Tests\TestCase;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Services\Services\Options\OptionCreationService;
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
use Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException;
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
class OptionCreationServiceTest extends TestCase
{

View file

@ -26,7 +26,7 @@ namespace Tests\Unit\Services\Services\Options;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Exceptions\Services\HasActiveServersException;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Services\Services\Options\OptionDeletionService;
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;

View file

@ -30,7 +30,7 @@ use Tests\TestCase;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Services\Services\Options\OptionUpdateService;
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
use Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException;
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
class OptionUpdateServiceTest extends TestCase
{

View file

@ -28,7 +28,7 @@ use Exception;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Services\Services\ServiceDeletionService;
use Pterodactyl\Exceptions\Services\HasActiveServersException;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;

View file

@ -99,7 +99,7 @@ class VariableCreationServiceTest extends TestCase
* Test that all of the reserved variables defined in the model trigger an exception.
*
* @dataProvider reservedNamesProvider
* @expectedException \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
* @expectedException \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
*/
public function testExceptionIsThrownIfEnvironmentVariableIsInListOfReservedNames($variable)
{

View file

@ -126,7 +126,7 @@ class VariableUpdateServiceTest extends TestCase
* Test that all of the reserved variables defined in the model trigger an exception.
*
* @dataProvider reservedNamesProvider
* @expectedException \Pterodactyl\Exceptions\Services\ServiceVariable\ReservedVariableNameException
* @expectedException \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
*/
public function testExceptionIsThrownIfEnvironmentVariableIsInListOfReservedNames($variable)
{