what the fuck
This commit is contained in:
1 parent
c1b1c2f372
commit
72a99a5bcd
69 files changed
+7519
-558
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Service;
|
||||
|
||||
use App\Repository\SettingRepository;
|
||||
use App\Service\MusicBrainzClient;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
final class MusicBrainzClientTest extends TestCase
|
||||
{
|
||||
public function testDetailedAlbumUsesCanonicalMusicBrainzUrlForOpenSourceLink(): void
|
||||
{
|
||||
$releaseId = '78eb2077-b86d-4382-9ce7-38f9260316f0';
|
||||
|
||||
$httpClient = $this->createMock(ClientInterface::class);
|
||||
$httpClient->expects(self::once())
|
||||
->method('request')
|
||||
->with(
|
||||
'GET',
|
||||
'https://musicbrainz.org/ws/2/release/' . $releaseId,
|
||||
self::callback(static function (array $options): bool {
|
||||
$query = $options['query'] ?? [];
|
||||
return ($query['fmt'] ?? null) === 'json';
|
||||
})
|
||||
)
|
||||
->willReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode([
|
||||
'id' => $releaseId,
|
||||
'title' => 'Reference Album',
|
||||
'artist-credit' => [
|
||||
['name' => 'Reference Artist'],
|
||||
],
|
||||
'media' => [[
|
||||
'position' => 1,
|
||||
'tracks' => [[
|
||||
'id' => 'track-1',
|
||||
'number' => '1',
|
||||
'title' => 'Reference Track',
|
||||
'length' => 180000,
|
||||
]],
|
||||
]],
|
||||
// External storefront URL should not be used as the "Open Source" link.
|
||||
'relations' => [[
|
||||
'url' => ['resource' => 'https://store.example.test/reference-album'],
|
||||
]],
|
||||
], JSON_THROW_ON_ERROR)));
|
||||
|
||||
$settings = $this->createMock(SettingRepository::class);
|
||||
$cache = new ArrayAdapter();
|
||||
|
||||
$client = new MusicBrainzClient($httpClient, $cache, $settings);
|
||||
$album = $client->getAlbumWithTracks('mbid:' . $releaseId);
|
||||
|
||||
self::assertIsArray($album);
|
||||
self::assertSame(
|
||||
'https://musicbrainz.org/release/' . $releaseId,
|
||||
$album['external_urls']['external'] ?? null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user