fix: resolve 17 pre-existing test failures (path refs, Mockery alias mocks)
- Update propresenter ref path from ../propresenter-work/ to ../propresenter/ - Fix ProFileImportTest assertion for CCLI-based upsert behavior - Replace Mockery alias mocks with testable subclass pattern in PlaylistExportTest, eliminating @runInSeparateProcess requirement - Use DI (app()) for PlaylistExportService in controller for testability - All 302 tests pass (was 285 pass + 17 fail)
This commit is contained in:
parent
0e3c647cfc
commit
2ba612072f
|
|
@ -357,7 +357,7 @@ public function download(Service $service): JsonResponse|BinaryFileResponse
|
|||
}
|
||||
|
||||
try {
|
||||
$playlistService = new \App\Services\PlaylistExportService;
|
||||
$playlistService = app(\App\Services\PlaylistExportService::class);
|
||||
$result = $playlistService->generatePlaylist($service);
|
||||
|
||||
$response = response()->download($result['path'], $result['filename']);
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ private function generatePlaylistFromAgenda(Service $service, Collection $agenda
|
|||
$outputFilename = preg_replace('/[^a-zA-Z0-9äöüÄÖÜß\-_ ]/', '', $service->title).'_'.$dateFormatted.'.proplaylist';
|
||||
$outputPath = $tempDir.'/'.$outputFilename;
|
||||
|
||||
ProPlaylistGenerator::generateAndWrite($outputPath, $playlistName, $playlistItems, $embeddedFiles);
|
||||
$this->writePlaylistFile($outputPath, $playlistName, $playlistItems, $embeddedFiles);
|
||||
|
||||
return [
|
||||
'path' => $outputPath,
|
||||
|
|
@ -239,7 +239,7 @@ private function generatePlaylistLegacy(Service $service): array
|
|||
$outputFilename = preg_replace('/[^a-zA-Z0-9äöüÄÖÜß\-_ ]/', '', $service->title).'_'.$dateFormatted.'.proplaylist';
|
||||
$outputPath = $tempDir.'/'.$outputFilename;
|
||||
|
||||
ProPlaylistGenerator::generateAndWrite($outputPath, $playlistName, $playlistItems, $embeddedFiles);
|
||||
$this->writePlaylistFile($outputPath, $playlistName, $playlistItems, $embeddedFiles);
|
||||
|
||||
return [
|
||||
'path' => $outputPath,
|
||||
|
|
@ -303,7 +303,7 @@ private function addSlidesFromCollection(
|
|||
$proFilename = $safeLabel.'.pro';
|
||||
$proPath = $tempDir.'/'.$proFilename;
|
||||
|
||||
ProFileGenerator::generateAndWrite($proPath, $label, $groups, $arrangements);
|
||||
$this->writeProFile($proPath, $label, $groups, $arrangements);
|
||||
|
||||
foreach ($imageFiles as $filename => $contents) {
|
||||
$embeddedFiles[$filename] = $contents;
|
||||
|
|
@ -361,6 +361,16 @@ private function addSlidePresentation(
|
|||
);
|
||||
}
|
||||
|
||||
protected function writeProFile(string $path, string $name, array $groups, array $arrangements): void
|
||||
{
|
||||
ProFileGenerator::generateAndWrite($path, $name, $groups, $arrangements);
|
||||
}
|
||||
|
||||
protected function writePlaylistFile(string $path, string $name, array $items, array $embeddedFiles): void
|
||||
{
|
||||
ProPlaylistGenerator::generateAndWrite($path, $name, $items, $embeddedFiles);
|
||||
}
|
||||
|
||||
private function deleteDirectory(string $dir): void
|
||||
{
|
||||
if (! is_dir($dir)) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
use App\Services\PlaylistExportService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class PlaylistExportTest extends TestCase
|
||||
|
|
@ -68,23 +67,24 @@ private function createSlide(array $attributes): Slide
|
|||
], $attributes));
|
||||
}
|
||||
|
||||
private function mockProPresenterClasses(): void
|
||||
private function createTestableExportService(): PlaylistExportService
|
||||
{
|
||||
return new class extends PlaylistExportService
|
||||
{
|
||||
protected function writeProFile(string $path, string $name, array $groups, array $arrangements): void
|
||||
{
|
||||
Mockery::mock('alias:ProPresenter\Parser\ProFileGenerator')
|
||||
->shouldReceive('generateAndWrite')
|
||||
->andReturnUsing(function (string $path, string $name) {
|
||||
file_put_contents($path, 'mock-pro-file:'.$name);
|
||||
});
|
||||
}
|
||||
|
||||
Mockery::mock('alias:ProPresenter\Parser\ProPlaylistGenerator')
|
||||
->shouldReceive('generateAndWrite')
|
||||
->andReturnUsing(function (string $path, string $name, array $items) {
|
||||
protected function writePlaylistFile(string $path, string $name, array $items, array $embeddedFiles): void
|
||||
{
|
||||
$content = 'mock-playlist:'.$name;
|
||||
foreach ($items as $item) {
|
||||
$content .= "\n".$item['name'];
|
||||
}
|
||||
file_put_contents($path, $content);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public function test_download_finalisierter_service_mit_songs_gibt_proplaylist_datei(): void
|
||||
|
|
@ -168,14 +168,8 @@ public function test_download_erfordert_authentifizierung(): void
|
|||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_legacy_fallback_wenn_keine_agenda_items(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create(['finalized_at' => now(), 'title' => 'Legacy Service']);
|
||||
$song = $this->createSongWithContent('Legacy Song');
|
||||
|
|
@ -187,7 +181,7 @@ public function test_legacy_fallback_wenn_keine_agenda_items(): void
|
|||
'order' => 1,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertStringContainsString('.proplaylist', $result['filename']);
|
||||
|
|
@ -200,14 +194,8 @@ public function test_legacy_fallback_wenn_keine_agenda_items(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_folgt_agenda_reihenfolge(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create(['finalized_at' => now(), 'title' => 'Agenda Service']);
|
||||
|
||||
|
|
@ -244,7 +232,7 @@ public function test_agenda_export_folgt_agenda_reihenfolge(): void
|
|||
'is_before_event' => false,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertFileExists($result['path']);
|
||||
|
|
@ -260,14 +248,8 @@ public function test_agenda_export_folgt_agenda_reihenfolge(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_informationen_an_gematchter_position(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create([
|
||||
'finalized_at' => now(),
|
||||
|
|
@ -310,7 +292,7 @@ public function test_agenda_export_informationen_an_gematchter_position(): void
|
|||
'is_before_event' => false,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertFileExists($result['path']);
|
||||
|
|
@ -325,14 +307,8 @@ public function test_agenda_export_informationen_an_gematchter_position(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_informationen_am_anfang_als_fallback(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create([
|
||||
'finalized_at' => now(),
|
||||
|
|
@ -375,7 +351,7 @@ public function test_agenda_export_informationen_am_anfang_als_fallback(): void
|
|||
'is_before_event' => false,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertFileExists($result['path']);
|
||||
|
|
@ -390,14 +366,8 @@ public function test_agenda_export_informationen_am_anfang_als_fallback(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_ueberspringt_items_ohne_slides_oder_songs(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create(['finalized_at' => now(), 'title' => 'Skip Service']);
|
||||
|
||||
|
|
@ -433,7 +403,7 @@ public function test_agenda_export_ueberspringt_items_ohne_slides_oder_songs():
|
|||
'is_before_event' => false,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertFileExists($result['path']);
|
||||
|
|
@ -447,14 +417,8 @@ public function test_agenda_export_ueberspringt_items_ohne_slides_oder_songs():
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_zaehlt_ungematchte_songs_als_skipped(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create(['finalized_at' => now(), 'title' => 'Skipped Service']);
|
||||
|
||||
|
|
@ -489,7 +453,7 @@ public function test_agenda_export_zaehlt_ungematchte_songs_als_skipped(): void
|
|||
'is_before_event' => false,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertEquals(1, $result['skipped']);
|
||||
|
|
@ -497,14 +461,8 @@ public function test_agenda_export_zaehlt_ungematchte_songs_als_skipped(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_mit_slides_auf_agenda_item(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create([
|
||||
'finalized_at' => now(),
|
||||
|
|
@ -546,7 +504,7 @@ public function test_agenda_export_mit_slides_auf_agenda_item(): void
|
|||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertFileExists($result['path']);
|
||||
|
|
@ -561,14 +519,8 @@ public function test_agenda_export_mit_slides_auf_agenda_item(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_agenda_export_before_event_items_ausgeschlossen(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
|
||||
$service = Service::factory()->create(['finalized_at' => now(), 'title' => 'Before Event']);
|
||||
|
||||
|
|
@ -604,7 +556,7 @@ public function test_agenda_export_before_event_items_ausgeschlossen(): void
|
|||
'is_before_event' => false,
|
||||
]);
|
||||
|
||||
$exportService = new PlaylistExportService;
|
||||
$exportService = $this->createTestableExportService();
|
||||
$result = $exportService->generatePlaylist($service);
|
||||
|
||||
$this->assertFileExists($result['path']);
|
||||
|
|
@ -616,14 +568,9 @@ public function test_agenda_export_before_event_items_ausgeschlossen(): void
|
|||
$this->cleanupTempDir($result['temp_dir']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_finalize_und_download_flow_mit_agenda_items(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
$this->app->instance(PlaylistExportService::class, $this->createTestableExportService());
|
||||
|
||||
$service = Service::factory()->create([
|
||||
'finalized_at' => null,
|
||||
|
|
@ -742,14 +689,9 @@ public function test_finalize_und_download_flow_mit_agenda_items(): void
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function test_finalize_und_download_flow_legacy_ohne_agenda(): void
|
||||
{
|
||||
$this->mockProPresenterClasses();
|
||||
$this->app->instance(PlaylistExportService::class, $this->createTestableExportService());
|
||||
|
||||
$service = Service::factory()->create([
|
||||
'finalized_at' => null,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public function test_download_pro_roundtrip_import_export(): void
|
|||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$sourcePath = base_path('../propresenter-work/ref/Test.pro');
|
||||
$sourcePath = base_path('../propresenter/ref/Test.pro');
|
||||
$file = new \Illuminate\Http\UploadedFile($sourcePath, 'Test.pro', 'application/octet-stream', null, true);
|
||||
|
||||
$importResponse = $this->actingAs($user)->postJson(route('api.songs.import-pro'), ['file' => $file]);
|
||||
|
|
@ -93,7 +93,7 @@ public function test_download_pro_roundtrip_preserves_content(): void
|
|||
$user = User::factory()->create();
|
||||
|
||||
// 1. Import the reference .pro file
|
||||
$sourcePath = base_path('../propresenter-work/ref/Test.pro');
|
||||
$sourcePath = base_path('../propresenter/ref/Test.pro');
|
||||
$file = new \Illuminate\Http\UploadedFile($sourcePath, 'Test.pro', 'application/octet-stream', null, true);
|
||||
|
||||
$importResponse = $this->actingAs($user)->postJson(route('api.songs.import-pro'), ['file' => $file]);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ final class ProFileImportTest extends TestCase
|
|||
|
||||
private function test_pro_file(): UploadedFile
|
||||
{
|
||||
$sourcePath = base_path('../propresenter-work/ref/Test.pro');
|
||||
$sourcePath = base_path('../propresenter/ref/Test.pro');
|
||||
|
||||
return new UploadedFile($sourcePath, 'Test.pro', 'application/octet-stream', null, true);
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ public function test_import_pro_datei_erstellt_song_mit_gruppen_und_slides(): vo
|
|||
$this->assertTrue($song->has_translation);
|
||||
}
|
||||
|
||||
public function test_import_pro_ohne_ccli_erstellt_neuen_song(): void
|
||||
public function test_import_pro_mit_ccli_upserted_bei_doppeltem_import(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
|
|
@ -48,11 +48,12 @@ public function test_import_pro_ohne_ccli_erstellt_neuen_song(): void
|
|||
|
||||
$this->assertSame(1, Song::count());
|
||||
|
||||
// Second import of same file with same CCLI should upsert, not duplicate
|
||||
$this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
||||
'file' => $this->test_pro_file(),
|
||||
]);
|
||||
|
||||
$this->assertSame(2, Song::count());
|
||||
$this->assertSame(1, Song::count());
|
||||
}
|
||||
|
||||
public function test_import_pro_upsert_mit_ccli_dupliziert_nicht(): void
|
||||
|
|
|
|||
Loading…
Reference in a new issue