1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-15 22:52:32 +01:00
flox/backend/tests/Traits/Mocks.php
Viktor Geringer 619e407bcd subpage design (#64)
* start with subpage design

* transitions

* transitions

* transitions, stuff

* modal for trailer

* english fallback for trailers

* slugs in url

* bit refactor

* tests and fixtures

* travis

* update production files

* move time limit to config and display error message to user

* fix import

* fix review
2017-04-11 08:45:08 +02:00

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;
}
}