Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links to runner output that open the file directly in my IDE #6259

Closed
ThomasLandauer opened this issue Oct 7, 2021 · 3 comments · Fixed by #6261
Closed

Add links to runner output that open the file directly in my IDE #6259

ThomasLandauer opened this issue Oct 7, 2021 · 3 comments · Fixed by #6261

Comments

@ThomasLandauer
Copy link
Member

I started implementing what I suggested at #6208 :

First step: The line https://github.com/Codeception/Codeception/blob/4.1/src/Codeception/Subscriber/Console.php#L360 needs to be replaced by something like:

->append(codecept_absolute_path(Descriptor::getTestFileName($failedTest)))

My plan would be to define a new configuration parameter in codeception.yml, following phpstan's format (see https://phpstan.org/user-guide/output-format#opening-file-in-an-editor):

editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'

And if this parameter is present, replace the value of "Test" here:

1) FooCest: Try bar
 Test  tests/functional/FooCest.php:tryBar
 Step  See whatever
 Fail  Number of elements counted differs from expected range
Failed asserting that false is true.

...with the clickable link.

Questions:

  1. How can I access a configuration parameter from there?
  2. How can I access the failing line number? If that's not so easy, let's just omit it for now - a link to just the file is still better than nothing ;-)
@Naktibalda
Copy link
Member

  1. How can I access a configuration parameter from there?

You get all settings from settings section of codeception.yaml file in $this->options when codeception run command is used. codecept dry-run doesn't get them, so it is always necessary to check if $this->options['editorUrl'] is set before using it.

  1. How can I access the failing line number?

$failEvent->getFail() returns exception.
You can use getFile and getLine methods to find the origin place of exception, but it won't be in the test file.
You could iterate stack trace retuned by $failEvent->getFail()->getTrace ` and find the first row matching the name of test file.

ThomasLandauer added a commit to ThomasLandauer/Codeception that referenced this issue Oct 8, 2021
Closes Codeception#6259

I followed the syntax of https://phpstan.org/user-guide/output-format#opening-file-in-an-editor even though we would need the second `%` here. (This is due to some phpstan internals, the code ultimately reads `\str_replace(['%file%', '%line%'], ...`
But I'd say having an *identical* `editorUrl` syntax between Codeception and phpstan by far outweighs the "cost" of some unneeded `%` characters... ;-)
@ThomasLandauer
Copy link
Member Author

@Naktibalda thanks! See #6261

but it won't be in the test file.

You mean that it would only refer to some Codeception generated "temporary" file?

@Naktibalda
Copy link
Member

You mean that it would only refer to some Codeception generated "temporary" file?

Exceptions are usually raised by one of PHPUnit\Framework\Assert methods or application code.

Naktibalda pushed a commit that referenced this issue Dec 21, 2021
* Adding clickable `editorUrl` from `codeception.yml`

Closes #6259

I followed the syntax of https://phpstan.org/user-guide/output-format#opening-file-in-an-editor even though we would need the second `%` here. (This is due to some phpstan internals, the code ultimately reads `\str_replace(['%file%', '%line%'], ...`
But I'd say having an *identical* `editorUrl` syntax between Codeception and phpstan by far outweighs the "cost" of some unneeded `%` characters... ;-)

* Update Console.php

* Update Console.php

* Update Console.php

* Update Step.php

* Update Console.php

* Update Console.php

* Update Console.php

* Update Console.php

* Update Console.php

* Update Console.php

* Update Console.php

* Bringing back but `@deprecate`ing `getLine()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants