propresenter-php/php/tests/ProFileReaderTest.php
2026-03-01 16:12:17 +01:00

80 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace ProPresenter\Parser\Tests;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use ProPresenter\Parser\ProFileReader;
use RuntimeException;
class ProFileReaderTest extends TestCase
{
#[Test]
public function readThrowsOnMissingFile(): void
{
$this->expectException(InvalidArgumentException::class);
ProFileReader::read(dirname(__DIR__, 2) . '/ref/does-not-exist.pro');
}
#[Test]
public function readThrowsOnEmptyFile(): void
{
$this->expectException(RuntimeException::class);
ProFileReader::read(dirname(__DIR__, 2) . '/ref/all-songs/Du machst alles neu_ver2025-05-11-4.pro');
}
#[Test]
public function readLoadsTestProAndReturnsSong(): void
{
$song = ProFileReader::read(dirname(__DIR__, 2) . '/ref/Test.pro');
$this->assertSame('Test', $song->getName());
$this->assertCount(4, $song->getGroups());
$this->assertCount(2, $song->getArrangements());
}
#[Test]
public function readHandlesUtf8Filename(): void
{
$matches = glob(dirname(__DIR__, 2) . '/ref/all-songs/-- ANK*DIGUNGEN --.pro');
$this->assertNotFalse($matches);
$this->assertNotEmpty($matches);
$song = ProFileReader::read($matches[0]);
$this->assertNotSame('', $song->getName());
$this->assertGreaterThanOrEqual(0, count($song->getGroups()));
}
#[Test]
public function readLoadsDiverseReferenceFilesSuccessfully(): void
{
$repoRoot = dirname(__DIR__, 2);
$files = [
$repoRoot . '/ref/Test.pro',
$repoRoot . '/ref/all-songs/Cornerstone.pro',
$repoRoot . '/ref/all-songs/Du machst alles neu.pro',
$repoRoot . '/ref/all-songs/-- MODERATION --.pro',
];
$oceans = glob($repoRoot . '/ref/all-songs/Oceans*TRANS*.pro');
$announcements = glob($repoRoot . '/ref/all-songs/-- ANK*DIGUNGEN --.pro');
$this->assertNotFalse($oceans);
$this->assertNotFalse($announcements);
$this->assertNotEmpty($oceans);
$this->assertNotEmpty($announcements);
$files[] = $oceans[0];
$files[] = $announcements[0];
foreach ($files as $file) {
$song = ProFileReader::read($file);
$this->assertNotSame('', $song->getUuid(), sprintf('Song UUID should not be empty for %s', basename($file)));
}
}
}