mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 22:52:32 +01:00
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
use App\Services\IMDB;
|
||
|
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);
|
||
|
$mock->shouldReceive('downloadPoster', 'downloadBackdrop')->andReturn(null, null);
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|