Update to Laravel 5.5 (#814)

This commit is contained in:
Dane Everitt 2017-12-17 13:07:38 -06:00 committed by GitHub
parent f9df463d32
commit b9d67459b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 1021 additions and 818 deletions

View file

@ -1,14 +1,8 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Tests\Unit\Commands\Maintenance;
use SplFileInfo;
use Mockery as m;
use Carbon\Carbon;
use Tests\Unit\Commands\CommandTestCase;
@ -18,11 +12,6 @@ use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
class CleanServiceBackupFilesCommandTest extends CommandTestCase
{
/**
* @var \Carbon\Carbon|\Mockery\Mock
*/
protected $carbon;
/**
* @var \Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand
*/
@ -45,13 +34,10 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase
{
parent::setUp();
$this->carbon = m::mock(Carbon::class);
Carbon::setTestNow();
$this->disk = m::mock(Filesystem::class);
$this->filesystem = m::mock(Factory::class);
$this->filesystem->shouldReceive('disk')->withNoArgs()->once()->andReturn($this->disk);
$this->command = new CleanServiceBackupFilesCommand($this->carbon, $this->filesystem);
$this->command->setLaravel($this->app);
}
/**
@ -59,14 +45,13 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase
*/
public function testCommandCleansFilesMoreThan5MinutesOld()
{
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn(['testfile.txt']);
$this->disk->shouldReceive('lastModified')->with('testfile.txt')->once()->andReturn('disk:last:modified');
$this->carbon->shouldReceive('timestamp')->with('disk:last:modified')->once()->andReturnSelf();
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnNull();
$this->carbon->shouldReceive('diffInMinutes')->with(null)->once()->andReturn(10);
$this->disk->shouldReceive('delete')->with('testfile.txt')->once()->andReturnNull();
$file = new SplFileInfo('testfile.txt');
$display = $this->runCommand($this->command);
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn([$file]);
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now()->subDays(100)->getTimestamp());
$this->disk->shouldReceive('delete')->with($file->getPath())->once()->andReturnNull();
$display = $this->runCommand($this->getCommand());
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.maintenance.deleting_service_backup', ['file' => 'testfile.txt']), $display);
@ -77,14 +62,26 @@ class CleanServiceBackupFilesCommandTest extends CommandTestCase
*/
public function testCommandDoesNotCleanFileLessThan5MinutesOld()
{
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn(['testfile.txt']);
$this->disk->shouldReceive('lastModified')->with('testfile.txt')->once()->andReturn('disk:last:modified');
$this->carbon->shouldReceive('timestamp')->with('disk:last:modified')->once()->andReturnSelf();
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnNull();
$this->carbon->shouldReceive('diffInMinutes')->with(null)->once()->andReturn(2);
$file = new SplFileInfo('testfile.txt');
$display = $this->runCommand($this->command);
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn([$file]);
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now()->getTimestamp());
$display = $this->runCommand($this->getCommand());
$this->assertEmpty($display);
}
/**
* Return an instance of the command for testing.
*
* @return \Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand
*/
private function getCommand(): CleanServiceBackupFilesCommand
{
$command = new CleanServiceBackupFilesCommand($this->filesystem);
$command->setLaravel($this->app);
return $command;
}
}

View file

@ -50,13 +50,13 @@ class AccountControllerTest extends ControllerTestCase
public function testUpdateControllerForPassword()
{
$this->setRequestMockClass(AccountDataFormRequest::class);
$user = $this->setRequestUser();
$user = $this->generateRequestUserModel();
$this->request->shouldReceive('input')->with('do_action')->andReturn('password');
$this->request->shouldReceive('input')->with('new_password')->once()->andReturn('test-password');
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
$this->updateService->shouldReceive('handle')->with($user, ['password' => 'test-password'])->once()->andReturnNull();
$this->updateService->shouldReceive('handle')->with($user, ['password' => 'test-password'])->once()->andReturn(collect());
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
$response = $this->getController()->update($this->request);
@ -70,13 +70,13 @@ class AccountControllerTest extends ControllerTestCase
public function testUpdateControllerForEmail()
{
$this->setRequestMockClass(AccountDataFormRequest::class);
$user = $this->setRequestUser();
$user = $this->generateRequestUserModel();
$this->request->shouldReceive('input')->with('do_action')->andReturn('email');
$this->request->shouldReceive('input')->with('new_email')->once()->andReturn('test@example.com');
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
$this->updateService->shouldReceive('handle')->with($user, ['email' => 'test@example.com'])->once()->andReturnNull();
$this->updateService->shouldReceive('handle')->with($user, ['email' => 'test@example.com'])->once()->andReturn(collect());
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
$response = $this->getController()->update($this->request);
@ -90,7 +90,7 @@ class AccountControllerTest extends ControllerTestCase
public function testUpdateControllerForIdentity()
{
$this->setRequestMockClass(AccountDataFormRequest::class);
$user = $this->setRequestUser();
$user = $this->generateRequestUserModel();
$this->request->shouldReceive('input')->with('do_action')->andReturn('identity');
$this->request->shouldReceive('only')->with(['name_first', 'name_last', 'username'])->once()->andReturn([
@ -98,7 +98,7 @@ class AccountControllerTest extends ControllerTestCase
]);
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
$this->updateService->shouldReceive('handle')->with($user, ['test_data' => 'value'])->once()->andReturnNull();
$this->updateService->shouldReceive('handle')->with($user, ['test_data' => 'value'])->once()->andReturn(collect());
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
$response = $this->getController()->update($this->request);

View file

@ -58,7 +58,7 @@ class SecurityControllerTest extends ControllerTestCase
*/
public function testIndexControllerWithDatabaseDriver()
{
$model = $this->setRequestUser();
$model = $this->generateRequestUserModel();
$this->config->shouldReceive('get')->with('session.driver')->once()->andReturn('database');
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(['sessions']);
@ -89,7 +89,7 @@ class SecurityControllerTest extends ControllerTestCase
*/
public function testGenerateTotpController()
{
$model = $this->setRequestUser();
$model = $this->generateRequestUserModel();
$this->twoFactorSetupService->shouldReceive('handle')->with($model)->once()->andReturn('qrCodeImage');
@ -103,10 +103,10 @@ class SecurityControllerTest extends ControllerTestCase
*/
public function testDisableTotpControllerSuccess()
{
$model = $this->setRequestUser();
$model = $this->generateRequestUserModel();
$this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken');
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken', false)->once()->andReturnNull();
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken', false)->once()->andReturn(true);
$response = $this->getController()->disableTotp($this->request);
$this->assertIsRedirectResponse($response);
@ -118,7 +118,7 @@ class SecurityControllerTest extends ControllerTestCase
*/
public function testDisableTotpControllerWhenExceptionIsThrown()
{
$model = $this->setRequestUser();
$model = $this->generateRequestUserModel();
$this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken');
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken', false)->once()->andThrow(new TwoFactorAuthenticationTokenInvalid);
@ -135,7 +135,7 @@ class SecurityControllerTest extends ControllerTestCase
*/
public function testRevokeController()
{
$model = $this->setRequestUser();
$model = $this->generateRequestUserModel();
$this->repository->shouldReceive('deleteUserSession')->with($model->id, 123)->once()->andReturnNull();

View file

@ -133,7 +133,7 @@ class ServerCreationServiceTest extends TestCase
$this->configurationStructureService->shouldReceive('handle')->with($model)->once()->andReturn(['test' => 'struct']);
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'], ['start_on_completion' => false])->once()->andReturnNull();
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'], ['start_on_completion' => false])->once();
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$response = $this->getService()->create($model->toArray());