From eaae74fe33269e19e3f1c10a56220fdfeeeffb78 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 23 Jun 2020 21:33:56 -0700 Subject: [PATCH] Fix immediately obvious deprecation notices while running command tests --- .../Environment/EmailSettingsCommandTest.php | 25 ++++------ .../Location/DeleteLocationCommandTest.php | 10 ++-- .../Location/MakeLocationCommandTest.php | 4 +- .../CleanServiceBackupFilesCommandTest.php | 2 +- .../Schedule/ProcessRunnableCommandTest.php | 13 ++---- .../Server/BulkPowerActionCommandTest.php | 46 ++++++++----------- .../Commands/User/DeleteUserCommandTest.php | 18 ++++---- .../User/DisableTwoFactorCommandTest.php | 4 +- .../Commands/User/MakeUserCommandTest.php | 26 +++++------ 9 files changed, 63 insertions(+), 85 deletions(-) diff --git a/tests/Unit/Commands/Environment/EmailSettingsCommandTest.php b/tests/Unit/Commands/Environment/EmailSettingsCommandTest.php index 63489c157..d52b7b3fd 100644 --- a/tests/Unit/Commands/Environment/EmailSettingsCommandTest.php +++ b/tests/Unit/Commands/Environment/EmailSettingsCommandTest.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Tests\Unit\Commands\Environment; @@ -58,7 +51,7 @@ class EmailSettingsCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], array_values($data)); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -90,7 +83,7 @@ class EmailSettingsCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -115,7 +108,7 @@ class EmailSettingsCommandTest extends CommandTestCase $display = $this->runCommand($this->command, ['--driver' => 'mail'], array_values($data)); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -136,7 +129,7 @@ class EmailSettingsCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], array_values($data)); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -164,7 +157,7 @@ class EmailSettingsCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -184,7 +177,7 @@ class EmailSettingsCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], array_values($data)); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -210,7 +203,7 @@ class EmailSettingsCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -235,7 +228,7 @@ class EmailSettingsCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** @@ -264,7 +257,7 @@ class EmailSettingsCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains('Updating stored environment configuration file.', $display); + $this->assertStringContainsString('Updating stored environment configuration file.', $display); } /** diff --git a/tests/Unit/Commands/Location/DeleteLocationCommandTest.php b/tests/Unit/Commands/Location/DeleteLocationCommandTest.php index 8b292c3f6..26bd73319 100644 --- a/tests/Unit/Commands/Location/DeleteLocationCommandTest.php +++ b/tests/Unit/Commands/Location/DeleteLocationCommandTest.php @@ -63,7 +63,7 @@ class DeleteLocationCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], [$location2->short]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.location.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.location.deleted'), $display); } /** @@ -84,7 +84,7 @@ class DeleteLocationCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.location.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.location.deleted'), $display); } /** @@ -103,8 +103,8 @@ class DeleteLocationCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], ['123_not_exist', 'another_not_exist', $location2->short]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.location.no_location_found'), $display); - $this->assertContains(trans('command/messages.location.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.location.no_location_found'), $display); + $this->assertStringContainsString(trans('command/messages.location.deleted'), $display); } /** @@ -123,6 +123,6 @@ class DeleteLocationCommandTest extends CommandTestCase $display = $this->withoutInteraction()->runCommand($this->command, ['--short' => 'randomTestString']); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.location.no_location_found'), $display); + $this->assertStringContainsString(trans('command/messages.location.no_location_found'), $display); } } diff --git a/tests/Unit/Commands/Location/MakeLocationCommandTest.php b/tests/Unit/Commands/Location/MakeLocationCommandTest.php index 48823acfa..6b628a6f0 100644 --- a/tests/Unit/Commands/Location/MakeLocationCommandTest.php +++ b/tests/Unit/Commands/Location/MakeLocationCommandTest.php @@ -55,7 +55,7 @@ class MakeLocationCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], [$location->short, $location->long]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.location.created', [ + $this->assertStringContainsString(trans('command/messages.location.created', [ 'name' => $location->short, 'id' => $location->id, ]), $display); @@ -79,7 +79,7 @@ class MakeLocationCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.location.created', [ + $this->assertStringContainsString(trans('command/messages.location.created', [ 'name' => $location->short, 'id' => $location->id, ]), $display); diff --git a/tests/Unit/Commands/Maintenance/CleanServiceBackupFilesCommandTest.php b/tests/Unit/Commands/Maintenance/CleanServiceBackupFilesCommandTest.php index ca3e5b74f..ecb412e52 100644 --- a/tests/Unit/Commands/Maintenance/CleanServiceBackupFilesCommandTest.php +++ b/tests/Unit/Commands/Maintenance/CleanServiceBackupFilesCommandTest.php @@ -54,7 +54,7 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase $display = $this->runCommand($this->getCommand()); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.maintenance.deleting_service_backup', ['file' => 'testfile.txt']), $display); + $this->assertStringContainsString(trans('command/messages.maintenance.deleting_service_backup', ['file' => 'testfile.txt']), $display); } /** diff --git a/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php b/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php index d483ede05..5efbef6c4 100644 --- a/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php +++ b/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Tests\Unit\Commands\Schedule; @@ -64,7 +57,7 @@ class ProcessRunnableCommandTest extends CommandTestCase $display = $this->runCommand($this->command); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.schedule.output_line', [ + $this->assertStringContainsString(trans('command/messages.schedule.output_line', [ 'schedule' => $schedule->name, 'hash' => $schedule->hashid, ]), $display); @@ -83,7 +76,7 @@ class ProcessRunnableCommandTest extends CommandTestCase $display = $this->runCommand($this->command); $this->assertNotEmpty($display); - $this->assertNotContains(trans('command/messages.schedule.output_line', [ + $this->assertStringNotContainsString(trans('command/messages.schedule.output_line', [ 'schedule' => $schedule->name, 'hash' => $schedule->hashid, ]), $display); @@ -101,7 +94,7 @@ class ProcessRunnableCommandTest extends CommandTestCase $display = $this->runCommand($this->command); $this->assertNotEmpty($display); - $this->assertNotContains(trans('command/messages.schedule.output_line', [ + $this->assertStringNotContainsString(trans('command/messages.schedule.output_line', [ 'schedule' => $schedule->name, 'hash' => $schedule->hashid, ]), $display); diff --git a/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php b/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php index 3c760fcb7..d1ba90cf4 100644 --- a/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php +++ b/tests/Unit/Commands/Server/BulkPowerActionCommandTest.php @@ -6,8 +6,10 @@ use Mockery as m; use Pterodactyl\Models\Node; use GuzzleHttp\Psr7\Response; use Pterodactyl\Models\Server; +use Illuminate\Support\Collection; use Illuminate\Validation\Factory; use Tests\Unit\Commands\CommandTestCase; +use Illuminate\Validation\ValidationException; use Pterodactyl\Repositories\Wings\DaemonPowerRepository; use Pterodactyl\Console\Commands\Server\BulkPowerActionCommand; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; @@ -47,25 +49,18 @@ class BulkPowerActionCommandTest extends CommandTestCase $server->setRelation('node', factory(Node::class)->make()); } - $this->repository->expects('getServersForPowerActionCount')->with([], [])->andReturns(2); - - $this->repository->shouldReceive('getServersForPowerAction') - ->once() - ->with([], []) - ->andReturn($servers); + $this->repository->expects('getServersForPowerActionCount')->with([], [])->andReturn(2); + $this->repository->expects('getServersForPowerAction')->with([], [])->andReturn($servers); for ($i = 0; $i < count($servers); $i++) { - $this->powerRepository->shouldReceive('setNode->setServer->sendSignal') - ->once() - ->with('kill') - ->andReturnNull(); + $this->powerRepository->expects('setNode->setServer->send')->with('kill')->andReturnNull(); } $display = $this->runCommand($this->getCommand(), ['action' => 'kill'], ['yes']); $this->assertNotEmpty($display); - $this->assertContains('2/2', $display); - $this->assertContains(trans('command/messages.server.power.confirm', ['action' => 'kill', 'count' => 2]), $display); + $this->assertStringContainsString('2/2', $display); + $this->assertStringContainsString(trans('command/messages.server.power.confirm', ['action' => 'kill', 'count' => 2]), $display); } /** @@ -76,19 +71,17 @@ class BulkPowerActionCommandTest extends CommandTestCase $server = factory(Server::class)->make(); $server->setRelation('node', $node = factory(Node::class)->make()); - $this->repository->shouldReceive('getServersForPowerActionCount') - ->once() + $this->repository->expects('getServersForPowerActionCount') ->with([1, 2], [3, 4]) ->andReturn(1); - $this->repository->shouldReceive('getServersForPowerAction') - ->once() + $this->repository->expects('getServersForPowerAction') ->with([1, 2], [3, 4]) - ->andReturn([$server]); + ->andReturn(Collection::make([$server])); $this->powerRepository->expects('setNode')->with($node)->andReturnSelf(); $this->powerRepository->expects('setServer')->with($server)->andReturnSelf(); - $this->powerRepository->expects('sendSignal')->with('kill')->andReturn(new Response); + $this->powerRepository->expects('send')->with('kill')->andReturn(new Response); $display = $this->runCommand($this->getCommand(), [ 'action' => 'kill', @@ -97,8 +90,8 @@ class BulkPowerActionCommandTest extends CommandTestCase ], ['yes']); $this->assertNotEmpty($display); - $this->assertContains('1/1', $display); - $this->assertContains(trans('command/messages.server.power.confirm', ['action' => 'kill', 'count' => 1]), $display); + $this->assertStringContainsString('1/1', $display); + $this->assertStringContainsString(trans('command/messages.server.power.confirm', ['action' => 'kill', 'count' => 1]), $display); } /** @@ -109,13 +102,12 @@ class BulkPowerActionCommandTest extends CommandTestCase $server = factory(Server::class)->make(); $server->setRelation('node', factory(Node::class)->make()); - $this->repository->shouldReceive('getServersForPowerActionCount') - ->once() + $this->repository->expects('getServersForPowerActionCount') ->with([], []) ->andReturn(1); - $this->repository->shouldReceive('getServersForPowerAction')->once()->with([], [])->andReturn([$server]); - $this->powerRepository->shouldReceive('setNode->setServer->sendSignal')->once()->with('kill')->andReturnNull(); + $this->repository->expects('getServersForPowerAction')->with([], [])->andReturn(Collection::make([$server])); + $this->powerRepository->expects('setNode->setServer->send')->with('kill')->andReturnNull(); $display = $this->runCommand($this->getCommand(), [ 'action' => 'kill', @@ -124,8 +116,8 @@ class BulkPowerActionCommandTest extends CommandTestCase ], ['yes']); $this->assertNotEmpty($display); - $this->assertContains('1/1', $display); - $this->assertContains(trans('command/messages.server.power.confirm', ['action' => 'kill', 'count' => 1]), $display); + $this->assertStringContainsString('1/1', $display); + $this->assertStringContainsString(trans('command/messages.server.power.confirm', ['action' => 'kill', 'count' => 1]), $display); } /** @@ -134,10 +126,10 @@ class BulkPowerActionCommandTest extends CommandTestCase * @param array $data * * @dataProvider validationFailureDataProvider - * @expectedException \Illuminate\Validation\ValidationException */ public function testValidationErrors(array $data) { + $this->expectException(ValidationException::class); $this->runCommand($this->getCommand(), $data); } diff --git a/tests/Unit/Commands/User/DeleteUserCommandTest.php b/tests/Unit/Commands/User/DeleteUserCommandTest.php index 77516bbf7..8263c2241 100644 --- a/tests/Unit/Commands/User/DeleteUserCommandTest.php +++ b/tests/Unit/Commands/User/DeleteUserCommandTest.php @@ -63,7 +63,7 @@ class DeleteUserCommandTest extends CommandTestCase $this->assertTableContains($user1->id, $display); $this->assertTableContains($user1->email, $display); $this->assertTableContains($user1->name, $display); - $this->assertContains(trans('command/messages.user.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.user.deleted'), $display); } /** @@ -84,11 +84,11 @@ class DeleteUserCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], ['noResults', $user1->username, $user1->id, 'yes']); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.no_users_found'), $display); + $this->assertStringContainsString(trans('command/messages.user.no_users_found'), $display); $this->assertTableContains($user1->id, $display); $this->assertTableContains($user1->email, $display); $this->assertTableContains($user1->name, $display); - $this->assertContains(trans('command/messages.user.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.user.deleted'), $display); } /** @@ -107,11 +107,11 @@ class DeleteUserCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], [$user1->username, 0, $user1->username, $user1->id, 'yes']); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.select_search_user'), $display); + $this->assertStringContainsString(trans('command/messages.user.select_search_user'), $display); $this->assertTableContains($user1->id, $display); $this->assertTableContains($user1->email, $display); $this->assertTableContains($user1->name, $display); - $this->assertContains(trans('command/messages.user.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.user.deleted'), $display); } /** @@ -130,7 +130,7 @@ class DeleteUserCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], [$user1->username, $user1->id, 'no']); $this->assertNotEmpty($display); - $this->assertNotContains(trans('command/messages.user.deleted'), $display); + $this->assertStringNotContainsString(trans('command/messages.user.deleted'), $display); } /** @@ -149,7 +149,7 @@ class DeleteUserCommandTest extends CommandTestCase $display = $this->withoutInteraction()->runCommand($this->command, ['--user' => $user1->username]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.deleted'), $display); + $this->assertStringContainsString(trans('command/messages.user.deleted'), $display); } /** @@ -169,7 +169,7 @@ class DeleteUserCommandTest extends CommandTestCase $display = $this->withoutInteraction()->runCommand($this->command, ['--user' => $user1->username]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.multiple_found'), $display); + $this->assertStringContainsString(trans('command/messages.user.multiple_found'), $display); } /** @@ -183,6 +183,6 @@ class DeleteUserCommandTest extends CommandTestCase $display = $this->withoutInteraction()->runCommand($this->command, ['--user' => 123456]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.no_users_found'), $display); + $this->assertStringContainsString(trans('command/messages.user.no_users_found'), $display); } } diff --git a/tests/Unit/Commands/User/DisableTwoFactorCommandTest.php b/tests/Unit/Commands/User/DisableTwoFactorCommandTest.php index 28c9377ff..f2868883d 100644 --- a/tests/Unit/Commands/User/DisableTwoFactorCommandTest.php +++ b/tests/Unit/Commands/User/DisableTwoFactorCommandTest.php @@ -58,7 +58,7 @@ class DisableTwoFactorCommandTest extends CommandTestCase $display = $this->runCommand($this->command, [], [$user->email]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display); + $this->assertStringContainsString(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display); } /** @@ -78,6 +78,6 @@ class DisableTwoFactorCommandTest extends CommandTestCase $display = $this->withoutInteraction()->runCommand($this->command, ['--email' => $user->email]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display); + $this->assertStringContainsString(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display); } } diff --git a/tests/Unit/Commands/User/MakeUserCommandTest.php b/tests/Unit/Commands/User/MakeUserCommandTest.php index d67e90ab5..89baa3323 100644 --- a/tests/Unit/Commands/User/MakeUserCommandTest.php +++ b/tests/Unit/Commands/User/MakeUserCommandTest.php @@ -61,12 +61,12 @@ class MakeUserCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertContains(trans('command/messages.user.ask_password_help'), $display); - $this->assertContains($user->uuid, $display); - $this->assertContains($user->email, $display); - $this->assertContains($user->username, $display); - $this->assertContains($user->name, $display); - $this->assertContains('Yes', $display); + $this->assertStringContainsString(trans('command/messages.user.ask_password_help'), $display); + $this->assertStringContainsString($user->uuid, $display); + $this->assertStringContainsString($user->email, $display); + $this->assertStringContainsString($user->username, $display); + $this->assertStringContainsString($user->name, $display); + $this->assertStringContainsString('Yes', $display); } /** @@ -90,7 +90,7 @@ class MakeUserCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertNotContains(trans('command/messages.user.ask_password_help'), $display); + $this->assertStringNotContainsString(trans('command/messages.user.ask_password_help'), $display); } /** @@ -119,11 +119,11 @@ class MakeUserCommandTest extends CommandTestCase ]); $this->assertNotEmpty($display); - $this->assertNotContains(trans('command/messages.user.ask_password_help'), $display); - $this->assertContains($user->uuid, $display); - $this->assertContains($user->email, $display); - $this->assertContains($user->username, $display); - $this->assertContains($user->name, $display); - $this->assertContains('No', $display); + $this->assertStringNotContainsString(trans('command/messages.user.ask_password_help'), $display); + $this->assertStringContainsString($user->uuid, $display); + $this->assertStringContainsString($user->email, $display); + $this->assertStringContainsString($user->username, $display); + $this->assertStringContainsString($user->name, $display); + $this->assertStringContainsString('No', $display); } }