Add unit tests for user management commands
This commit is contained in:
parent
22459a877a
commit
12ba96bd42
5 changed files with 300 additions and 41 deletions
41
tests/Assertions/CommandAssertionsTrait.php
Normal file
41
tests/Assertions/CommandAssertionsTrait.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Tests\Assertions;
|
||||
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
trait CommandAssertionsTrait
|
||||
{
|
||||
/**
|
||||
* Assert that an output table contains a value.
|
||||
*
|
||||
* @param mixed $string
|
||||
* @param string $display
|
||||
*/
|
||||
public function assertTableContains($string, $display)
|
||||
{
|
||||
Assert::assertRegExp('/\|(\s+)' . preg_quote($string) . '(\s+)\|/', $display, 'Assert that a response table contains a value.');
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace Tests\Assertions;
|
|||
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\Response;
|
||||
use PHPUnit_Framework_Assert;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
|
@ -39,7 +39,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertIsViewResponse($response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertInstanceOf(View::class, $response);
|
||||
Assert::assertInstanceOf(View::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertIsRedirectResponse($response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertInstanceOf(RedirectResponse::class, $response);
|
||||
Assert::assertInstanceOf(RedirectResponse::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertIsJsonResponse($response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertInstanceOf(JsonResponse::class, $response);
|
||||
Assert::assertInstanceOf(JsonResponse::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertIsResponse($response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertInstanceOf(Response::class, $response);
|
||||
Assert::assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertViewNameEquals($name, $view)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals($name, $view->getName());
|
||||
Assert::assertEquals($name, $view->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +91,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertViewNameNotEquals($name, $view)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertNotEquals($name, $view->getName());
|
||||
Assert::assertNotEquals($name, $view->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,12 +103,12 @@ trait ControllerAssertionsTrait
|
|||
public function assertViewHasKey($attribute, $view)
|
||||
{
|
||||
if (str_contains($attribute, '.')) {
|
||||
PHPUnit_Framework_Assert::assertNotEquals(
|
||||
Assert::assertNotEquals(
|
||||
'__TEST__FAIL',
|
||||
array_get($view->getData(), $attribute, '__TEST__FAIL')
|
||||
);
|
||||
} else {
|
||||
PHPUnit_Framework_Assert::assertArrayHasKey($attribute, $view->getData());
|
||||
Assert::assertArrayHasKey($attribute, $view->getData());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,12 +121,12 @@ trait ControllerAssertionsTrait
|
|||
public function assertViewNotHasKey($attribute, $view)
|
||||
{
|
||||
if (str_contains($attribute, '.')) {
|
||||
PHPUnit_Framework_Assert::assertEquals(
|
||||
Assert::assertEquals(
|
||||
'__TEST__PASS',
|
||||
array_get($view->getData(), $attribute, '__TEST__PASS')
|
||||
);
|
||||
} else {
|
||||
PHPUnit_Framework_Assert::assertArrayNotHasKey($attribute, $view->getData());
|
||||
Assert::assertArrayNotHasKey($attribute, $view->getData());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertViewKeyEquals($attribute, $value, $view)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
|
||||
Assert::assertEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,7 +151,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertViewKeyNotEquals($attribute, $value, $view)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertNotEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
|
||||
Assert::assertNotEquals($value, array_get($view->getData(), $attribute, '__TEST__FAIL'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +163,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertRedirectRouteEquals($route, $response, array $args = [])
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals(route($route, $args), $response->getTargetUrl());
|
||||
Assert::assertEquals(route($route, $args), $response->getTargetUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,7 +174,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertRedirectUrlEquals($url, $response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals($url, $response->getTargetUrl());
|
||||
Assert::assertEquals($url, $response->getTargetUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,7 +185,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertResponseCodeEquals($code, $response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals($code, $response->getStatusCode());
|
||||
Assert::assertEquals($code, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,7 +196,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertResponseCodeNotEquals($code, $response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertNotEquals($code, $response->getStatusCode());
|
||||
Assert::assertNotEquals($code, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,7 +206,7 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertResponseHasJsonHeaders($response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals('application/json', $response->headers->get('content-type'));
|
||||
Assert::assertEquals('application/json', $response->headers->get('content-type'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +217,6 @@ trait ControllerAssertionsTrait
|
|||
*/
|
||||
public function assertResponseJsonEquals($json, $response)
|
||||
{
|
||||
PHPUnit_Framework_Assert::assertEquals(is_array($json) ? json_encode($json) : $json, $response->getContent());
|
||||
Assert::assertEquals(is_array($json) ? json_encode($json) : $json, $response->getContent());
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue