2024-05-31 14:51:10 +00:00
|
|
|
<?php
|
|
|
|
|
2024-07-07 13:29:37 +00:00
|
|
|
namespace Tests\Integration\Values;
|
2024-05-31 14:51:10 +00:00
|
|
|
|
|
|
|
use App\Models\Song;
|
|
|
|
use App\Values\Podcast\EpisodePlayable;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-10-24 10:45:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2024-05-31 14:51:10 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class EpisodePlayableTest extends TestCase
|
|
|
|
{
|
2024-10-24 10:45:45 +00:00
|
|
|
#[Test]
|
|
|
|
public function createAndRetrieved(): void
|
2024-05-31 14:51:10 +00:00
|
|
|
{
|
|
|
|
Http::fake([
|
|
|
|
'https://example.com/episode.mp3' => Http::response('foo'),
|
|
|
|
]);
|
|
|
|
|
2024-07-07 13:29:37 +00:00
|
|
|
/** @var Song $episode */
|
2024-05-31 14:51:10 +00:00
|
|
|
$episode = Song::factory()->asEpisode()->create([
|
|
|
|
'path' => 'https://example.com/episode.mp3',
|
|
|
|
]);
|
|
|
|
|
2024-09-03 10:52:07 +00:00
|
|
|
$playable = EpisodePlayable::getForEpisode($episode);
|
|
|
|
|
|
|
|
Http::assertSentCount(1);
|
2024-05-31 14:51:10 +00:00
|
|
|
self::assertSame('acbd18db4cc2f85cedef654fccc4a4d8', $playable->checksum);
|
|
|
|
|
|
|
|
self::assertTrue(Cache::has("episode-playable.$episode->id"));
|
|
|
|
|
2024-09-03 10:52:07 +00:00
|
|
|
$retrieved = EpisodePlayable::getForEpisode($episode);
|
|
|
|
|
|
|
|
// No extra HTTP request should be made.
|
|
|
|
Http::assertSentCount(1);
|
2024-05-31 14:51:10 +00:00
|
|
|
self::assertSame($playable, $retrieved);
|
|
|
|
self::assertTrue($retrieved->valid());
|
|
|
|
|
|
|
|
file_put_contents($playable->path, 'bar');
|
|
|
|
self::assertFalse($retrieved->valid());
|
|
|
|
}
|
|
|
|
}
|