Upgrade to Laravel 9 (#4413)

Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner 2022-10-14 10:59:20 -06:00 committed by GitHub
parent 95e15d2c8a
commit cbcf62086f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
573 changed files with 4387 additions and 9411 deletions

View file

@ -25,7 +25,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
}
/**
* Test that an unassigned allocation is prefered rather than creating an entirely new
* Test that an unassigned allocation is preferred rather than creating an entirely new
* allocation for the server.
*/
public function testExistingAllocationIsPreferred()
@ -141,7 +141,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
try {
$this->getService()->handle($server);
$this->assertTrue(false, 'This assertion should not be reached.');
$this->fail('This assertion should not be reached.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
$this->assertSame('Expected an integerish value. Got: string', $exception->getMessage());
@ -152,7 +152,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
try {
$this->getService()->handle($server);
$this->assertTrue(false, 'This assertion should not be reached.');
$this->fail('This assertion should not be reached.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
$this->assertSame('Expected an integerish value. Got: string', $exception->getMessage());
@ -169,10 +169,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
$this->getService()->handle($server);
}
/**
* @return \Pterodactyl\Services\Allocations\FindAssignableAllocationService
*/
private function getService()
private function getService(): FindAssignableAllocationService
{
return $this->app->make(FindAssignableAllocationService::class);
}

View file

@ -2,12 +2,12 @@
namespace Pterodactyl\Tests\Integration\Services\Backups;
use Mockery;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Backup;
use GuzzleHttp\Exception\ClientException;
use Pterodactyl\Extensions\Backups\BackupManager;
use Pterodactyl\Extensions\Filesystem\S3Filesystem;
use Pterodactyl\Services\Backups\DeleteBackupService;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
@ -16,17 +16,6 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class DeleteBackupServiceTest extends IntegrationTestCase
{
private $repository;
public function setUp(): void
{
parent::setUp();
$this->repository = Mockery::mock(DaemonBackupRepository::class);
$this->app->instance(DaemonBackupRepository::class, $this->repository);
}
public function testLockedBackupCannotBeDeleted()
{
$server = $this->createServerModel();
@ -49,9 +38,8 @@ class DeleteBackupServiceTest extends IntegrationTestCase
'is_successful' => false,
]);
$this->repository->expects('setServer->delete')->with($backup)->andReturn(
new Response()
);
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andReturn(new Response());
$this->app->make(DeleteBackupService::class)->handle($backup);
@ -65,7 +53,8 @@ class DeleteBackupServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$backup = Backup::factory()->create(['server_id' => $server->id]);
$this->repository->expects('setServer->delete')->with($backup)->andThrow(
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andThrow(
new DaemonConnectionException(
new ClientException('', new Request('DELETE', '/'), new Response(404))
)
@ -83,7 +72,8 @@ class DeleteBackupServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$backup = Backup::factory()->create(['server_id' => $server->id]);
$this->repository->expects('setServer->delete')->with($backup)->andThrow(
$mock = $this->mock(DaemonBackupRepository::class);
$mock->expects('setServer->delete')->with($backup)->andThrow(
new DaemonConnectionException(
new ClientException('', new Request('DELETE', '/'), new Response(500))
)
@ -107,17 +97,18 @@ class DeleteBackupServiceTest extends IntegrationTestCase
]);
$manager = $this->mock(BackupManager::class);
$manager->expects('getBucket')->andReturns('foobar');
$manager->expects('adapter')->with(Backup::ADAPTER_AWS_S3)->andReturnSelf();
$manager->expects('getClient->deleteObject')->with([
$adapter = $this->mock(S3Filesystem::class);
$manager->expects('adapter')->with(Backup::ADAPTER_AWS_S3)->andReturn($adapter);
$adapter->expects('getBucket')->andReturn('foobar');
$adapter->expects('getClient->deleteObject')->with([
'Bucket' => 'foobar',
'Key' => sprintf('%s/%s.tar.gz', $server->uuid, $backup->uuid),
]);
$this->app->make(DeleteBackupService::class)->handle($backup);
$backup->refresh();
$this->assertNotNull($backup->deleted_at);
$this->assertSoftDeleted($backup);
}
}

View file

@ -3,6 +3,7 @@
namespace Pterodactyl\Tests\Integration\Services\Databases;
use Mockery;
use Mockery\MockInterface;
use BadMethodCallException;
use InvalidArgumentException;
use Pterodactyl\Models\Database;
@ -16,8 +17,7 @@ use Pterodactyl\Exceptions\Service\Database\DatabaseClientFeatureNotEnabledExcep
class DatabaseManagementServiceTest extends IntegrationTestCase
{
/** @var \Mockery\MockInterface */
private $repository;
private MockInterface $repository;
/**
* Setup tests.
@ -28,8 +28,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
config()->set('pterodactyl.client_features.databases.enabled', true);
$this->repository = Mockery::mock(DatabaseRepository::class);
$this->swap(DatabaseRepository::class, $this->repository);
$this->repository = $this->mock(DatabaseRepository::class);
}
/**
@ -74,10 +73,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
/**
* Test that a missing or invalid database name format causes an exception to be thrown.
*
* @param array $data
* @dataProvider invalidDataDataProvider
*/
public function testEmptyDatabaseNameOrInvalidNameTriggersAnException($data)
public function testEmptyDatabaseNameOrInvalidNameTriggersAnException(array $data)
{
$server = $this->createServerModel();
@ -166,7 +164,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$this->assertInstanceOf(Database::class, $response);
$this->assertSame($response->server_id, $server->id);
$this->assertMatchesRegularExpression('/^(u[\d]+_)(\w){10}$/', $username);
$this->assertMatchesRegularExpression('/^(u\d+_)(\w){10}$/', $username);
$this->assertSame($username, $secondUsername);
$this->assertSame(24, strlen($password));
@ -174,8 +172,8 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
}
/**
* Test that an exception encountered while creating the database leads to cleanup code being called
* and any exceptions encountered while cleaning up go unreported.
* Test that an exception encountered while creating the database leads to the cleanup code
* being called and any exceptions encountered while cleaning up go unreported.
*/
public function testExceptionEncounteredWhileCreatingDatabaseAttemptsToCleanup()
{
@ -211,10 +209,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
];
}
/**
* @return \Pterodactyl\Services\Databases\DatabaseManagementService
*/
private function getService()
private function getService(): DatabaseManagementService
{
return $this->app->make(DatabaseManagementService::class);
}

View file

@ -3,6 +3,7 @@
namespace Pterodactyl\Tests\Integration\Services\Databases;
use Mockery;
use Mockery\MockInterface;
use Pterodactyl\Models\Node;
use InvalidArgumentException;
use Pterodactyl\Models\Database;
@ -14,8 +15,7 @@ use Pterodactyl\Exceptions\Service\Database\NoSuitableDatabaseHostException;
class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
/** @var \Mockery\MockInterface */
private $managementService;
private MockInterface $managementService;
/**
* Setup tests.
@ -44,10 +44,9 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
/**
* Test that an error is thrown if either the database name or the remote host are empty.
*
* @param array $data
* @dataProvider invalidDataProvider
*/
public function testErrorIsThrownIfDatabaseNameIsEmpty($data)
public function testErrorIsThrownIfDatabaseNameIsEmpty(array $data)
{
$server = $this->createServerModel();
@ -154,10 +153,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
];
}
/**
* @return \Pterodactyl\Services\Databases\DeployServerDatabaseService
*/
private function getService()
private function getService(): DeployServerDatabaseService
{
return $this->app->make(DeployServerDatabaseService::class);
}

View file

@ -53,7 +53,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
try {
$this->getService()->setLocations(['a']);
$this->assertTrue(false, 'This expectation should not be called.');
$this->fail('This expectation should not be called.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
$this->assertSame('An array of location IDs should be provided when calling setLocations.', $exception->getMessage());
@ -61,7 +61,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
try {
$this->getService()->setLocations(['1.2', '1', 2]);
$this->assertTrue(false, 'This expectation should not be called.');
$this->fail('This expectation should not be called.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
$this->assertSame('An array of location IDs should be provided when calling setLocations.', $exception->getMessage());
@ -96,7 +96,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
]),
];
// Expect that all of the nodes are returned as we're under all of their limits
// Expect that all the nodes are returned as we're under all of their limits
// and there is no location filter being provided.
$response = $this->getService()->setDisk(512)->setMemory(512)->handle();
$this->assertInstanceOf(Collection::class, $response);
@ -182,10 +182,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
$this->assertSame($nodes[1]->id, $response[0]->id);
}
/**
* @return \Pterodactyl\Services\Deployment\FindViableNodesService
*/
private function getService()
private function getService(): FindViableNodesService
{
return $this->app->make(FindViableNodesService::class);
}

View file

@ -58,10 +58,9 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
/**
* Test that a job is dispatched as expected using the initial delay.
*
* @param bool $now
* @dataProvider dispatchNowDataProvider
*/
public function testJobCanBeDispatchedWithExpectedInitialDelay($now)
public function testJobCanBeDispatchedWithExpectedInitialDelay(bool $now)
{
Bus::fake();
@ -156,10 +155,7 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
return [[true], [false]];
}
/**
* @return \Pterodactyl\Services\Schedules\ProcessScheduleService
*/
private function getService()
private function getService(): ProcessScheduleService
{
return $this->app->make(ProcessScheduleService::class);
}

View file

@ -3,6 +3,7 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Mockery\MockInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Server;
@ -16,8 +17,7 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class BuildModificationServiceTest extends IntegrationTestCase
{
/** @var \Mockery\MockInterface */
private $daemonServerRepository;
private MockInterface $daemonServerRepository;
/**
* Setup tests.
@ -183,7 +183,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
/**
* Test that allocations in both the add and remove arrays are only added, and not removed.
* This scenario wouldn't really happen in the UI, but it is possible to perform via the API
* This scenario wouldn't really happen in the UI, but it is possible to perform via the API,
* so we want to make sure that the logic being used doesn't break if the allocation exists
* in both arrays.
*
@ -229,7 +229,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
/**
* Test that any changes we made to the server or allocations are rolled back if there is an
* exception while performing any action. This is different than the connection exception
* exception while performing any action. This is different from the connection exception
* test which should properly ignore connection issues. We want any other type of exception
* to properly be thrown back to the caller.
*/
@ -248,10 +248,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
$this->assertDatabaseHas('allocations', ['id' => $allocation->id, 'server_id' => null]);
}
/**
* @return \Pterodactyl\Services\Servers\BuildModificationService
*/
private function getService()
private function getService(): BuildModificationService
{
return $this->app->make(BuildModificationService::class);
}

View file

@ -3,6 +3,7 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Mockery\MockInterface;
use Pterodactyl\Models\Egg;
use GuzzleHttp\Psr7\Request;
use Pterodactyl\Models\Node;
@ -24,8 +25,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
{
use WithFaker;
/** @var \Mockery\MockInterface */
protected $daemonServerRepository;
protected MockInterface $daemonServerRepository;
protected Egg $bungeecord;
@ -208,10 +208,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
$this->assertDatabaseMissing('servers', ['owner_id' => $user->id]);
}
/**
* @return \Pterodactyl\Services\Servers\ServerCreationService
*/
private function getService()
private function getService(): ServerCreationService
{
return $this->app->make(ServerCreationService::class);
}

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Exception;
use Mockery\MockInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\DatabaseHost;
use GuzzleHttp\Exception\BadResponseException;
@ -18,13 +18,11 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class ServerDeletionServiceTest extends IntegrationTestCase
{
/** @var \Mockery\MockInterface */
private $daemonServerRepository;
private MockInterface $daemonServerRepository;
/** @var \Mockery\MockInterface */
private $databaseManagementService;
private MockInterface $databaseManagementService;
private static $defaultLogger;
private static ?string $defaultLogger;
/**
* Stub out services that we don't want to test in here.
@ -102,7 +100,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response(500)))
);
$this->getService()->withForce(true)->handle($server);
$this->getService()->withForce()->handle($server);
$this->assertDatabaseMissing('servers', ['id' => $server->id]);
}
@ -157,10 +155,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$this->assertDatabaseMissing('databases', ['id' => $db->id]);
}
/**
* @return \Pterodactyl\Services\Servers\ServerDeletionService
*/
private function getService()
private function getService(): ServerDeletionService
{
return $this->app->make(ServerDeletionService::class);
}

View file

@ -33,7 +33,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
],
]);
$this->assertTrue(false, 'This assertion should not be called.');
$this->fail('This assertion should not be called.');
} catch (Exception $exception) {
$this->assertInstanceOf(ValidationException::class, $exception);
@ -161,10 +161,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
->handle($server, ['egg_id' => 123456789]);
}
/**
* @return \Pterodactyl\Services\Servers\StartupModificationService
*/
private function getService()
private function getService(): StartupModificationService
{
return $this->app->make(StartupModificationService::class);
}

View file

@ -3,6 +3,7 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Mockery\MockInterface;
use InvalidArgumentException;
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Servers\SuspensionService;
@ -11,8 +12,7 @@ use Pterodactyl\Repositories\Wings\DaemonServerRepository;
class SuspensionServiceTest extends IntegrationTestCase
{
/** @var \Mockery\MockInterface */
private $repository;
private MockInterface $repository;
/**
* Setup test instance.
@ -31,7 +31,7 @@ class SuspensionServiceTest extends IntegrationTestCase
$this->repository->expects('setServer->sync')->twice()->andReturnSelf();
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
$this->getService()->toggle($server);
$this->assertTrue($server->refresh()->isSuspended());
@ -50,7 +50,7 @@ class SuspensionServiceTest extends IntegrationTestCase
$this->assertFalse($server->isSuspended());
$server->update(['status' => Server::STATUS_SUSPENDED]);
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
$this->getService()->toggle($server);
$server->refresh();
$this->assertTrue($server->isSuspended());
@ -66,10 +66,7 @@ class SuspensionServiceTest extends IntegrationTestCase
$this->getService()->toggle($server, 'foo');
}
/**
* @return \Pterodactyl\Services\Servers\SuspensionService
*/
private function getService()
private function getService(): SuspensionService
{
return $this->app->make(SuspensionService::class);
}

View file

@ -25,7 +25,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
}
/**
* Test that enviornment variables for a server are validated as expected.
* Test that environment variables for a server are validated as expected.
*/
public function testEnvironmentVariablesCanBeValidated()
{
@ -36,7 +36,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
'BUNGEE_VERSION' => '1.2.3',
]);
$this->assertTrue(false, 'This statement should not be reached.');
$this->fail('This statement should not be reached.');
} catch (ValidationException $exception) {
$errors = $exception->errors();
@ -96,7 +96,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
'SERVER_JARFILE' => 'server.jar',
]);
$this->assertTrue(false, 'This statement should not be reached.');
$this->fail('This statement should not be reached.');
} catch (ValidationException $exception) {
$this->assertCount(1, $exception->errors());
$this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors());
@ -135,10 +135,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
$this->assertSame('', $response->get(0)->value);
}
/**
* @return \Pterodactyl\Services\Servers\VariableValidatorService
*/
private function getService()
private function getService(): VariableValidatorService
{
return $this->app->make(VariableValidatorService::class);
}