koel/tests/YouTubeTest.php

44 lines
1.2 KiB
PHP
Raw Normal View History

2016-07-14 08:47:50 +00:00
<?php
use App\Models\Song;
use App\Services\YouTube;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
2016-07-30 15:34:34 +00:00
use Mockery as m;
2016-07-14 08:47:50 +00:00
use YouTube as YouTubeFacade;
class YouTubeTest extends TestCase
{
use DatabaseTransactions, WithoutMiddleware;
public function testSearch()
{
$this->withoutEvents();
$client = m::mock(Client::class, [
2016-11-24 04:07:57 +00:00
'get' => new Response(200, [], file_get_contents(__DIR__.'/blobs/youtube/search.json')),
2016-07-14 08:47:50 +00:00
]);
$api = new YouTube(null, $client);
$response = $api->search('Lorem Ipsum');
$this->assertEquals('Slipknot - Snuff [OFFICIAL VIDEO]', $response->items[0]->snippet->title);
// Is it cached?
2016-12-12 02:43:14 +00:00
$this->assertNotNull(cache('1492972ec5c8e6b3a9323ba719655ddb'));
2016-07-14 08:47:50 +00:00
}
public function testSearchVideosRelatedToSong()
{
$this->createSampleMediaSet();
$song = Song::first();
// We test on the facade here
2016-07-30 15:49:14 +00:00
YouTubeFacade::shouldReceive('searchVideosRelatedToSong')->once();
2016-07-14 08:47:50 +00:00
$this->visit("/api/youtube/search/song/{$song->id}");
}
}