|
| 1 | +Printing paths |
| 2 | +============== |
| 3 | + |
| 4 | +When showing test results or failures Behat will print the path to the related files. Usually it will |
| 5 | +simply print a path which is relative to the current directory but there are some configuration options |
| 6 | +that will let you modify this: |
| 7 | + |
| 8 | +``Print Absolute Paths``: if this is set to true, Behat will print the full absolute path instead. |
| 9 | + |
| 10 | +``Editor URL``: if this is set, Behat will surround each path with a link that, when clicked, will open |
| 11 | +the file in your IDE. This parameter is a template which can use some placeholders which will be |
| 12 | +replaced at run time by Behat. The available placeholders are |
| 13 | + |
| 14 | +- ``{relPath}``: Relative path to the file |
| 15 | +- ``{absPath}``: Absolute path to the file |
| 16 | +- ``{line}}``: Line number (note that this is optional and may not be available in some cases) |
| 17 | + |
| 18 | +The specific value that you need to use will depend on your IDE and other factors (for example, it may |
| 19 | +need to be different if you are running your code within a Docker container). Some examples could be: |
| 20 | + |
| 21 | +- For PhpStorm: ``phpstorm://open?file={relPath}&line={line}`` |
| 22 | +- For VS Code: ``vscode://file/{absPath}:{line}`` |
| 23 | + |
| 24 | +.. note:: |
| 25 | + |
| 26 | + The path style can be different for the visible path and the one used in the editor URL. For example you |
| 27 | + might have a visible relative path and use an absolute path in the URL. |
| 28 | + |
| 29 | +These options can be set using the ``withPathOptions()`` function of the ``Profile`` config object, for example: |
| 30 | + |
| 31 | +.. code-block:: php |
| 32 | +
|
| 33 | + <?php |
| 34 | + // behat.php |
| 35 | +
|
| 36 | + use Behat\Config\Config; |
| 37 | + use Behat\Config\Profile; |
| 38 | +
|
| 39 | + return (new Config()) |
| 40 | + ->withProfile((new Profile('default')) |
| 41 | + ->withPathOptions( |
| 42 | + printAbsolutePaths: true, |
| 43 | + editorUrl: 'phpstorm://open?file={relPath}&line={line}' |
| 44 | + )); |
| 45 | +
|
| 46 | +They can also be set as command line options (notice that the editor URL will usually need to be quoted): |
| 47 | + |
| 48 | +.. code-block:: bash |
| 49 | +
|
| 50 | + behat --print-absolute-paths --editor-url="phpstorm://open?file={relPath}&line={line}" |
0 commit comments