Skip to content

Commit 12ba96b

Browse files
committed
Add unit tests for user management commands
1 parent 22459a8 commit 12ba96b

File tree

5 files changed

+300
-41
lines changed

5 files changed

+300
-41
lines changed

app/Console/Commands/User/DeleteUserCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public function handle()
7979
$results = $this->repository->search($search)->all();
8080
if (count($results) < 1) {
8181
$this->error(trans('command/messages.user.no_users_found'));
82-
if (! $this->option('no-interaction')) {
82+
if ($this->input->isInteractive()) {
8383
return $this->handle();
8484
}
8585

8686
return false;
8787
}
8888

89-
if (! $this->option('no-interaction')) {
89+
if ($this->input->isInteractive()) {
9090
$tableValues = [];
9191
foreach ($results as $user) {
9292
$tableValues[] = [$user->id, $user->email, $user->name];
@@ -106,7 +106,7 @@ public function handle()
106106
$deleteUser = $results->first();
107107
}
108108

109-
if ($this->confirm(trans('command/messages.user.confirm_delete')) || $this->option('no-interaction')) {
109+
if ($this->confirm(trans('command/messages.user.confirm_delete')) || ! $this->input->isInteractive()) {
110110
$this->deletionService->handle($deleteUser);
111111
$this->info(trans('command/messages.user.deleted'));
112112
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Tests\Assertions;
26+
27+
use PHPUnit\Framework\Assert;
28+
29+
trait CommandAssertionsTrait
30+
{
31+
/**
32+
* Assert that an output table contains a value.
33+
*
34+
* @param mixed $string
35+
* @param string $display
36+
*/
37+
public function assertTableContains($string, $display)
38+
{
39+
Assert::assertRegExp('/\|(\s+)' . preg_quote($string) . '(\s+)\|/', $display, 'Assert that a response table contains a value.');
40+
}
41+
}

tests/Assertions/ControllerAssertionsTrait.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
use Illuminate\View\View;
2828
use Illuminate\Http\Response;
29-
use PHPUnit_Framework_Assert;
29+
use PHPUnit\Framework\Assert;
3030
use Illuminate\Http\JsonResponse;
3131
use Illuminate\Http\RedirectResponse;
3232

@@ -39,7 +39,7 @@ trait ControllerAssertionsTrait
3939
*/
4040
public function assertIsViewResponse($response)
4141
{
42-
PHPUnit_Framework_Assert::assertInstanceOf(View::class, $response);
42+
Assert::assertInstanceOf(View::class, $response);
4343
}
4444

4545
/**
@@ -49,7 +49,7 @@ public function assertIsViewResponse($response)
4949
*/
5050
public function assertIsRedirectResponse($response)
5151
{
52-
PHPUnit_Framework_Assert::assertInstanceOf(RedirectResponse::class, $response);
52+
Assert::assertInstanceOf(RedirectResponse::class, $response);
5353
}
5454

5555
/**
@@ -59,7 +59,7 @@ public function assertIsRedirectResponse($response)
5959
*/
6060
public function assertIsJsonResponse($response)
6161
{
62-
PHPUnit_Framework_Assert::assertInstanceOf(JsonResponse::class, $response);
62+
Assert::assertInstanceOf(JsonResponse::class, $response);
6363
}
6464

6565
/**
@@ -69,7 +69,7 @@ public function assertIsJsonResponse($response)
6969
*/
7070
public function assertIsResponse($response)
7171
{
72-
PHPUnit_Framework_Assert::assertInstanceOf(Response::class, $response);
72+
Assert::assertInstanceOf(Response::class, $response);
7373
}
7474

7575
/**
@@ -80,7 +80,7 @@ public function assertIsResponse($response)
8080
*/
8181
public function assertViewNameEquals($name, $view)
8282
{
83-
PHPUnit_Framework_Assert::assertEquals($name, $view->getName());
83+
Assert::assertEquals($name, $view->getName());
8484
}
8585

8686
/**
@@ -91,7 +91,7 @@ public function assertViewNameEquals($name, $view)
9191
*/
9292
public function assertViewNameNotEquals($name, $view)
9393
{
94-
PHPUnit_Framework_Assert::assertNotEquals($name, $view->getName());
94+
Assert::assertNotEquals($name, $view->getName());
9595
}
9696

9797
/**
@@ -103,12 +103,12 @@ public function assertViewNameNotEquals($name, $view)
103103
public function assertViewHasKey($attribute, $view)
104104
{
105105
if (str_contains($attribute, '.')) {
106-
PHPUnit_Framework_Assert::assertNotEquals(
106+
Assert::assertNotEquals(
107107
'__TEST__FAIL',
108108
array_get($view->getData(), $attribute, '__TEST__FAIL')
109109
);
110110
} else {
111-
PHPUnit_Framework_Assert::assertArrayHasKey($attribute, $view->getData());
111+
Assert::assertArrayHasKey($attribute, $view->getData());
112112
}
113113
}
114114

@@ -121,12 +121,12 @@ public function assertViewHasKey($attribute, $view)
121121
public function assertViewNotHasKey($attribute, $view)
122122
{
123123
if (str_contains($attribute, '.')) {
124-
PHPUnit_Framework_Assert::assertEquals(
124+
Assert::assertEquals(
125125
'__TEST__PASS',
126126
array_get($view->getData(), $attribute, '__TEST__PASS')
127127
);
128128
} else {
129-
PHPUnit_Framework_Assert::assertArrayNotHasKey($attribute, $view->getData());
129+
Assert::assertArrayNotHasKey($attribute, $view->getData());
130130
}
131131
}
132132

@@ -139,7 +139,7 @@ public function assertViewNotHasKey($attribute, $view)
139139
*/
140140
public function assertViewKeyEquals($attribute, $value, $view)
141141
{
142-
PHPUnit_Framework_Assert::assertEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
142+
Assert::assertEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
143143
}
144144

145145
/**
@@ -151,7 +151,7 @@ public function assertViewKeyEquals($attribute, $value, $view)
151151
*/
152152
public function assertViewKeyNotEquals($attribute, $value, $view)
153153
{
154-
PHPUnit_Framework_Assert::assertNotEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
154+
Assert::assertNotEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
155155
}
156156

157157
/**
@@ -163,7 +163,7 @@ public function assertViewKeyNotEquals($attribute, $value, $view)
163163
*/
164164
public function assertRedirectRouteEquals($route, $response, array $args = [])
165165
{
166-
PHPUnit_Framework_Assert::assertEquals(route($route, $args), $response->getTargetUrl());
166+
Assert::assertEquals(route($route, $args), $response->getTargetUrl());
167167
}
168168

169169
/**
@@ -174,7 +174,7 @@ public function assertRedirectRouteEquals($route, $response, array $args = [])
174174
*/
175175
public function assertRedirectUrlEquals($url, $response)
176176
{
177-
PHPUnit_Framework_Assert::assertEquals($url, $response->getTargetUrl());
177+
Assert::assertEquals($url, $response->getTargetUrl());
178178
}
179179

180180
/**
@@ -185,7 +185,7 @@ public function assertRedirectUrlEquals($url, $response)
185185
*/
186186
public function assertResponseCodeEquals($code, $response)
187187
{
188-
PHPUnit_Framework_Assert::assertEquals($code, $response->getStatusCode());
188+
Assert::assertEquals($code, $response->getStatusCode());
189189
}
190190

191191
/**
@@ -196,7 +196,7 @@ public function assertResponseCodeEquals($code, $response)
196196
*/
197197
public function assertResponseCodeNotEquals($code, $response)
198198
{
199-
PHPUnit_Framework_Assert::assertNotEquals($code, $response->getStatusCode());
199+
Assert::assertNotEquals($code, $response->getStatusCode());
200200
}
201201

202202
/**
@@ -206,7 +206,7 @@ public function assertResponseCodeNotEquals($code, $response)
206206
*/
207207
public function assertResponseHasJsonHeaders($response)
208208
{
209-
PHPUnit_Framework_Assert::assertEquals('application/json', $response->headers->get('content-type'));
209+
Assert::assertEquals('application/json', $response->headers->get('content-type'));
210210
}
211211

212212
/**
@@ -217,6 +217,6 @@ public function assertResponseHasJsonHeaders($response)
217217
*/
218218
public function assertResponseJsonEquals($json, $response)
219219
{
220-
PHPUnit_Framework_Assert::assertEquals(is_array($json) ? json_encode($json) : $json, $response->getContent());
220+
Assert::assertEquals(is_array($json) ? json_encode($json) : $json, $response->getContent());
221221
}
222222
}

0 commit comments

Comments
 (0)