mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
Add tests for SongZipArchive
This commit is contained in:
parent
a8f98b2377
commit
8bb547cb4d
2 changed files with 72 additions and 0 deletions
|
@ -123,4 +123,12 @@ class SongZipArchive
|
|||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ZipArchive
|
||||
*/
|
||||
public function getArchive()
|
||||
{
|
||||
return $this->archive;
|
||||
}
|
||||
}
|
||||
|
|
64
tests/Unit/SongZipArchiveTest.php
Normal file
64
tests/Unit/SongZipArchiveTest.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Song;
|
||||
use App\Models\SongZipArchive;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SongZipArchiveTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_can_be_instantiated()
|
||||
{
|
||||
$songZipArchive = new SongZipArchive();
|
||||
$this->assertInstanceOf(SongZipArchive::class, $songZipArchive);
|
||||
$this->assertInstanceOf(\ZipArchive::class, $songZipArchive->getArchive());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_song_can_be_added_into_an_archive()
|
||||
{
|
||||
// Given a song
|
||||
$song = factory(Song::class)->create([
|
||||
'path' => realpath(__DIR__.'/../songs/full.mp3'),
|
||||
]);
|
||||
|
||||
// When I add the song into the archive
|
||||
$songArchive = new SongZipArchive();
|
||||
$songArchive->addSong($song);
|
||||
|
||||
// Then I see the archive contains one file
|
||||
$archive = $songArchive->getArchive();
|
||||
$this->assertEquals(1, $archive->numFiles);
|
||||
|
||||
// and the file is our song
|
||||
$this->assertEquals('full.mp3', $archive->getNameIndex(0));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function multiple_songs_can_be_added_into_an_archive()
|
||||
{
|
||||
// Given some songs
|
||||
$songs = collect([
|
||||
factory(Song::class)->create([
|
||||
'path' => realpath(__DIR__.'/../songs/full.mp3'),
|
||||
]),
|
||||
factory(Song::class)->create([
|
||||
'path' => realpath(__DIR__.'/../songs/lorem.mp3'),
|
||||
])
|
||||
]);
|
||||
|
||||
// When I add the songs into the archive
|
||||
$songArchive = new SongZipArchive();
|
||||
$songArchive->addSongs($songs);
|
||||
|
||||
// Then I see the archive contains two files
|
||||
$archive = $songArchive->getArchive();
|
||||
$this->assertEquals(2, $archive->numFiles);
|
||||
|
||||
// and the files are our songs
|
||||
$this->assertEquals('full.mp3', $archive->getNameIndex(0));
|
||||
$this->assertEquals('lorem.mp3', $archive->getNameIndex(1));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue