From 18e394eb14016056345413021002e14c1b41b929 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 3 Mar 2018 18:24:40 -0600 Subject: [PATCH] Fix tests --- .../Admin/DatabaseControllerTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/Unit/Http/Controllers/Admin/DatabaseControllerTest.php b/tests/Unit/Http/Controllers/Admin/DatabaseControllerTest.php index 108198bde..c3735b927 100644 --- a/tests/Unit/Http/Controllers/Admin/DatabaseControllerTest.php +++ b/tests/Unit/Http/Controllers/Admin/DatabaseControllerTest.php @@ -13,11 +13,13 @@ 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; @@ -35,6 +37,11 @@ class DatabaseControllerTest extends TestCase */ private $creationService; + /** + * @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface|\Mockery\Mock + */ + private $databaseRepository; + /** * @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService|\Mockery\Mock */ @@ -64,6 +71,7 @@ class DatabaseControllerTest extends TestCase $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); @@ -94,9 +102,14 @@ class DatabaseControllerTest extends TestCase 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('getWithServers')->with(1)->once()->andReturn($model); + $this->repository->shouldReceive('find')->with(1)->once()->andReturn($model); + $this->databaseRepository->shouldReceive('getDatabasesForHost') + ->once() + ->with(1) + ->andReturn($paginator); $response = $this->getController()->view(1); @@ -104,8 +117,10 @@ class DatabaseControllerTest extends TestCase $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); } /** @@ -118,6 +133,7 @@ class DatabaseControllerTest extends TestCase return new DatabaseController( $this->alert, $this->repository, + $this->databaseRepository, $this->creationService, $this->deletionService, $this->updateService,