allocationRepository = m::mock(AllocationRepositoryInterface::class); $this->databaseRepository = m::mock(DatabaseRepositoryInterface::class); $this->eggRepository = m::mock(EggRepositoryInterface::class); $this->nodeRepository = m::mock(NodeRepositoryInterface::class); $this->serverRepository = m::mock(ServerRepositoryInterface::class); $this->userRepository = m::mock(UserRepositoryInterface::class); } public function testIndexController() { $controller = $this->getController(); $this->serverRepository->shouldReceive('all')->withNoArgs(); $this->nodeRepository->shouldReceive('all')->withNoArgs()->andReturn(collect([factory(Node::class)->make(), factory(Node::class)->make()])); $this->userRepository->shouldReceive('count')->withNoArgs(); $this->eggRepository->shouldReceive('count')->withNoArgs(); $this->databaseRepository->shouldReceive('count')->withNoArgs(); $this->allocationRepository->shouldReceive('count')->withNoArgs(); $this->serverRepository->shouldReceive('getSuspendedServersCount')->withNoArgs(); $this->nodeRepository->shouldReceive('getUsageStatsRaw')->twice()->andReturn([ 'memory' => [ 'value' => 1024, 'max' => 512, ], 'disk' => [ 'value' => 1024, 'max' => 512, ], ]); $controller->shouldReceive('injectJavascript')->once(); $response = $controller->index(); $this->assertIsViewResponse($response); $this->assertViewNameEquals('admin.statistics', $response); } private function getController() { return $this->buildMockedController(StatisticsController::class, [$this->allocationRepository, $this->databaseRepository, $this->eggRepository, $this->nodeRepository, $this->serverRepository, $this->userRepository, ] ); } }