2017-04-11 08:45:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Services\IMDB;
|
2017-07-28 12:44:22 +02:00
|
|
|
use App\Services\Models\ItemService;
|
2017-04-11 08:45:08 +02:00
|
|
|
use App\Services\Storage;
|
|
|
|
use App\Services\TMDB;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
|
|
use GuzzleHttp\HandlerStack;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
|
|
|
|
|
|
|
trait Mocks {
|
|
|
|
|
|
|
|
public function createGuzzleMock()
|
|
|
|
{
|
|
|
|
$fixtures = func_get_args();
|
|
|
|
$responses = [];
|
|
|
|
|
|
|
|
foreach($fixtures as $fixture) {
|
|
|
|
$responses[] = new Response(200, ['X-RateLimit-Remaining' => [40]], $fixture);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mock = new MockHandler($responses);
|
|
|
|
|
|
|
|
$handler = HandlerStack::create($mock);
|
|
|
|
$this->app->instance(Client::class, new Client(['handler' => $handler]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createStorageDownloadsMock()
|
|
|
|
{
|
|
|
|
$mock = $this->mock(Storage::class);
|
2017-07-28 11:37:33 +02:00
|
|
|
$mock->shouldReceive('downloadImages')->andReturn(null);
|
2017-04-11 08:45:08 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:44:22 +02:00
|
|
|
public function createRefreshAllMock()
|
|
|
|
{
|
|
|
|
$mock = $this->mock(ItemService::class);
|
|
|
|
$mock->shouldReceive('refreshAll')->andReturn(null);
|
|
|
|
}
|
|
|
|
|
2017-04-11 08:45:08 +02:00
|
|
|
public function createTmdbEpisodeMock()
|
|
|
|
{
|
|
|
|
// Mock this to avoid unknown requests to TMDb (get seasons and then get episodes for each season)
|
|
|
|
$mock = $this->mock(TMDB::class);
|
|
|
|
$mock->shouldReceive('tvEpisodes')->andReturn(json_decode($this->tmdbFixtures('tv/episodes')));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createImdbRatingMock()
|
|
|
|
{
|
|
|
|
$mock = $this->mock(IMDB::class);
|
|
|
|
$mock->shouldReceive('parseRating')->andReturn(json_decode($this->imdbFixtures('rating.txt')));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mock($class)
|
|
|
|
{
|
|
|
|
$mock = Mockery::mock(app($class))->makePartial();
|
|
|
|
|
|
|
|
$this->app->instance($class, $mock);
|
|
|
|
|
|
|
|
return $mock;
|
|
|
|
}
|
|
|
|
}
|