2017-08-05 18:55:02 +00:00
|
|
|
<?php
|
|
|
|
|
2017-12-09 22:39:34 +00:00
|
|
|
namespace Tests\Integration\Services;
|
2017-08-05 18:55:02 +00:00
|
|
|
|
2018-08-19 11:08:16 +00:00
|
|
|
use App\Services\YouTubeService;
|
|
|
|
use Exception;
|
2017-08-05 18:55:02 +00:00
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2018-08-31 13:47:15 +00:00
|
|
|
use Illuminate\Contracts\Cache\Repository;
|
|
|
|
use Illuminate\Log\Logger;
|
|
|
|
use Mockery;
|
2017-08-05 18:55:02 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2018-08-19 11:08:16 +00:00
|
|
|
class YouTubeServiceTest extends TestCase
|
2017-08-05 18:55:02 +00:00
|
|
|
{
|
2017-12-09 18:34:27 +00:00
|
|
|
/**
|
2018-08-19 11:08:16 +00:00
|
|
|
* @throws Exception
|
2017-12-09 18:34:27 +00:00
|
|
|
*/
|
2018-08-31 13:47:15 +00:00
|
|
|
public function testSearch(): void
|
2017-08-05 18:55:02 +00:00
|
|
|
{
|
|
|
|
$this->withoutEvents();
|
|
|
|
|
2018-08-19 11:08:16 +00:00
|
|
|
/** @var Client $client */
|
2018-08-31 13:47:15 +00:00
|
|
|
$client = Mockery::mock(Client::class, [
|
2017-12-09 22:39:34 +00:00
|
|
|
'get' => new Response(200, [], file_get_contents(__DIR__.'../../../blobs/youtube/search.json')),
|
2017-08-05 18:55:02 +00:00
|
|
|
]);
|
|
|
|
|
2018-08-31 13:47:15 +00:00
|
|
|
$api = new YouTubeService($client, app(Repository::class), app(Logger::class));
|
2017-08-05 18:55:02 +00:00
|
|
|
$response = $api->search('Lorem Ipsum');
|
|
|
|
|
|
|
|
$this->assertEquals('Slipknot - Snuff [OFFICIAL VIDEO]', $response->items[0]->snippet->title);
|
|
|
|
$this->assertNotNull(cache('1492972ec5c8e6b3a9323ba719655ddb'));
|
|
|
|
}
|
|
|
|
}
|