2018-08-19 14:40:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Services;
|
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
use App\Services\ITunesService;
|
2018-08-19 14:40:25 +00:00
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2018-08-29 07:05:24 +00:00
|
|
|
use Illuminate\Contracts\Cache\Repository as Cache;
|
2018-08-31 13:47:15 +00:00
|
|
|
use Illuminate\Log\Logger;
|
2018-08-19 14:40:25 +00:00
|
|
|
use Mockery;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
class ITunesServiceTest extends TestCase
|
2018-08-19 14:40:25 +00:00
|
|
|
{
|
2018-08-31 13:47:15 +00:00
|
|
|
public function testGetTrackUrl(): void
|
2018-08-19 14:40:25 +00:00
|
|
|
{
|
|
|
|
$term = 'Foo Bar';
|
|
|
|
|
|
|
|
/** @var Client $client */
|
|
|
|
$client = Mockery::mock(Client::class, [
|
2020-12-22 20:11:22 +00:00
|
|
|
'get' => new Response(200, [], file_get_contents(__DIR__ . '../../../blobs/itunes/track.json')),
|
2018-08-19 14:40:25 +00:00
|
|
|
]);
|
|
|
|
|
2018-08-29 07:05:24 +00:00
|
|
|
$cache = app(Cache::class);
|
2018-08-31 13:47:15 +00:00
|
|
|
$logger = app(Logger::class);
|
2018-08-29 07:05:24 +00:00
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
$url = (new ITunesService($client, $cache, $logger))->getTrackUrl($term);
|
2018-08-19 14:40:25 +00:00
|
|
|
|
|
|
|
self::assertEquals(
|
|
|
|
'https://itunes.apple.com/us/album/i-remember-you/id265611220?i=265611396&uo=4&at=1000lsGu',
|
|
|
|
$url
|
|
|
|
);
|
|
|
|
|
|
|
|
self::assertNotNull(cache('b57a14784d80c58a856e0df34ff0c8e2'));
|
|
|
|
}
|
|
|
|
}
|