Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
parent
95e15d2c8a
commit
cbcf62086f
573 changed files with 4387 additions and 9411 deletions
|
@ -10,7 +10,7 @@ trait IntegrationJsonRequestAssertions
|
|||
/**
|
||||
* Make assertions about a 404 response on the API.
|
||||
*/
|
||||
public function assertNotFoundJson(TestResponse $response)
|
||||
public function assertNotFoundJson(TestResponse $response): void
|
||||
{
|
||||
$response->assertStatus(Response::HTTP_NOT_FOUND);
|
||||
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
|
||||
|
@ -29,7 +29,7 @@ trait IntegrationJsonRequestAssertions
|
|||
/**
|
||||
* Make assertions about a 403 error returned by the API.
|
||||
*/
|
||||
public function assertAccessDeniedJson(TestResponse $response)
|
||||
public function assertAccessDeniedJson(TestResponse $response): void
|
||||
{
|
||||
$response->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
$response->assertJsonStructure(['errors' => [['code', 'status', 'detail']]]);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Tests\Traits\Http;
|
||||
|
||||
use Mockery as m;
|
||||
use Mockery\Mock;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\User;
|
||||
use InvalidArgumentException;
|
||||
|
@ -10,20 +11,14 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
|||
|
||||
trait RequestMockHelpers
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $requestMockClass = Request::class;
|
||||
private string $requestMockClass = Request::class;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Http\Request|\Mockery\Mock
|
||||
*/
|
||||
protected $request;
|
||||
protected Request|Mock $request;
|
||||
|
||||
/**
|
||||
* Set the class to mock for requests.
|
||||
*/
|
||||
public function setRequestMockClass(string $class)
|
||||
public function setRequestMockClass(string $class): void
|
||||
{
|
||||
$this->requestMockClass = $class;
|
||||
|
||||
|
@ -33,7 +28,7 @@ trait RequestMockHelpers
|
|||
/**
|
||||
* Configure the user model that the request mock should return with.
|
||||
*/
|
||||
public function setRequestUserModel(User $user = null)
|
||||
public function setRequestUserModel(User $user = null): void
|
||||
{
|
||||
$this->request->shouldReceive('user')->andReturn($user);
|
||||
}
|
||||
|
@ -43,6 +38,7 @@ trait RequestMockHelpers
|
|||
*/
|
||||
public function generateRequestUserModel(array $args = []): User
|
||||
{
|
||||
/** @var \Pterodactyl\Models\User $user */
|
||||
$user = User::factory()->make($args);
|
||||
$this->setRequestUserModel($user);
|
||||
|
||||
|
@ -51,10 +47,8 @@ trait RequestMockHelpers
|
|||
|
||||
/**
|
||||
* Set a request attribute on the mock object.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setRequestAttribute(string $attribute, $value)
|
||||
public function setRequestAttribute(string $attribute, mixed $value): void
|
||||
{
|
||||
$this->request->attributes->set($attribute, $value);
|
||||
}
|
||||
|
@ -62,7 +56,7 @@ trait RequestMockHelpers
|
|||
/**
|
||||
* Set the request route name.
|
||||
*/
|
||||
public function setRequestRouteName(string $name)
|
||||
public function setRequestRouteName(string $name): void
|
||||
{
|
||||
$this->request->shouldReceive('route->getName')->andReturn($name);
|
||||
}
|
||||
|
@ -70,7 +64,7 @@ trait RequestMockHelpers
|
|||
/**
|
||||
* Set the active request object to be an instance of a mocked request.
|
||||
*/
|
||||
protected function buildRequestMock()
|
||||
protected function buildRequestMock(): void
|
||||
{
|
||||
$this->request = m::mock($this->requestMockClass);
|
||||
if (!$this->request instanceof Request) {
|
||||
|
|
|
@ -18,11 +18,9 @@ trait CreatesTestModels
|
|||
* is passed in that normally requires this function to create a model no model will be
|
||||
* created and that attribute's value will be used.
|
||||
*
|
||||
* The returned server model will have all of the relationships loaded onto it.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Server
|
||||
* The returned server model will have all the relationships loaded onto it.
|
||||
*/
|
||||
public function createServerModel(array $attributes = [])
|
||||
public function createServerModel(array $attributes = []): Server
|
||||
{
|
||||
if (isset($attributes['user_id'])) {
|
||||
$attributes['owner_id'] = $attributes['user_id'];
|
||||
|
@ -126,11 +124,14 @@ trait CreatesTestModels
|
|||
}
|
||||
|
||||
/**
|
||||
* Most every test just assumes it is using Bungeecord — this is the critical
|
||||
* Almost every test just assumes it is using BungeeCord — this is the critical
|
||||
* egg model for all tests unless specified otherwise.
|
||||
*/
|
||||
private function getBungeecordEgg()
|
||||
private function getBungeecordEgg(): Egg
|
||||
{
|
||||
return Egg::query()->where('author', 'support@pterodactyl.io')->where('name', 'Bungeecord')->firstOrFail();
|
||||
/** @var \Pterodactyl\Models\Egg $egg */
|
||||
$egg = Egg::query()->where('author', 'support@pterodactyl.io')->where('name', 'Bungeecord')->firstOrFail();
|
||||
|
||||
return $egg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,21 +7,17 @@ use Mockery;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\MySqlConnection;
|
||||
use Illuminate\Database\ConnectionResolver;
|
||||
use Illuminate\Database\ConnectionResolverInterface;
|
||||
|
||||
trait MocksPdoConnection
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionResolverInterface|null
|
||||
*/
|
||||
private static $initialResolver;
|
||||
private static ?ConnectionResolverInterface $initialResolver;
|
||||
|
||||
/**
|
||||
* Generates a mock PDO connection and injects it into the models so that any actual
|
||||
* DB call can be properly intercepted.
|
||||
*
|
||||
* @return \Mockery\MockInterface
|
||||
*/
|
||||
protected function mockPdoConnection()
|
||||
protected function mockPdoConnection(): Mockery\MockInterface
|
||||
{
|
||||
self::$initialResolver = Model::getConnectionResolver();
|
||||
|
||||
|
@ -39,7 +35,7 @@ trait MocksPdoConnection
|
|||
/**
|
||||
* Resets the mock state.
|
||||
*/
|
||||
protected function tearDownPdoMock()
|
||||
protected function tearDownPdoMock(): void
|
||||
{
|
||||
if (!self::$initialResolver) {
|
||||
return;
|
||||
|
|
|
@ -3,28 +3,21 @@
|
|||
namespace Pterodactyl\Tests\Traits;
|
||||
|
||||
use Mockery;
|
||||
use Mockery\Mock;
|
||||
use Mockery\MockInterface;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
trait MocksRequestException
|
||||
{
|
||||
/**
|
||||
* @var \GuzzleHttp\Exception\RequestException|\Mockery\Mock
|
||||
*/
|
||||
private $exception;
|
||||
private RequestException|Mock $exception;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $exceptionResponse;
|
||||
private mixed $exceptionResponse;
|
||||
|
||||
/**
|
||||
* Configure the exception mock to work with the Panel's default exception
|
||||
* handler actions.
|
||||
*
|
||||
* @param null $response
|
||||
*/
|
||||
protected function configureExceptionMock(string $abstract = RequestException::class, $response = null)
|
||||
protected function configureExceptionMock(string $abstract = RequestException::class, $response = null): void
|
||||
{
|
||||
$this->getExceptionMock($abstract)->shouldReceive('getResponse')->andReturn(value($response));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?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 Pterodactyl\Tests\Traits;
|
||||
|
||||
|
@ -17,15 +10,13 @@ trait MocksUuids
|
|||
{
|
||||
/**
|
||||
* The known UUID string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $knownUuid = 'ffb5c3a6-ab17-43ab-97f0-8ff37ccd7f5f';
|
||||
protected string $knownUuid = 'ffb5c3a6-ab17-43ab-97f0-8ff37ccd7f5f';
|
||||
|
||||
/**
|
||||
* Setup a factory mock to produce the same UUID whenever called.
|
||||
*/
|
||||
public function setKnownUuidFactory()
|
||||
public function setKnownUuidFactory(): void
|
||||
{
|
||||
$uuid = Uuid::fromString($this->getKnownUuid());
|
||||
$factoryMock = m::mock(UuidFactory::class . '[uuid4]', [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue