diff --git a/src/Util/MakerFileLinkFormatter.php b/src/Util/MakerFileLinkFormatter.php index 50f6a2712..7acf53fa2 100644 --- a/src/Util/MakerFileLinkFormatter.php +++ b/src/Util/MakerFileLinkFormatter.php @@ -12,7 +12,8 @@ namespace Symfony\Bundle\MakerBundle\Util; use Symfony\Component\Console\Formatter\OutputFormatterStyle; -use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; +use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter; +use Symfony\Component\HttpKernel\Debug\FileLinkFormatter as LegacyFileLinkFormatter; /** * @internal @@ -20,7 +21,7 @@ final class MakerFileLinkFormatter { public function __construct( - private ?FileLinkFormatter $fileLinkFormatter = null, + private FileLinkFormatter|LegacyFileLinkFormatter|null $fileLinkFormatter = null, ) { } diff --git a/tests/FileManagerTest.php b/tests/FileManagerTest.php index 570d08d0b..cfbb071ab 100644 --- a/tests/FileManagerTest.php +++ b/tests/FileManagerTest.php @@ -16,8 +16,9 @@ use Symfony\Bundle\MakerBundle\Util\AutoloaderUtil; use Symfony\Bundle\MakerBundle\Util\MakerFileLinkFormatter; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; +use Symfony\Component\HttpKernel\Debug\FileLinkFormatter as LegacyFileLinkFormatter; class FileManagerTest extends TestCase { @@ -193,7 +194,12 @@ public function testWithMakerFileLinkFormatter(): void $this->markTestSkipped(); } - $fileLinkFormatter = $this->createMock(FileLinkFormatter::class); + if (class_exists(FileLinkFormatter::class)) { + $fileLinkFormatter = $this->createMock(FileLinkFormatter::class); + } else { + $fileLinkFormatter = $this->createMock(LegacyFileLinkFormatter::class); + } + $fileLinkFormatter ->method('format') ->willReturnCallback(function ($path, $line) { diff --git a/tests/Util/MakerFileLinkFormatterTest.php b/tests/Util/MakerFileLinkFormatterTest.php index a56a8e45a..3476df4ff 100644 --- a/tests/Util/MakerFileLinkFormatterTest.php +++ b/tests/Util/MakerFileLinkFormatterTest.php @@ -13,7 +13,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Bundle\MakerBundle\Util\MakerFileLinkFormatter; -use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; +use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter; +use Symfony\Component\HttpKernel\Debug\FileLinkFormatter as LegacyFileLinkFormatter; final class MakerFileLinkFormatterTest extends TestCase { @@ -39,7 +40,12 @@ public function testMakeLinkedPath(bool $withFileLinkFormatter, bool $linkFormat $fileLinkFormatter = null; if ($withFileLinkFormatter) { - $fileLinkFormatter = $this->createMock(FileLinkFormatter::class); + if (class_exists(FileLinkFormatter::class)) { + $fileLinkFormatter = $this->createMock(FileLinkFormatter::class); + } else { + $fileLinkFormatter = $this->createMock(LegacyFileLinkFormatter::class); + } + $return = $linkFormatterReturnsLink ? $this->returnCallback(function ($path, $line) { return sprintf('subl://open?url=file://%s&line=%d', $path, $line); }) : $this->returnValue(false);