Remove unused dependencies and cleanup namespacing

This commit is contained in:
Dane Everitt
2021-01-23 11:22:40 -08:00
parent b3b4b8a527
commit 42ba866b26
46 changed files with 186 additions and 526 deletions

View File

@@ -7,7 +7,7 @@
* https://opensource.org/licenses/MIT
*/
namespace Tests\Assertions;
namespace Pterodactyl\Tests\Assertions;
use PHPUnit\Framework\Assert;

View File

@@ -7,7 +7,7 @@
* https://opensource.org/licenses/MIT
*/
namespace Tests\Assertions;
namespace Pterodactyl\Tests\Assertions;
use Illuminate\View\View;
use Illuminate\Http\Response;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Assertions;
namespace Pterodactyl\Tests\Assertions;
use PHPUnit\Framework\Assert;

View File

@@ -7,7 +7,7 @@
* https://opensource.org/licenses/MIT
*/
namespace Tests\Assertions;
namespace Pterodactyl\Tests\Assertions;
use PHPUnit\Framework\Assert;
use PHPUnit_Util_InvalidArgumentHelper;

View File

@@ -5,7 +5,7 @@ namespace Pterodactyl\Tests\Browser;
use Laravel\Dusk\TestCase;
use BadMethodCallException;
use Pterodactyl\Models\User;
use Tests\CreatesApplication;
use Pterodactyl\Tests\CreatesApplication;
use Pterodactyl\Console\Kernel;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\Model;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests;
namespace Pterodactyl\Tests;
use Illuminate\Contracts\Console\Kernel;

View File

@@ -6,10 +6,10 @@ use Pterodactyl\Models\User;
use PHPUnit\Framework\Assert;
use Pterodactyl\Models\ApiKey;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Tests\Traits\Integration\CreatesTestModels;
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\Traits\Http\IntegrationJsonRequestAssertions;
use Pterodactyl\Tests\Traits\Http\IntegrationJsonRequestAssertions;
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;

View File

@@ -40,17 +40,6 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
parent::tearDown();
}
/**
* Setup tests and ensure all of the times are always the same.
*/
public function setUp(): void
{
parent::setUp();
Carbon::setTestNow(Carbon::now());
CarbonImmutable::setTestNow(Carbon::now());
}
/**
* Override the default createTestResponse from Illuminate so that we can
* just dump 500-level errors to the screen in the tests without having

View File

@@ -2,7 +2,6 @@
namespace Pterodactyl\Tests\Integration\Api\Client\Server;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Http\Response;
use Lcobucci\JWT\Configuration;
@@ -34,8 +33,6 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase
*/
public function testJwtAndWebsocketUrlAreReturnedForServerOwner()
{
CarbonImmutable::setTestNow(Carbon::now());
/** @var \Pterodactyl\Models\User $user */
/** @var \Pterodactyl\Models\Server $server */
[$user, $server] = $this->generateTestAccount();

View File

@@ -2,10 +2,10 @@
namespace Pterodactyl\Tests\Integration;
use Tests\TestCase;
use Cake\Chronos\Chronos;
use Pterodactyl\Tests\TestCase;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Model;
use Tests\Traits\Integration\CreatesTestModels;
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
abstract class IntegrationTestCase extends TestCase
@@ -42,7 +42,7 @@ abstract class IntegrationTestCase extends TestCase
*/
protected function formatTimestamp(string $timestamp): string
{
return Chronos::createFromFormat(Chronos::DEFAULT_TO_STRING_FORMAT, $timestamp)
return CarbonImmutable::createFromFormat(CarbonImmutable::DEFAULT_TO_STRING_FORMAT, $timestamp)
->setTimezone(BaseTransformer::RESPONSE_TIMEZONE)
->toIso8601String();
}

View File

@@ -1,8 +1,9 @@
<?php
namespace Tests;
namespace Pterodactyl\Tests;
use Cake\Chronos\Chronos;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
@@ -16,6 +17,9 @@ abstract class TestCase extends BaseTestCase
{
parent::setUp();
Carbon::setTestNow(Carbon::now());
CarbonImmutable::setTestNow(Carbon::now());
// Why, you ask? If we don't force this to false it is possible for certain exceptions
// to show their error message properly in the integration test output, but not actually
// be setup correctly to display their message in production.
@@ -35,7 +39,8 @@ abstract class TestCase extends BaseTestCase
{
parent::tearDown();
Chronos::setTestNow();
Carbon::setTestNow();
CarbonImmutable::setTestNow();
}
/**

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Traits\Http;
namespace Pterodactyl\Tests\Traits\Http;
use Illuminate\Http\Response;
use Illuminate\Testing\TestResponse;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Traits\Http;
namespace Pterodactyl\Tests\Traits\Http;
use Closure;
use Illuminate\Http\Request;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Traits\Http;
namespace Pterodactyl\Tests\Traits\Http;
use Mockery as m;
use Illuminate\Http\Request;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Traits\Integration;
namespace Pterodactyl\Tests\Traits\Integration;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Traits;
namespace Pterodactyl\Tests\Traits;
use PDO;
use Mockery;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Traits;
namespace Pterodactyl\Tests\Traits;
use Mockery;
use Mockery\MockInterface;

View File

@@ -7,7 +7,7 @@
* https://opensource.org/licenses/MIT
*/
namespace Tests\Traits;
namespace Pterodactyl\Tests\Traits;
use Mockery as m;
use Ramsey\Uuid\Uuid;

View File

@@ -1,15 +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\Helpers;
namespace Pterodactyl\Tests\Unit\Helpers;
use Tests\TestCase;
use Pterodactyl\Tests\TestCase;
class IsDigitTest extends TestCase
{

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Unit\Http\Middleware;
namespace Pterodactyl\Tests\Unit\Http\Middleware;
use Pterodactyl\Models\User;
use Pterodactyl\Http\Middleware\AdminAuthenticate;

View File

@@ -1,8 +1,8 @@
<?php
namespace Tests\Unit\Http\Middleware\Api\Application;
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api\Application;
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;

View File

@@ -1,9 +1,9 @@
<?php
namespace Tests\Unit\Http\Middleware\Api;
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api;
use Pterodactyl\Models\ApiKey;
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Http\Middleware\Api\AuthenticateIPAccess;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

View File

@@ -1,14 +1,14 @@
<?php
namespace Tests\Unit\Http\Middleware\Api;
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api;
use Mockery as m;
use Cake\Chronos\Chronos;
use Carbon\CarbonImmutable;
use Pterodactyl\Models\User;
use Pterodactyl\Models\ApiKey;
use Illuminate\Auth\AuthManager;
use Illuminate\Contracts\Encryption\Encrypter;
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Http\Middleware\Api\AuthenticateKey;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
@@ -38,7 +38,6 @@ class AuthenticateKeyTest extends MiddlewareTestCase
public function setUp(): void
{
parent::setUp();
Chronos::setTestNow(Chronos::now());
$this->auth = m::mock(AuthManager::class);
$this->encrypter = m::mock(Encrypter::class);
@@ -90,7 +89,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase
$this->auth->shouldReceive('guard->loginUsingId')->with($model->user_id)->once()->andReturnNull();
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
'last_used_at' => Chronos::now(),
'last_used_at' => CarbonImmutable::now(),
])->once()->andReturnNull();
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions(), ApiKey::TYPE_APPLICATION);
@@ -113,7 +112,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase
$this->auth->shouldReceive('guard->loginUsingId')->with($model->user_id)->once()->andReturnNull();
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
'last_used_at' => Chronos::now(),
'last_used_at' => CarbonImmutable::now(),
])->once()->andReturnNull();
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions(), ApiKey::TYPE_ACCOUNT);

View File

@@ -1,11 +1,11 @@
<?php
namespace Tests\Unit\Http\Middleware\Api\Daemon;
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api\Daemon;
use Mockery as m;
use Pterodactyl\Models\Node;
use Illuminate\Contracts\Encryption\Encrypter;
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;

View File

@@ -1,10 +1,10 @@
<?php
namespace Tests\Unit\Http\Middleware\Api;
namespace Pterodactyl\Tests\Unit\Http\Middleware\Api;
use Mockery as m;
use Illuminate\Contracts\Config\Repository;
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Http\Middleware\Api\SetSessionDriver;
class SetSessionDriverTest extends MiddlewareTestCase

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Unit\Http\Middleware;
namespace Pterodactyl\Tests\Unit\Http\Middleware;
use Illuminate\Auth\AuthenticationException;
use Pterodactyl\Http\Middleware\Authenticate;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Unit\Http\Middleware;
namespace Pterodactyl\Tests\Unit\Http\Middleware;
use Mockery as m;
use Pterodactyl\Models\User;

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Unit\Http\Middleware;
namespace Pterodactyl\Tests\Unit\Http\Middleware;
use Mockery as m;
use Pterodactyl\Models\Node;

View File

@@ -1,11 +1,11 @@
<?php
namespace Tests\Unit\Http\Middleware;
namespace Pterodactyl\Tests\Unit\Http\Middleware;
use Tests\TestCase;
use Tests\Traits\Http\RequestMockHelpers;
use Tests\Traits\Http\MocksMiddlewareClosure;
use Tests\Assertions\MiddlewareAttributeAssertionsTrait;
use Pterodactyl\Tests\TestCase;
use Pterodactyl\Tests\Traits\Http\RequestMockHelpers;
use Pterodactyl\Tests\Traits\Http\MocksMiddlewareClosure;
use Pterodactyl\Tests\Assertions\MiddlewareAttributeAssertionsTrait;
abstract class MiddlewareTestCase extends TestCase
{

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Unit\Http\Middleware;
namespace Pterodactyl\Tests\Unit\Http\Middleware;
use Mockery as m;
use Illuminate\Auth\AuthManager;

View File

@@ -1,12 +1,12 @@
<?php
namespace Tests\Unit\Http\Middleware\Server;
namespace Pterodactyl\Tests\Unit\Http\Middleware\Server;
use Mockery as m;
use Pterodactyl\Models\Server;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Routing\ResponseFactory;
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Pterodactyl\Http\Middleware\Server\AccessingValidServer;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;

View File

@@ -1,8 +1,8 @@
<?php
namespace Tests\Unit\Rules;
namespace Pterodactyl\Tests\Unit\Rules;
use Tests\TestCase;
use Pterodactyl\Tests\TestCase;
use Pterodactyl\Rules\Username;
class UsernameTest extends TestCase

View File

@@ -1,8 +1,8 @@
<?php
namespace Tests\Unit\Services\Acl\Api;
namespace Pterodactyl\Tests\Unit\Services\Acl\Api;
use Tests\TestCase;
use Pterodactyl\Tests\TestCase;
use Pterodactyl\Models\ApiKey;
use Pterodactyl\Services\Acl\Api\AdminAcl;

View File

@@ -1,9 +1,9 @@
<?php
namespace Tests\Unit\Services\Api;
namespace Pterodactyl\Tests\Unit\Services\Api;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Tests\TestCase;
use phpmock\phpunit\PHPMock;
use Pterodactyl\Models\ApiKey;
use Illuminate\Contracts\Encryption\Encrypter;