2017-06-10 13:25:30 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
namespace Tests\Unit\Models;
|
2017-06-10 13:25:30 +00:00
|
|
|
|
|
|
|
use App\Models\Artist;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ArtistTest extends TestCase
|
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testExistingArtistCanBeRetrievedUsingName(): void
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2017-06-10 15:09:56 +00:00
|
|
|
/** @var Artist $artist */
|
2020-11-14 16:57:25 +00:00
|
|
|
$artist = Artist::factory()->create(['name' => 'Foo']);
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertTrue(Artist::getOrCreate('Foo')->is($artist));
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testNewArtistIsCreatedWithName(): void
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertNull(Artist::whereName('Foo')->first());
|
|
|
|
self::assertSame('Foo', Artist::getOrCreate('Foo')->name);
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 20:11:22 +00:00
|
|
|
/** @return array<mixed> */
|
2020-11-14 16:57:25 +00:00
|
|
|
public function provideEmptyNames(): array
|
2017-06-10 13:25:30 +00:00
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
return [
|
|
|
|
[''],
|
|
|
|
[' '],
|
|
|
|
[null],
|
|
|
|
[false],
|
|
|
|
];
|
|
|
|
}
|
2017-06-10 13:25:30 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
/** @dataProvider provideEmptyNames */
|
|
|
|
public function testGettingArtistWithEmptyNameReturnsUnknownArtist($name): void
|
|
|
|
{
|
|
|
|
self::assertTrue(Artist::getOrCreate($name)->is_unknown);
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testArtistsWithNameInUtf16EncodingAreRetrievedCorrectly(): void
|
2017-06-10 15:17:34 +00:00
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
$name = file_get_contents(__DIR__ . '../../../blobs/utf16');
|
2020-11-14 16:57:25 +00:00
|
|
|
$artist = Artist::getOrCreate($name);
|
2017-06-10 15:17:34 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertTrue(Artist::getOrCreate($name)->is($artist));
|
2017-06-10 15:17:34 +00:00
|
|
|
}
|
2017-06-10 13:25:30 +00:00
|
|
|
}
|