koel/tests/Integration/Services/MediaMetadataServiceTest.php

61 lines
1.8 KiB
PHP
Raw Normal View History

2018-08-19 09:05:33 +00:00
<?php
namespace Tests\Integration\Services;
use App\Models\Album;
use App\Models\Artist;
use App\Services\ImageWriter;
2018-08-19 09:05:33 +00:00
use App\Services\MediaMetadataService;
2018-08-31 13:47:15 +00:00
use Illuminate\Log\Logger;
use Mockery;
use Mockery\MockInterface;
2018-08-19 09:05:33 +00:00
use Tests\TestCase;
class MediaMetadataServiceTest extends TestCase
{
/** @var MediaMetadataService */
private $mediaMetadataService;
/** @var ImageWriter|MockInterface */
private $imageWriter;
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-19 09:05:33 +00:00
{
parent::setUp();
$this->imageWriter = Mockery::mock(ImageWriter::class);
$this->mediaMetadataService = new MediaMetadataService($this->imageWriter, app(Logger::class));
2018-08-19 09:05:33 +00:00
}
2018-08-31 13:47:15 +00:00
public function testWriteAlbumCover(): void
2018-08-19 09:05:33 +00:00
{
/** @var Album $album */
$album = factory(Album::class)->create();
$coverContent = 'dummy';
$coverPath = '/koel/public/images/album/foo.jpg';
2018-08-19 09:05:33 +00:00
$this->imageWriter
->shouldReceive('writeFromBinaryData')
->once()
->with('/koel/public/images/album/foo.jpg', 'dummy');
2018-08-19 09:05:33 +00:00
$this->mediaMetadataService->writeAlbumCover($album, $coverContent, 'jpg', $coverPath);
2018-08-19 09:05:33 +00:00
$this->assertEquals('http://localhost/public/img/covers/foo.jpg', Album::find($album->id)->cover);
}
2018-08-31 13:47:15 +00:00
public function testWriteArtistImage(): void
2018-08-19 09:05:33 +00:00
{
$artist = factory(Artist::class)->create();
$imageContent = 'dummy';
$imagePath = '/koel/public/images/artist/foo.jpg';
2018-08-19 09:05:33 +00:00
$this->imageWriter
->shouldReceive('writeFromBinaryData')
->once()
->with('/koel/public/images/artist/foo.jpg', 'dummy');
2018-08-19 09:05:33 +00:00
$this->mediaMetadataService->writeArtistImage($artist, $imageContent, 'jpg', $imagePath);
2018-08-19 09:05:33 +00:00
$this->assertEquals('http://localhost/public/img/artists/foo.jpg', Artist::find($artist->id)->image);
}
}