Nuke useless tests
This commit is contained in:
parent
9a57011071
commit
f300577963
37 changed files with 0 additions and 4447 deletions
|
@ -1,143 +0,0 @@
|
|||
<?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\Http\Controllers\Admin;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
use Pterodactyl\Http\Controllers\Admin\DatabaseController;
|
||||
use Pterodactyl\Services\Databases\Hosts\HostUpdateService;
|
||||
use Pterodactyl\Services\Databases\Hosts\HostCreationService;
|
||||
use Pterodactyl\Services\Databases\Hosts\HostDeletionService;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
||||
|
||||
class DatabaseControllerTest extends TestCase
|
||||
{
|
||||
use ControllerAssertionsTrait;
|
||||
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag|\Mockery\Mock
|
||||
*/
|
||||
private $alert;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Databases\Hosts\HostCreationService|\Mockery\Mock
|
||||
*/
|
||||
private $creationService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
private $databaseRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService|\Mockery\Mock
|
||||
*/
|
||||
private $deletionService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
private $locationRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Databases\Hosts\HostUpdateService|\Mockery\Mock
|
||||
*/
|
||||
private $updateService;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->alert = m::mock(AlertsMessageBag::class);
|
||||
$this->creationService = m::mock(HostCreationService::class);
|
||||
$this->databaseRepository = m::mock(DatabaseRepositoryInterface::class);
|
||||
$this->deletionService = m::mock(HostDeletionService::class);
|
||||
$this->locationRepository = m::mock(LocationRepositoryInterface::class);
|
||||
$this->repository = m::mock(DatabaseHostRepositoryInterface::class);
|
||||
$this->updateService = m::mock(HostUpdateService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the index controller.
|
||||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn(collect(['getAllWithNodes']));
|
||||
$this->repository->shouldReceive('getWithViewDetails')->withNoArgs()->once()->andReturn(collect(['getWithViewDetails']));
|
||||
|
||||
$response = $this->getController()->index();
|
||||
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('admin.databases.index', $response);
|
||||
$this->assertViewHasKey('locations', $response);
|
||||
$this->assertViewHasKey('hosts', $response);
|
||||
$this->assertViewKeyEquals('locations', collect(['getAllWithNodes']), $response);
|
||||
$this->assertViewKeyEquals('hosts', collect(['getWithViewDetails']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the view controller for displaying a specific database host.
|
||||
*/
|
||||
public function testViewController()
|
||||
{
|
||||
$model = factory(DatabaseHost::class)->make();
|
||||
$paginator = new LengthAwarePaginator([], 1, 1);
|
||||
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn(collect(['getAllWithNodes']));
|
||||
$this->repository->shouldReceive('find')->with(1)->once()->andReturn($model);
|
||||
$this->databaseRepository->shouldReceive('getDatabasesForHost')
|
||||
->once()
|
||||
->with(1)
|
||||
->andReturn($paginator);
|
||||
|
||||
$response = $this->getController()->view(1);
|
||||
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('admin.databases.view', $response);
|
||||
$this->assertViewHasKey('locations', $response);
|
||||
$this->assertViewHasKey('host', $response);
|
||||
$this->assertViewHasKey('databases', $response);
|
||||
$this->assertViewKeyEquals('locations', collect(['getAllWithNodes']), $response);
|
||||
$this->assertViewKeyEquals('host', $model, $response);
|
||||
$this->assertViewKeyEquals('databases', $paginator, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the DatabaseController with mock dependencies.
|
||||
*
|
||||
* @return \Pterodactyl\Http\Controllers\Admin\DatabaseController
|
||||
*/
|
||||
private function getController(): DatabaseController
|
||||
{
|
||||
return new DatabaseController(
|
||||
$this->alert,
|
||||
$this->repository,
|
||||
$this->databaseRepository,
|
||||
$this->creationService,
|
||||
$this->deletionService,
|
||||
$this->updateService,
|
||||
$this->locationRepository
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Http\Controllers;
|
||||
|
||||
use Mockery as m;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Http\Controllers\Admin\Settings\MailController;
|
||||
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
||||
|
||||
class MailControllerTest extends ControllerTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag
|
||||
*/
|
||||
private $alert;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
private $configRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Console\Kernel
|
||||
*/
|
||||
private $kernel;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\SettingsRepositoryInterface
|
||||
*/
|
||||
private $settingsRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->alert = m::mock(AlertsMessageBag::class);
|
||||
$this->configRepository = m::mock(ConfigRepository::class);
|
||||
$this->encrypter = m::mock(Encrypter::class);
|
||||
$this->kernel = m::mock(Kernel::class);
|
||||
$this->settingsRepositoryInterface = m::mock(SettingsRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the mail controller for viewing mail settings page.
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->configRepository->shouldReceive('get');
|
||||
|
||||
$response = $this->getController()->index();
|
||||
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('admin.settings.mail', $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a MailController using our mocks.
|
||||
*
|
||||
* @return MailController
|
||||
*/
|
||||
public function getController()
|
||||
{
|
||||
return new MailController(
|
||||
$this->alert,
|
||||
$this->configRepository,
|
||||
$this->encrypter,
|
||||
$this->kernel,
|
||||
$this->settingsRepositoryInterface
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Http\Controllers;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\Http\RequestMockHelpers;
|
||||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
|
||||
abstract class ControllerTestCase extends TestCase
|
||||
{
|
||||
use ControllerAssertionsTrait, RequestMockHelpers;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Http\Controllers\Controller|\Mockery\Mock
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->buildRequestMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an instance of the controller.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Controllers\Controller|\Mockery\Mock $controller
|
||||
*/
|
||||
public function setControllerInstance($controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the controller.
|
||||
*
|
||||
* @return \Mockery\Mock|\Pterodactyl\Http\Controllers\Controller
|
||||
*/
|
||||
public function getControllerInstance()
|
||||
{
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to mock injectJavascript requests.
|
||||
*
|
||||
* @param array|null $args
|
||||
* @param bool $subset
|
||||
*/
|
||||
protected function mockInjectJavascript(array $args = null, bool $subset = false)
|
||||
{
|
||||
$controller = $this->getControllerInstance();
|
||||
|
||||
$controller->shouldReceive('setRequest')->with($this->request)->once()->andReturnSelf();
|
||||
if (is_null($args)) {
|
||||
$controller->shouldReceive('injectJavascript')->withAnyArgs()->once()->andReturnNull();
|
||||
} else {
|
||||
$with = $subset ? m::subset($args) : $args;
|
||||
|
||||
$controller->shouldReceive('injectJavascript')->with($with)->once()->andReturnNull();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks a request input call.
|
||||
*
|
||||
* @param string $param
|
||||
* @param mixed $return
|
||||
*/
|
||||
protected function mockRequestInput(string $param, $return = null)
|
||||
{
|
||||
$this->request->shouldReceive('input')->withArgs(function ($k) use ($param) {
|
||||
return $k === $param;
|
||||
})->andReturn($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return a mocked controller instance to use for testing.
|
||||
*
|
||||
* @param string $class
|
||||
* @param array $args
|
||||
* @return \Mockery\Mock|\Pterodactyl\Http\Controllers\Controller
|
||||
*/
|
||||
protected function buildMockedController(string $class, array $args = [])
|
||||
{
|
||||
$controller = m::mock($class, $args)->makePartial();
|
||||
|
||||
if (is_null($this->getControllerInstance())) {
|
||||
$this->setControllerInstance($controller);
|
||||
}
|
||||
|
||||
return $this->getControllerInstance();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue