Skip to content

Commit adfc4e3

Browse files
docs: document path options
1 parent 90e6942 commit adfc4e3

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

user_guide/command_line_tool.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ This is a summary of the usage of Behat in the command line:
4141
Set formatters parameters using json object.
4242
Keys are parameter names, values are values. (multiple
4343
values allowed)
44+
--print-absolute-paths
45+
Print absolute paths in output
46+
--editor-url=EDITOR-URL
47+
URL template for opening files in an editor
4448
--init
4549
Initialize all registered test suites.
4650
--lang=LANG

user_guide/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ profiles.
88
:maxdepth: 2
99

1010
configuration/suites.rst
11+
configuration/printing_paths.rst
1112
configuration/yaml_configuration.rst
1213

1314
``behat.php``
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)