Laravel 10 (#4706)

This commit is contained in:
Matthew Penner 2023-02-23 12:30:16 -07:00 committed by GitHub
parent ad4ddc6300
commit 1d38b4f0e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
136 changed files with 1735 additions and 2008 deletions

View file

@ -2,8 +2,6 @@
namespace Pterodactyl\Tests\Integration\Services\Allocations;
use Exception;
use InvalidArgumentException;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Pterodactyl\Services\Allocations\FindAssignableAllocationService;
@ -142,8 +140,8 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
try {
$this->getService()->handle($server);
$this->fail('This assertion should not be reached.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
} catch (\Exception $exception) {
$this->assertInstanceOf(\InvalidArgumentException::class, $exception);
$this->assertSame('Expected an integerish value. Got: string', $exception->getMessage());
}
@ -153,8 +151,8 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
try {
$this->getService()->handle($server);
$this->fail('This assertion should not be reached.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
} catch (\Exception $exception) {
$this->assertInstanceOf(\InvalidArgumentException::class, $exception);
$this->assertSame('Expected an integerish value. Got: string', $exception->getMessage());
}
}

View file

@ -2,10 +2,7 @@
namespace Pterodactyl\Tests\Integration\Services\Databases;
use Mockery;
use Mockery\MockInterface;
use BadMethodCallException;
use InvalidArgumentException;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\DatabaseHost;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
@ -79,7 +76,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The database name passed to DatabaseManagementService::handle MUST be prefixed with "s{server_id}_".');
$this->getService()->create($server, $data);
@ -134,13 +131,13 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
// assertions that would get caught by the functions catcher and thus lead to the exception
// being swallowed incorrectly.
$this->repository->expects('createUser')->with(
Mockery::on(function ($value) use (&$username) {
\Mockery::on(function ($value) use (&$username) {
$username = $value;
return true;
}),
'%',
Mockery::on(function ($value) use (&$password) {
\Mockery::on(function ($value) use (&$password) {
$password = $value;
return true;
@ -148,7 +145,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
null
);
$this->repository->expects('assignUserToDatabase')->with($name, Mockery::on(function ($value) use (&$secondUsername) {
$this->repository->expects('assignUserToDatabase')->with($name, \Mockery::on(function ($value) use (&$secondUsername) {
$secondUsername = $value;
return true;
@ -182,11 +179,11 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$this->repository->expects('createDatabase')->with($name)->andThrows(new BadMethodCallException());
$this->repository->expects('createDatabase')->with($name)->andThrows(new \BadMethodCallException());
$this->repository->expects('dropDatabase')->with($name);
$this->repository->expects('dropUser')->withAnyArgs()->andThrows(new InvalidArgumentException());
$this->repository->expects('dropUser')->withAnyArgs()->andThrows(new \InvalidArgumentException());
$this->expectException(BadMethodCallException::class);
$this->expectException(\BadMethodCallException::class);
$this->getService()->create($server, [
'remote' => '%',
@ -197,7 +194,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$this->assertDatabaseMissing('databases', ['server_id' => $server->id]);
}
public function invalidDataDataProvider(): array
public static function invalidDataDataProvider(): array
{
return [
[[]],

View file

@ -2,10 +2,8 @@
namespace Pterodactyl\Tests\Integration\Services\Databases;
use Mockery;
use Mockery\MockInterface;
use Pterodactyl\Models\Node;
use InvalidArgumentException;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\DatabaseHost;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
@ -24,7 +22,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
parent::setUp();
$this->managementService = Mockery::mock(DatabaseManagementService::class);
$this->managementService = \Mockery::mock(DatabaseManagementService::class);
$this->swap(DatabaseManagementService::class, $this->managementService);
}
@ -50,7 +48,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/^Expected a non-empty value\. Got: /');
$this->getService()->handle($server, $data);
}
@ -142,7 +140,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
$this->assertInstanceOf(Database::class, $response);
}
public function invalidDataProvider(): array
public static function invalidDataProvider(): array
{
return [
[['remote' => '%']],

View file

@ -2,9 +2,7 @@
namespace Pterodactyl\Tests\Integration\Services\Deployment;
use Exception;
use Pterodactyl\Models\Node;
use InvalidArgumentException;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\Location;
@ -26,7 +24,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
public function testExceptionIsThrownIfNoDiskSpaceHasBeenSet()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Disk space must be an int, got NULL');
$this->getService()->handle();
@ -34,7 +32,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
public function testExceptionIsThrownIfNoMemoryHasBeenSet()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Memory usage must be an int, got NULL');
$this->getService()->setDisk(10)->handle();
@ -54,16 +52,16 @@ class FindViableNodesServiceTest extends IntegrationTestCase
try {
$this->getService()->setLocations(['a']);
$this->fail('This expectation should not be called.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
} catch (\Exception $exception) {
$this->assertInstanceOf(\InvalidArgumentException::class, $exception);
$this->assertSame('An array of location IDs should be provided when calling setLocations.', $exception->getMessage());
}
try {
$this->getService()->setLocations(['1.2', '1', 2]);
$this->fail('This expectation should not be called.');
} catch (Exception $exception) {
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
} catch (\Exception $exception) {
$this->assertInstanceOf(\InvalidArgumentException::class, $exception);
$this->assertSame('An array of location IDs should be provided when calling setLocations.', $exception->getMessage());
}
}

View file

@ -2,11 +2,9 @@
namespace Pterodactyl\Tests\Integration\Services\Schedules;
use Mockery;
use Exception;
use Carbon\CarbonImmutable;
use Pterodactyl\Models\Task;
use InvalidArgumentException;
use Pterodactyl\Models\Schedule;
use Illuminate\Support\Facades\Bus;
use Illuminate\Contracts\Bus\Dispatcher;
@ -47,7 +45,7 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
/** @var \Pterodactyl\Models\Task $task */
$task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]);
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->getService()->handle($schedule);
@ -126,7 +124,7 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
*/
public function testTaskDispatchedNowIsResetProperlyIfErrorIsEncountered()
{
$this->swap(Dispatcher::class, $dispatcher = Mockery::mock(Dispatcher::class));
$this->swap(Dispatcher::class, $dispatcher = \Mockery::mock(Dispatcher::class));
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Schedule $schedule */
@ -134,9 +132,9 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
/** @var \Pterodactyl\Models\Task $task */
$task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]);
$dispatcher->expects('dispatchNow')->andThrows(new Exception('Test thrown exception'));
$dispatcher->expects('dispatchNow')->andThrows(new \Exception('Test thrown exception'));
$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Test thrown exception');
$this->getService()->handle($schedule, true);
@ -150,7 +148,7 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$this->assertDatabaseHas('tasks', ['id' => $task->id, 'is_queued' => false]);
}
public function dispatchNowDataProvider(): array
public static function dispatchNowDataProvider(): array
{
return [[true], [false]];
}

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Mockery\MockInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
@ -108,7 +107,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->daemonServerRepository->expects('setServer')->with(Mockery::on(function (Server $s) use ($server) {
$this->daemonServerRepository->expects('setServer')->with(\Mockery::on(function (Server $s) use ($server) {
return $s->id === $server->id;
}))->andReturnSelf();

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Mockery\MockInterface;
use Pterodactyl\Models\Egg;
use GuzzleHttp\Psr7\Request;
@ -42,7 +41,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
->where('name', 'Bungeecord')
->firstOrFail();
$this->daemonServerRepository = Mockery::mock(DaemonServerRepository::class);
$this->daemonServerRepository = \Mockery::mock(DaemonServerRepository::class);
$this->swap(DaemonServerRepository::class, $this->daemonServerRepository);
}

View file

@ -2,8 +2,6 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Exception;
use Mockery\MockInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
@ -35,8 +33,8 @@ class ServerDeletionServiceTest extends IntegrationTestCase
// There will be some log calls during this test, don't actually write to the disk.
config()->set('logging.default', 'null');
$this->daemonServerRepository = Mockery::mock(DaemonServerRepository::class);
$this->databaseManagementService = Mockery::mock(DatabaseManagementService::class);
$this->daemonServerRepository = \Mockery::mock(DaemonServerRepository::class);
$this->databaseManagementService = \Mockery::mock(DatabaseManagementService::class);
$this->app->instance(DaemonServerRepository::class, $this->daemonServerRepository);
$this->app->instance(DatabaseManagementService::class, $this->databaseManagementService);
@ -120,11 +118,11 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$server->refresh();
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andReturnUndefined();
$this->databaseManagementService->expects('delete')->with(Mockery::on(function ($value) use ($db) {
$this->databaseManagementService->expects('delete')->with(\Mockery::on(function ($value) use ($db) {
return $value instanceof Database && $value->id === $db->id;
}))->andThrows(new Exception());
}))->andThrows(new \Exception());
$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->getService()->handle($server);
$this->assertDatabaseHas('servers', ['id' => $server->id]);
@ -145,9 +143,9 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$server->refresh();
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andReturnUndefined();
$this->databaseManagementService->expects('delete')->with(Mockery::on(function ($value) use ($db) {
$this->databaseManagementService->expects('delete')->with(\Mockery::on(function ($value) use ($db) {
return $value instanceof Database && $value->id === $db->id;
}))->andThrows(new Exception());
}))->andThrows(new \Exception());
$this->getService()->withForce(true)->handle($server);

View file

@ -34,7 +34,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
]);
$this->fail('This assertion should not be called.');
} catch (Exception $exception) {
} catch (\Exception $exception) {
$this->assertInstanceOf(ValidationException::class, $exception);
/** @var \Illuminate\Validation\ValidationException $exception */

View file

@ -2,9 +2,7 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Mockery\MockInterface;
use InvalidArgumentException;
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Servers\SuspensionService;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
@ -21,7 +19,7 @@ class SuspensionServiceTest extends IntegrationTestCase
{
parent::setUp();
$this->repository = Mockery::mock(DaemonServerRepository::class);
$this->repository = \Mockery::mock(DaemonServerRepository::class);
$this->app->instance(DaemonServerRepository::class, $this->repository);
}
@ -60,7 +58,7 @@ class SuspensionServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected one of: "suspend", "unsuspend". Got: "foo"');
$this->getService()->toggle($server, 'foo');