Use more standardized phpcs

This commit is contained in:
Dane Everitt 2021-01-23 12:33:34 -08:00
parent a043071e3c
commit c449ca5155
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
493 changed files with 1116 additions and 3903 deletions

View file

@ -15,7 +15,9 @@ use Pterodactyl\Tests\Traits\Http\IntegrationJsonRequestAssertions;
abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
{
use CreatesTestModels, DatabaseTransactions, IntegrationJsonRequestAssertions;
use CreatesTestModels;
use DatabaseTransactions;
use IntegrationJsonRequestAssertions;
/**
* @var \Pterodactyl\Models\ApiKey
@ -44,17 +46,11 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
$this->withMiddleware('api..key:' . ApiKey::TYPE_APPLICATION);
}
/**
* @return \Pterodactyl\Models\User
*/
public function getApiUser(): User
{
return $this->user;
}
/**
* @return \Pterodactyl\Models\ApiKey
*/
public function getApiKey(): ApiKey
{
return $this->key;
@ -62,10 +58,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
/**
* Creates a new default API key and refreshes the headers using it.
*
* @param \Pterodactyl\Models\User $user
* @param array $permissions
* @return \Pterodactyl\Models\ApiKey
*/
protected function createNewDefaultApiKey(User $user, array $permissions = []): ApiKey
{
@ -77,8 +69,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
/**
* Refresh the authorization header for a request to use a different API key.
*
* @param \Pterodactyl\Models\ApiKey $key
*/
protected function refreshHeaders(ApiKey $key)
{
@ -87,8 +77,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
/**
* Create an administrative user.
*
* @return \Pterodactyl\Models\User
*/
protected function createApiUser(): User
{
@ -99,10 +87,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
/**
* Create a new application API key for a given user model.
*
* @param \Pterodactyl\Models\User $user
* @param array $permissions
* @return \Pterodactyl\Models\ApiKey
*/
protected function createApiKey(User $user, array $permissions = []): ApiKey
{
@ -123,9 +107,6 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
/**
* Return a transformer that can be used for testing purposes.
*
* @param string $abstract
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
*/
protected function getTransformer(string $abstract): BaseTransformer
{

View file

@ -61,7 +61,9 @@ class EggControllerTest extends ApplicationApiIntegrationTestCase
$expected = json_encode(Arr::sortRecursive($datum['attributes']));
$actual = json_encode(Arr::sortRecursive($this->getTransformer(EggTransformer::class)->transform($egg)));
$this->assertSame($expected, $actual,
$this->assertSame(
$expected,
$actual,
'Unable to find JSON fragment: ' . PHP_EOL . PHP_EOL . "[{$expected}]" . PHP_EOL . PHP_EOL . 'within' . PHP_EOL . PHP_EOL . "[{$actual}]."
);
}

View file

@ -292,9 +292,6 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
* Test that an API key without write permissions cannot create, update, or
* delete a user model.
*
* @param string $method
* @param string $url
*
* @dataProvider userWriteEndpointsDataProvider
*/
public function testApiKeyWithoutWritePermissions(string $method, string $url)
@ -313,8 +310,6 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
/**
* Endpoints that should return a 403 error when the key does not have write
* permissions for user management.
*
* @return array
*/
public function userWriteEndpointsDataProvider(): array
{

View file

@ -44,6 +44,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
* to keep re-assigning variables.
*
* @param \Illuminate\Http\Response $response
*
* @return \Illuminate\Testing\TestResponse
*/
protected function createTestResponse($response)
@ -54,10 +55,8 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
/**
* Returns a link to the specific resource using the client API.
*
* @param mixed $model
* @param mixed $model
* @param string|null $append
*
* @return string
*/
protected function link($model, $append = null): string
{
@ -87,8 +86,6 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
* is assumed that the user is actually a subuser of the server.
*
* @param string[] $permissions
*
* @return array
*/
protected function generateTestAccount(array $permissions = []): array
{
@ -115,7 +112,6 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
* Asserts that the data passed through matches the output of the data from the transformer. This
* will remove the "relationships" key when performing the comparison.
*
* @param array $data
* @param \Pterodactyl\Models\Model|\Illuminate\Database\Eloquent\Model $model
*/
protected function assertJsonTransformedWith(array $data, $model)
@ -123,7 +119,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
$reflect = new ReflectionClass($model);
$transformer = sprintf('\\Pterodactyl\\Transformers\\Api\\Client\\%sTransformer', $reflect->getShortName());
$transformer = new $transformer;
$transformer = new $transformer();
$this->assertInstanceOf(BaseClientTransformer::class, $transformer);
$this->assertSame(

View file

@ -9,8 +9,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
class AllocationAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* @param string $method
* @param string $endpoint
* @dataProvider methodDataProvider
*/
public function testAccessToAServersAllocationsIsRestrictedProperly(string $method, string $endpoint)

View file

@ -24,7 +24,6 @@ class CreateNewAllocationTest extends ClientApiIntegrationTestCase
/**
* Tests that a new allocation can be properly assigned to a server.
*
* @param array $permission
* @dataProvider permissionDataProvider
*/
public function testNewAllocationCanBeAssignedToServer(array $permission)

View file

@ -13,7 +13,6 @@ class DeleteAllocationTest extends ClientApiIntegrationTestCase
* Test that an allocation is deleted from the server and the notes are properly reset
* to an empty value on assignment.
*
* @param array $permission
* @dataProvider permissionDataProvider
*/
public function testAllocationCanBeDeletedFromServer(array $permission)

View file

@ -12,8 +12,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
class BackupAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* @param string $method
* @param string $endpoint
* @dataProvider methodDataProvider
*/
public function testAccessToAServersBackupIsRestrictedProperly(string $method, string $endpoint)

View file

@ -69,7 +69,7 @@ class CommandControllerTest extends ClientApiIntegrationTestCase
$this->repository->expects('setServer')->with(Mockery::on(function ($value) use ($server) {
return $value->uuid === $server->uuid;
}))->andReturnSelf();
$this->repository->expects('send')->with('say Test')->andReturn(new GuzzleResponse);
$this->repository->expects('send')->with('say Test')->andReturn(new GuzzleResponse());
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/command", [
'command' => 'say Test',

View file

@ -14,8 +14,6 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
class DatabaseAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* @param string $method
* @param string $endpoint
* @dataProvider methodDataProvider
*/
public function testAccessToAServersDatabasesIsRestrictedProperly(string $method, string $endpoint)

View file

@ -49,7 +49,6 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase
/**
* Tests that notes on an allocation can be set correctly.
*
* @param array $permissions
* @dataProvider updatePermissionsDataProvider
*/
public function testAllocationNotesCanBeUpdated(array $permissions)
@ -98,7 +97,6 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase
}
/**
* @param array $permissions
* @dataProvider updatePermissionsDataProvider
*/
public function testPrimaryAllocationCanBeModified(array $permissions)

View file

@ -15,7 +15,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
* an error in response. This checks against the specific permission needed to send
* the command to the server.
*
* @param string $action
* @param string[] $permissions
* @dataProvider invalidPermissionDataProvider
*/
@ -47,8 +46,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
/**
* Test that sending a valid power actions works.
*
* @param string $action
* @param string $permission
* @dataProvider validPowerActionDataProvider
*/
public function testActionCanBeSentToServer(string $action, string $permission)
@ -74,8 +71,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
/**
* Returns invalid permission combinations for a given power action.
*
* @return array
*/
public function invalidPermissionDataProvider(): array
{
@ -88,9 +83,6 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
];
}
/**
* @return array
*/
public function validPowerActionDataProvider(): array
{
return [

View file

@ -90,9 +90,6 @@ class CreateServerScheduleTest extends ClientApiIntegrationTestCase
->assertForbidden();
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_CREATE]]];

View file

@ -78,9 +78,6 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_DELETE]]];

View file

@ -15,7 +15,6 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase
/**
* Test that a schedule can be executed and is updated in the database correctly.
*
* @param array $permissions
* @dataProvider permissionsDataProvider
*/
public function testScheduleIsExecutedRightAway(array $permissions)
@ -85,9 +84,6 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase
$this->actingAs($user)->postJson($this->link($schedule, '/execute'))->assertForbidden();
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];

View file

@ -24,7 +24,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
* Test that schedules for a server are returned.
*
* @param array $permissions
* @param bool $individual
* @param bool $individual
* @dataProvider permissionsDataProvider
*/
public function testServerSchedulesAreReturned($permissions, $individual)
@ -45,7 +45,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
->assertOk();
$prefix = $individual ? '' : 'data.0.';
if (! $individual) {
if (!$individual) {
$response->assertJsonCount(1, 'data');
}
@ -91,9 +91,6 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase
->assertForbidden();
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [

View file

@ -17,8 +17,6 @@ class ScheduleAuthorizationTest extends ClientApiIntegrationTestCase
* The comments within the test code itself are better at explaining exactly what is
* being tested and protected against.
*
* @param string $method
* @param string $endpoint
* @dataProvider methodDataProvider
*/
public function testAccessToAServersSchedulesIsRestrictedProperly(string $method, string $endpoint)

View file

@ -112,9 +112,6 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
$this->assertFalse($schedule->is_processing);
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];

View file

@ -167,9 +167,6 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase
->assertForbidden();
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_UPDATE]]];

View file

@ -110,17 +110,11 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
$this->assertSame(Server::STATUS_INSTALLED, $server->installed);
}
/**
* @return array
*/
public function renamePermissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SETTINGS_RENAME]]];
}
/**
* @return array
*/
public function reinstallPermissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SETTINGS_REINSTALL]]];

View file

@ -49,7 +49,6 @@ class UpdateStartupVariableTest extends ClientApiIntegrationTestCase
* Test that variables that are either not user_viewable, or not user_editable, cannot be
* updated via this endpoint.
*
* @param array $permissions
* @dataProvider permissionsDataProvider
*/
public function testStartupVariableCannotBeUpdatedIfNotUserViewableOrEditable(array $permissions)

View file

@ -156,9 +156,6 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase
$response->assertJsonPath('errors.0.detail', 'A user with that email address is already assigned as a subuser for this server.');
}
/**
* @return array
*/
public function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_USER_CREATE]]];

View file

@ -13,7 +13,6 @@ class SubuserAuthorizationTest extends ClientApiIntegrationTestCase
/**
* Test that mismatched subusers are not accessible to a server.
*
* @param string $method
* @dataProvider methodDataProvider
*/
public function testUserCannotAccessResourceBelongingToOtherServers(string $method)

View file

@ -50,8 +50,8 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
$this->assertStringStartsWith('wss://', $connection, 'Failed asserting that websocket connection address has expected "wss://" prefix.');
$this->assertStringEndsWith("/api/servers/{$server->uuid}/ws", $connection, 'Failed asserting that websocket connection address uses expected Wings endpoint.');
$config = Configuration::forSymmetricSigner(new Sha256, $key = InMemory::plainText($server->node->getDecryptedKey()));
$config->setValidationConstraints(new SignedWith(new Sha256, $key));
$config = Configuration::forSymmetricSigner(new Sha256(), $key = InMemory::plainText($server->node->getDecryptedKey()));
$config->setValidationConstraints(new SignedWith(new Sha256(), $key));
/** @var \Lcobucci\JWT\Token\Plain $token */
$token = $config->parser()->parse($response->json('data.token'));
@ -95,8 +95,8 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
$response->assertOk();
$response->assertJsonStructure(['data' => ['token', 'socket']]);
$config = Configuration::forSymmetricSigner(new Sha256, $key = InMemory::plainText($server->node->getDecryptedKey()));
$config->setValidationConstraints(new SignedWith(new Sha256, $key));
$config = Configuration::forSymmetricSigner(new Sha256(), $key = InMemory::plainText($server->node->getDecryptedKey()));
$config->setValidationConstraints(new SignedWith(new Sha256(), $key));
/** @var \Lcobucci\JWT\Token\Plain $token */
$token = $config->parser()->parse($response->json('data.token'));

View file

@ -111,9 +111,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase
}
}
throw new ExpectationFailedException(
sprintf('Failed asserting that token [%s] exists as a hashed value in recovery_tokens table.', $raw)
);
throw new ExpectationFailedException(sprintf('Failed asserting that token [%s] exists as a hashed value in recovery_tokens table.', $raw));
}
}

View file

@ -36,9 +36,6 @@ abstract class IntegrationTestCase extends TestCase
/**
* Return an ISO-8601 formatted timestamp to use in the API response.
*
* @param string $timestamp
* @return string
*/
protected function formatTimestamp(string $timestamp): string
{

View file

@ -92,7 +92,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
config()->set('pterodactyl.client_features.allocations.range_start', 5000);
config()->set('pterodactyl.client_features.allocations.range_end', 5005);
for ($i = 5000; $i <= 5005; $i++) {
for ($i = 5000; $i <= 5005; ++$i) {
Allocation::factory()->create([
'ip' => $server->allocation->ip,
'port' => $i,

View file

@ -184,9 +184,9 @@ 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);
@ -199,9 +199,6 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$this->assertDatabaseMissing('databases', ['server_id' => $server->id]);
}
/**
* @return array
*/
public function invalidDataDataProvider(): array
{
return [

View file

@ -107,7 +107,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
'database_host_id' => $host->id,
'database' => "s{$server->id}_something",
'remote' => '%',
])->andReturns(new Database);
])->andReturns(new Database());
$response = $this->getService()->handle($server, [
'database' => 'something',
@ -133,7 +133,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
'database_host_id' => $host->id,
'database' => "s{$server->id}_something",
'remote' => '%',
])->andReturns(new Database);
])->andReturns(new Database());
$response = $this->getService()->handle($server, [
'database' => 'something',
@ -143,9 +143,6 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
$this->assertInstanceOf(Database::class, $response);
}
/**
* @return array
*/
public function invalidDataProvider(): array
{
return [

View file

@ -151,9 +151,6 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$this->assertDatabaseHas('tasks', ['id' => $task->id, 'is_queued' => false]);
}
/**
* @return array
*/
public function dispatchNowDataProvider(): array
{
return [[true], [false]];

View file

@ -66,7 +66,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$this->expectException(DaemonConnectionException::class);
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response))
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response()))
);
$this->getService()->handle($server);
@ -124,7 +124,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andReturnUndefined();
$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->getService()->handle($server);
@ -149,7 +149,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andReturnUndefined();
$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

@ -15,6 +15,7 @@ class TestResponse extends IlluminateTestResponse
* look for that status response.
*
* @param int $status
*
* @return \Pterodactyl\Tests\Integration\TestResponse
*/
public function assertStatus($status)
@ -25,7 +26,7 @@ class TestResponse extends IlluminateTestResponse
// to fail so that debugging isn't such a nightmare.
if ($actual !== $status && $status !== 500) {
$this->dump();
if (! is_null($this->exception) && ! $this->exception instanceof DisplayException && ! $this->exception instanceof ValidationException) {
if (!is_null($this->exception) && !$this->exception instanceof DisplayException && !$this->exception instanceof ValidationException) {
dump($this->exception);
}
}