Skip to content

Commit 910a290

Browse files
author
LDA
committed
Add hyperlinks
Turns file paths seen in `Saved Source Files` into links that open those files right inside your browser Enable the `Zenstruck\Browser\Test\BrowserExtension` extension Configure the file link format with the environment variable `BROWSER_FILE_LINK_FORMAT`, the default value is `file://%f#L%l` Can be overloaded in the `phpunit.xml.dist` for example ``` <server name="BROWSER_FILE_LINK_FORMAT" value="'file://%f#L%l"/> ``` iUseful when running your app in a container or in a virtual machine, see Symfony doc https://symfony.com/doc/current/reference/configuration/framework.html#ide
1 parent 28b7e1a commit 910a290

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ There are several environment variables available to configure:
563563
| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` |
564564
| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ |
565565
| `BROWSER_ALWAYS_START_WEBSERVER` | Always start a webserver configured for your current test env before running tests (only applies to `PantherBrowser`). | `0` _(false)_ |
566+
| `BROWSER_FILE_LINK_FORMAT` | Turns file paths seen in `Saved Source Files` into links that open those files right inside your browser | `file://%f#L%l` |
566567

567568
## Extending
568569

src/Browser/Test/LegacyExtension.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111

1212
namespace Zenstruck\Browser\Test;
1313

14+
use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
15+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter as LegacyFileLinkFormatter;
1416
use Zenstruck\Browser;
1517

18+
if (!class_exists(FileLinkFormatter::class) && class_exists(LegacyFileLinkFormatter::class)) {
19+
class_alias(LegacyFileLinkFormatter::class, FileLinkFormatter::class);
20+
}
21+
22+
1623
/**
1724
* @author Kevin Bond <[email protected]>
1825
*/
@@ -24,6 +31,12 @@ class LegacyExtension
2431

2532
/** @var array<string,array<string,string[]>> */
2633
private array $savedArtifacts = [];
34+
private FileLinkFormatter $fileLinkFormatter;
35+
36+
public function __construct(FileLinkFormatter|null $fileLinkFormatter = null)
37+
{
38+
$this->fileLinkFormatter = $fileLinkFormatter ?? new FileLinkFormatter($_ENV['BROWSER_FILE_LINK_FORMAT'] ?? $_SERVER['BROWSER_FILE_LINK_FORMAT'] ?? '');
39+
}
2740

2841
/**
2942
* @internal
@@ -77,7 +90,7 @@ public function executeAfterLastTest(): void
7790
echo "\n {$category}:";
7891

7992
foreach ($artifacts as $artifact) {
80-
echo "\n * {$artifact}:";
93+
echo "\n * \033]8;;{$this->fileLinkFormatter->format(realpath($artifact) ?: '', 1)}\033\\$artifact\033]8;;\033\\";
8194
}
8295
}
8396
}

0 commit comments

Comments
 (0)