Update repository base code to be cleaner and make use of PHP 7 features
This commit is contained in:
parent
0ec5a4e08c
commit
60eb60013c
96 changed files with 1048 additions and 1785 deletions
|
@ -46,15 +46,15 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->repository->shouldReceive('findWhere')->with([['user_id', '=', $model->id]])->once()->andReturn(['testkeys']);
|
||||
$this->repository->shouldReceive('findWhere')->with([['user_id', '=', $model->id]])->once()->andReturn(collect(['testkeys']));
|
||||
|
||||
$response = $this->getController()->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.api.index', $response);
|
||||
$this->assertViewHasKey('keys', $response);
|
||||
$this->assertViewKeyEquals('keys', ['testkeys'], $response);
|
||||
$this->assertViewKeyEquals('keys', collect(['testkeys']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testCreateController($admin)
|
||||
{
|
||||
$this->setRequestUser(factory(User::class)->make(['root_admin' => $admin]));
|
||||
$this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
|
||||
$response = $this->getController()->create($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
|
@ -87,7 +87,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
public function testStoreController($admin)
|
||||
{
|
||||
$this->setRequestMockClass(ApiKeyFormRequest::class);
|
||||
$model = $this->setRequestUser(factory(User::class)->make(['root_admin' => $admin]));
|
||||
$model = $this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
$keyModel = factory(APIKey::class)->make();
|
||||
|
||||
if ($admin) {
|
||||
|
@ -118,12 +118,12 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testRevokeController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->repository->shouldReceive('deleteWhere')->with([
|
||||
['user_id', '=', $model->id],
|
||||
['token', '=', 'testKey123'],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$response = $this->getController()->revoke($this->request, 'testKey123');
|
||||
$this->assertIsResponse($response);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -61,13 +61,13 @@ class SecurityControllerTest extends ControllerTestCase
|
|||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->config->shouldReceive('get')->with('session.driver')->once()->andReturn('database');
|
||||
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(['sessions']);
|
||||
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(collect(['sessions']));
|
||||
|
||||
$response = $this->getController()->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.security', $response);
|
||||
$this->assertViewHasKey('sessions', $response);
|
||||
$this->assertViewKeyEquals('sessions', ['sessions'], $response);
|
||||
$this->assertViewKeyEquals('sessions', collect(['sessions']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue