isDir()) { @rmdir($item->getPathname()); } else { @unlink($item->getPathname()); } } @rmdir($path); } afterEach(function (): void { \Mockery::close(); }); test('legacy archive is copied into amministratore storage', function () { $service = app(AmministratoreArchiveSyncService::class); $legacyRoot = storage_path('app/testing/legacy_sources'); $legacyCode = '0010'; $sourcePath = $legacyRoot . DIRECTORY_SEPARATOR . $legacyCode; cleanupDirectory($legacyRoot); mkdir($sourcePath, 0755, true); file_put_contents($sourcePath . DIRECTORY_SEPARATOR . 'singolo_anno.mdb', 'dummy'); file_put_contents($sourcePath . DIRECTORY_SEPARATOR . 'info.txt', 'hello world'); $archiveBase = storage_path('app/testing/amministratori/TESTADM'); cleanupDirectory($archiveBase); $amministratore = \Mockery::mock(Amministratore::class); $amministratore->shouldReceive('provisionArchiveIfMissing')->once(); $amministratore->shouldReceive('getArchivePath')->andReturn($archiveBase); $result = $service->sync($amministratore, $legacyCode, $legacyRoot, true); $targetPath = $archiveBase . DIRECTORY_SEPARATOR . 'legacy' . DIRECTORY_SEPARATOR . $legacyCode; $targetFile = $targetPath . DIRECTORY_SEPARATOR . 'info.txt'; expect(is_dir($targetPath))->toBeTrue(); expect(is_file($targetFile))->toBeTrue(); expect(trim((string) file_get_contents($targetFile)))->toBe('hello world'); expect($result['legacy_code'])->toBe($legacyCode); expect($result['files_count'])->toBeGreaterThan(0); cleanupDirectory($legacyRoot); cleanupDirectory($archiveBase); });