2018-08-29 09:41:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Services;
|
|
|
|
|
|
|
|
use App\Services\FileSynchronizer;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class FileSynchronizerTest extends TestCase
|
|
|
|
{
|
2021-06-05 10:47:56 +00:00
|
|
|
private FileSynchronizer $fileSynchronizer;
|
2018-08-29 09:41:24 +00:00
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function setUp(): void
|
2018-08-29 09:41:24 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-11-14 16:57:25 +00:00
|
|
|
|
2018-08-29 09:41:24 +00:00
|
|
|
$this->fileSynchronizer = app(FileSynchronizer::class);
|
|
|
|
}
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function testGetFileInfo(): void
|
2018-08-29 09:41:24 +00:00
|
|
|
{
|
2022-07-07 10:45:57 +00:00
|
|
|
$info = $this->fileSynchronizer->setFile(__DIR__ . '/../../songs/full.mp3')->getFileScanInformation();
|
2018-08-29 09:41:24 +00:00
|
|
|
|
|
|
|
$expectedData = [
|
|
|
|
'artist' => 'Koel',
|
|
|
|
'album' => 'Koel Testing Vol. 1',
|
|
|
|
'title' => 'Amet',
|
|
|
|
'track' => 5,
|
|
|
|
'disc' => 3,
|
|
|
|
'lyrics' => "Foo\rbar",
|
|
|
|
'cover' => [
|
2020-12-22 20:11:22 +00:00
|
|
|
'data' => file_get_contents(__DIR__ . '/../../blobs/cover.png'),
|
2018-08-29 09:41:24 +00:00
|
|
|
'image_mime' => 'image/png',
|
|
|
|
'image_width' => 512,
|
|
|
|
'image_height' => 512,
|
|
|
|
'imagetype' => 'PNG',
|
|
|
|
'picturetype' => 'Other',
|
|
|
|
'description' => '',
|
|
|
|
'datalength' => 7627,
|
|
|
|
],
|
2022-07-07 10:45:57 +00:00
|
|
|
'path' => realpath(__DIR__ . '/../../songs/full.mp3'),
|
2020-12-22 20:11:22 +00:00
|
|
|
'mtime' => filemtime(__DIR__ . '/../../songs/full.mp3'),
|
2018-08-29 09:41:24 +00:00
|
|
|
'albumartist' => '',
|
|
|
|
];
|
|
|
|
|
2022-07-07 10:45:57 +00:00
|
|
|
self::assertArraySubset($expectedData, $info->toArray());
|
|
|
|
self::assertEqualsWithDelta(10, $info->length, 0.001);
|
2018-08-29 09:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testSongWithoutTitleHasFileNameAsTitle(): void
|
2018-08-29 09:41:24 +00:00
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
$this->fileSynchronizer->setFile(__DIR__ . '/../../songs/blank.mp3');
|
2020-11-14 16:57:25 +00:00
|
|
|
|
2022-07-07 10:45:57 +00:00
|
|
|
self::assertSame('blank', $this->fileSynchronizer->getFileScanInformation()->title);
|
2018-08-29 09:41:24 +00:00
|
|
|
}
|
|
|
|
}
|