Skip to content

Commit c6cece5

Browse files
committed
Fix the surprisingly few broken tests
1 parent 3c48947 commit c6cece5

File tree

8 files changed

+43
-66
lines changed

8 files changed

+43
-66
lines changed

app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Pterodactyl\Console\Commands\Maintenance;
44

5+
use SplFileInfo;
56
use Carbon\Carbon;
67
use Illuminate\Console\Command;
7-
use Symfony\Component\Finder\SplFileInfo;
88
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
99

1010
class CleanServiceBackupFilesCommand extends Command

app/Http/Controllers/Base/SecurityController.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
5-
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com>.
6-
*
7-
* Permission is hereby granted, free of charge, to any person obtaining a copy
8-
* of this software and associated documentation files (the "Software"), to deal
9-
* in the Software without restriction, including without limitation the rights
10-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
* copies of the Software, and to permit persons to whom the Software is
12-
* furnished to do so, subject to the following conditions:
13-
*
14-
* The above copyright notice and this permission notice shall be included in all
15-
* copies or substantial portions of the Software.
16-
*
17-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
* SOFTWARE.
24-
*/
252

263
namespace Pterodactyl\Http\Controllers\Base;
274

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"fzaninotto/faker": "^1.6",
4949
"mockery/mockery": "^1.0",
5050
"php-mock/php-mock-phpunit": "^2.0",
51-
"phpunit/phpunit": "^6.5"
51+
"phpunit/phpunit": "~6.4.0"
5252
},
5353
"autoload": {
5454
"classmap": [

composer.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Unit/Commands/Maintenance/CleanServiceBackupFilesCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testCommandCleansFilesMoreThan5MinutesOld()
4848
$file = new SplFileInfo('testfile.txt');
4949

5050
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn([$file]);
51-
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now()->subDays(100));
51+
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now()->subDays(100)->getTimestamp());
5252
$this->disk->shouldReceive('delete')->with($file->getPath())->once()->andReturnNull();
5353

5454
$display = $this->runCommand($this->getCommand());
@@ -65,7 +65,7 @@ public function testCommandDoesNotCleanFileLessThan5MinutesOld()
6565
$file = new SplFileInfo('testfile.txt');
6666

6767
$this->disk->shouldReceive('files')->with('services/.bak')->once()->andReturn([$file]);
68-
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now());
68+
$this->disk->shouldReceive('lastModified')->with($file->getPath())->once()->andReturn(Carbon::now()->getTimestamp());
6969

7070
$display = $this->runCommand($this->getCommand());
7171

tests/Unit/Http/Controllers/Base/AccountControllerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public function testIndexController()
5050
public function testUpdateControllerForPassword()
5151
{
5252
$this->setRequestMockClass(AccountDataFormRequest::class);
53-
$user = $this->setRequestUser();
53+
$user = $this->generateRequestUserModel();
5454

5555
$this->request->shouldReceive('input')->with('do_action')->andReturn('password');
5656
$this->request->shouldReceive('input')->with('new_password')->once()->andReturn('test-password');
5757

5858
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
59-
$this->updateService->shouldReceive('handle')->with($user, ['password' => 'test-password'])->once()->andReturnNull();
59+
$this->updateService->shouldReceive('handle')->with($user, ['password' => 'test-password'])->once()->andReturn(collect());
6060
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
6161

6262
$response = $this->getController()->update($this->request);
@@ -70,13 +70,13 @@ public function testUpdateControllerForPassword()
7070
public function testUpdateControllerForEmail()
7171
{
7272
$this->setRequestMockClass(AccountDataFormRequest::class);
73-
$user = $this->setRequestUser();
73+
$user = $this->generateRequestUserModel();
7474

7575
$this->request->shouldReceive('input')->with('do_action')->andReturn('email');
7676
$this->request->shouldReceive('input')->with('new_email')->once()->andReturn('test@example.com');
7777

7878
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
79-
$this->updateService->shouldReceive('handle')->with($user, ['email' => 'test@example.com'])->once()->andReturnNull();
79+
$this->updateService->shouldReceive('handle')->with($user, ['email' => 'test@example.com'])->once()->andReturn(collect());
8080
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
8181

8282
$response = $this->getController()->update($this->request);
@@ -90,15 +90,15 @@ public function testUpdateControllerForEmail()
9090
public function testUpdateControllerForIdentity()
9191
{
9292
$this->setRequestMockClass(AccountDataFormRequest::class);
93-
$user = $this->setRequestUser();
93+
$user = $this->generateRequestUserModel();
9494

9595
$this->request->shouldReceive('input')->with('do_action')->andReturn('identity');
9696
$this->request->shouldReceive('only')->with(['name_first', 'name_last', 'username'])->once()->andReturn([
9797
'test_data' => 'value',
9898
]);
9999

100100
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
101-
$this->updateService->shouldReceive('handle')->with($user, ['test_data' => 'value'])->once()->andReturnNull();
101+
$this->updateService->shouldReceive('handle')->with($user, ['test_data' => 'value'])->once()->andReturn(collect());
102102
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
103103

104104
$response = $this->getController()->update($this->request);

tests/Unit/Http/Controllers/Base/SecurityControllerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function setUp()
5858
*/
5959
public function testIndexControllerWithDatabaseDriver()
6060
{
61-
$model = $this->setRequestUser();
61+
$model = $this->generateRequestUserModel();
6262

6363
$this->config->shouldReceive('get')->with('session.driver')->once()->andReturn('database');
6464
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(['sessions']);
@@ -89,7 +89,7 @@ public function testIndexControllerWithoutDatabaseDriver()
8989
*/
9090
public function testGenerateTotpController()
9191
{
92-
$model = $this->setRequestUser();
92+
$model = $this->generateRequestUserModel();
9393

9494
$this->twoFactorSetupService->shouldReceive('handle')->with($model)->once()->andReturn('qrCodeImage');
9595

@@ -103,10 +103,10 @@ public function testGenerateTotpController()
103103
*/
104104
public function testDisableTotpControllerSuccess()
105105
{
106-
$model = $this->setRequestUser();
106+
$model = $this->generateRequestUserModel();
107107

108108
$this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken');
109-
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken', false)->once()->andReturnNull();
109+
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken', false)->once()->andReturn(true);
110110

111111
$response = $this->getController()->disableTotp($this->request);
112112
$this->assertIsRedirectResponse($response);
@@ -118,7 +118,7 @@ public function testDisableTotpControllerSuccess()
118118
*/
119119
public function testDisableTotpControllerWhenExceptionIsThrown()
120120
{
121-
$model = $this->setRequestUser();
121+
$model = $this->generateRequestUserModel();
122122

123123
$this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken');
124124
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken', false)->once()->andThrow(new TwoFactorAuthenticationTokenInvalid);
@@ -135,7 +135,7 @@ public function testDisableTotpControllerWhenExceptionIsThrown()
135135
*/
136136
public function testRevokeController()
137137
{
138-
$model = $this->setRequestUser();
138+
$model = $this->generateRequestUserModel();
139139

140140
$this->repository->shouldReceive('deleteUserSession')->with($model->id, 123)->once()->andReturnNull();
141141

tests/Unit/Services/Servers/ServerCreationServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function testCreateShouldHitAllOfTheNecessaryServicesAndStoreTheServer()
133133
$this->configurationStructureService->shouldReceive('handle')->with($model)->once()->andReturn(['test' => 'struct']);
134134

135135
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
136-
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'], ['start_on_completion' => false])->once()->andReturnNull();
136+
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'], ['start_on_completion' => false])->once();
137137
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
138138

139139
$response = $this->getService()->create($model->toArray());

0 commit comments

Comments
 (0)