Update repository base code to be cleaner and make use of PHP 7 features

This commit is contained in:
Dane Everitt 2018-01-04 22:49:50 -06:00
parent 0ec5a4e08c
commit 60eb60013c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
96 changed files with 1048 additions and 1785 deletions

View file

@ -15,6 +15,7 @@ use Pterodactyl\Models\Server;
use Tests\Assertions\ControllerAssertionsTrait;
use Tests\Unit\Http\Controllers\ControllerTestCase;
use Pterodactyl\Http\Controllers\Base\IndexController;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
@ -62,19 +63,19 @@ class IndexControllerTest extends ControllerTestCase
*/
public function testIndexController()
{
$model = $this->setRequestUser();
$paginator = m::mock(LengthAwarePaginator::class);
$model = $this->generateRequestUserModel();
$this->request->shouldReceive('input')->with('query')->once()->andReturn('searchTerm');
$this->repository->shouldReceive('search')->with('searchTerm')->once()->andReturnSelf()
->shouldReceive('filterUserAccessServers')->with(
$model->id, $model->root_admin, 'all', ['user']
)->once()->andReturn(['test']);
$this->repository->shouldReceive('setSearchTerm')->with('searchTerm')->once()->andReturnSelf()
->shouldReceive('filterUserAccessServers')->with($model, User::FILTER_LEVEL_ALL)
->once()->andReturn($paginator);
$response = $this->controller->getIndex($this->request);
$this->assertIsViewResponse($response);
$this->assertViewNameEquals('base.index', $response);
$this->assertViewHasKey('servers', $response);
$this->assertViewKeyEquals('servers', ['test'], $response);
$this->assertViewKeyEquals('servers', $paginator, $response);
}
/**
@ -82,7 +83,7 @@ class IndexControllerTest extends ControllerTestCase
*/
public function testStatusController()
{
$user = $this->setRequestUser();
$user = $this->generateRequestUserModel();
$server = factory(Server::class)->make(['suspended' => 0, 'installed' => 1]);
$this->repository->shouldReceive('findFirstWhere')->with([['uuidShort', '=', $server->uuidShort]])->once()->andReturn($server);
@ -105,7 +106,7 @@ class IndexControllerTest extends ControllerTestCase
*/
public function testStatusControllerWhenServerNotInstalled()
{
$user = $this->setRequestUser();
$user = $this->generateRequestUserModel();
$server = factory(Server::class)->make(['suspended' => 0, 'installed' => 0]);
$this->repository->shouldReceive('findFirstWhere')->with([['uuidShort', '=', $server->uuidShort]])->once()->andReturn($server);