song scanner test

master
Josha von Gizycki 3 years ago
parent d510bb7c10
commit 37503d1d16

@ -23,7 +23,7 @@ class SongScanner
/** /**
* @return ScannedSong[] * @return ScannedSong[]
*/ */
public function scanFunctional(): array { public function scan(): array {
$it = new RecursiveDirectoryIterator( $it = new RecursiveDirectoryIterator(
$this->rootDir, $this->rootDir,
FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS
@ -35,7 +35,6 @@ class SongScanner
public static function isMp3(iterable $files): iterable { public static function isMp3(iterable $files): iterable {
return filter(function (SplFileInfo $file, string $_): bool { return filter(function (SplFileInfo $file, string $_): bool {
echo $_ . "\n";
return $file->isFile() && strtolower($file->getExtension()) === 'mp3'; return $file->isFile() && strtolower($file->getExtension()) === 'mp3';
}, $files); }, $files);
} }

@ -2,15 +2,24 @@
namespace App\Tests\Adapter; namespace App\Tests\Adapter;
use App\Adapter\ScannedSong;
use App\Adapter\SongScanner; use App\Adapter\SongScanner;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function Lambdish\Phunctional\map;
class SongScannerTest extends TestCase class SongScannerTest extends TestCase
{ {
function testDefaultBehaviourFunctional() { function testDefaultBehaviourFunctional() {
$scanner = new SongScanner(__DIR__); $scanner = new SongScanner(__DIR__);
$songs = $scanner->scanFunctional(); $songs = $scanner->scan();
var_dump($songs);
$this->assertCount(5, $songs);
$combinations = map(fn(ScannedSong $song) => [$song->artist, $song->album, $song->title], $songs);
$this->assertContains(['Band A', 'Album A', 'Song 1'], $combinations);
$this->assertContains(['Band A', 'Album A', 'Song 2'], $combinations);
$this->assertContains(['Band A', 'Album B', 'Song 1'], $combinations);
$this->assertContains(['Band B', 'Album A', 'Song 1'], $combinations);
} }
} }

Loading…
Cancel
Save