koel/tests/Integration/Services/MediaCacheServiceTest.php

63 lines
1.6 KiB
PHP
Raw Normal View History

2018-08-19 14:56:56 +00:00
<?php
namespace Tests\Integration\Services;
use App\Models\Album;
use App\Models\Artist;
use App\Models\Song;
use App\Services\MediaCacheService;
use Illuminate\Cache\Repository as Cache;
use Mockery;
use Tests\TestCase;
class MediaCacheServiceTest extends TestCase
{
private $mediaCacheService;
private $cache;
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-19 14:56:56 +00:00
{
parent::setUp();
$this->cache = Mockery::mock(Cache::class);
$this->mediaCacheService = new MediaCacheService($this->cache);
}
2019-07-22 07:03:23 +00:00
public function testGetIfCacheIsNotAvailable(): void
2018-08-19 14:56:56 +00:00
{
Song::factory(5)->create();
2018-08-19 14:56:56 +00:00
$this->cache->shouldReceive('rememberForever')->andReturn([
'albums' => Album::orderBy('name')->get(),
'artists' => Artist::orderBy('name')->get(),
'songs' => Song::all(),
]);
$data = $this->mediaCacheService->get();
2020-09-06 18:21:39 +00:00
self::assertCount(6, $data['albums']); // 5 new albums and the default Unknown Album
self::assertCount(7, $data['artists']); // 5 new artists and the default Various and Unknown Artist
self::assertCount(5, $data['songs']);
2018-08-19 14:56:56 +00:00
}
2019-07-22 07:03:23 +00:00
public function testGetIfCacheIsAvailable(): void
2018-08-19 14:56:56 +00:00
{
2018-08-24 15:27:19 +00:00
$this->cache->shouldReceive('rememberForever')->andReturn(['dummy']);
2018-08-19 14:56:56 +00:00
config(['koel.cache_media' => true]);
$data = $this->mediaCacheService->get();
2020-09-06 18:21:39 +00:00
self::assertEquals(['dummy'], $data);
2018-08-19 14:56:56 +00:00
}
2019-07-22 07:03:23 +00:00
public function testCacheDisabled(): void
2018-08-19 14:56:56 +00:00
{
$this->cache->shouldReceive('rememberForever')->never();
config(['koel.cache_media' => false]);
$this->mediaCacheService->get();
}
}