@@ -420,4 +420,74 @@ public static function invalidOptionProvider(): array
420420 ],
421421 ];
422422 }
423+
424+ #[DataProvider('getVersionPathProvider ' )]
425+ public function testGetVersionPath (
426+ array $ structure ,
427+ string $ path ,
428+ ?string $ expected ,
429+ ): void {
430+ $ root = vfsStream::setup ('root ' , structure: $ structure );
431+
432+ if ($ expected === null ) {
433+ $ this ->expectException (\ValueError::class);
434+ $ this ->expectExceptionMessage ("Unable to find a version.php in {$ path }" );
435+ Helper::getVersionPath ($ path );
436+ } else {
437+ $ this ->assertSame ($ expected , Helper::getVersionPath ($ path ));
438+ }
439+ }
440+
441+ public static function getVersionPathProvider (): \Generator
442+ {
443+ yield 'Valid path ' => [
444+ 'structure ' => [
445+ 'version.php ' => '<?php // Version file content. ' ,
446+ ],
447+ 'path ' => vfsStream::url ('root ' ),
448+ 'expected ' => vfsStream::url ('root/version.php ' ),
449+ ];
450+
451+ yield 'Valid path with trailing slash ' => [
452+ 'structure ' => [
453+ 'version.php ' => '<?php // Version file content. ' ,
454+ ],
455+ 'path ' => vfsStream::url ('root/ ' ),
456+ 'expected ' => vfsStream::url ('root/version.php ' ),
457+ ];
458+
459+ yield 'Valid path in public ' => [
460+ 'structure ' => [
461+ 'public ' => [
462+ 'version.php ' => '<?php // Version file content. ' ,
463+ ],
464+ ],
465+ 'path ' => vfsStream::url ('root ' ),
466+ 'expected ' => vfsStream::url ('root/public/version.php ' ),
467+ ];
468+
469+ yield 'Valid path in public with trailing slash ' => [
470+ 'structure ' => [
471+ 'public ' => [
472+ 'version.php ' => '<?php // Version file content. ' ,
473+ ],
474+ ],
475+ 'path ' => vfsStream::url ('root/ ' ),
476+ 'expected ' => vfsStream::url ('root/public/version.php ' ),
477+ ];
478+
479+ yield 'Invalid path ' => [
480+ 'structure ' => [],
481+ 'path ' => vfsStream::url ('root ' ),
482+ 'expected ' => null ,
483+ ];
484+
485+ yield 'Invalid path in public ' => [
486+ 'structure ' => [
487+ 'public ' => [],
488+ ],
489+ 'path ' => vfsStream::url ('root ' ),
490+ 'expected ' => null ,
491+ ];
492+ }
423493}
0 commit comments