Fix PHP error when step is undefined#1
Merged
Chekote merged 1 commit intov3.4.3-with-patchesfrom Jan 30, 2019
Merged
Conversation
## Steps to recreate:
Write a feature file with an undefined step
Execute the feature file with Behat
## Expected Behavior
Behat should warn that the suite has undefined steps, and ask you to choose a context to generate the snippet.
## Actual Behavior
The following PHP fatal error occurs:
```
PHP Fatal error: Class name must be a valid object or a string in /var/www/vendor/behat/behat/src/Behat/Behat/Context/Environment/InitializedContextEnvironment.php on line 118
PHP Fatal Error.
Details: Array
(
[type] => 1
[message] => Class name must be a valid object or a string
[file] => /var/www/vendor/behat/behat/src/Behat/Behat/Context/Environment/InitializedContextEnvironment.php
[line] => 118
)
Stack trace: Array
(
[0] => Array
(
[file] => /var/www/bin/behat
[line] => 33
[function] => fatalHandler
[args] => Array
(
)
)
[1] => Array
(
[function] => {closure}
[args] => Array
(
)
)
)
```
## Cause
The Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier class is being initialized with an empty string. When a snippet is undefined, the system attempts to present a list of all of the available contexts to generate the snippet within. One of the contexts that the system tries to list is the context defined in Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier. Since this is an empty string, it causes a PHP error when passed to resolveContextClass() via hasContextClass().
## Fix
Add a falsy check on the class parameter to hasContextClass(), and return false the param is falsy rather than passing it to resolveContextClass().
Chekote
pushed a commit
that referenced
this pull request
Aug 20, 2021
This PR was merged into the 3.8.x-dev branch.
Discussion
----------
I added "return 0" to fix this error message:
```
$ vendor/bin/behat --debug
behat version 3.7.0
--- configuration
environment variable (BEHAT_PARAMS): none
configuration file: /home/jawira/PhpstormProjects/xxxxxxxx/behat.yml
--- extensions
extensions loaded: api_extension
PHP Fatal error: Uncaught TypeError: Return value of "Behat\Testwork\Cli\DebugCommand::execute()" must be of the type int, NULL returned. in /home/jawira/PhpstormProjects/xxxxxxxx/vendor/symfony/console/Command/Command.php:258
Stack trace:
#0 /home/jawira/PhpstormProjects/xxxxxxxx/vendor/symfony/console/Application.php(912): Symfony\Component\Console\Command\Command->run()
#1 /home/jawira/PhpstormProjects/xxxxxxxx/vendor/symfony/console/Application.php(264): Symfony\Component\Console\Application->doRunCommand()
#2 /home/jawira/PhpstormProjects/xxxxxxxx/vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(124): Symfony\Component\Console\Application->doRun()
#3 /home/jawira/PhpstormProjects/xxxxxxxx/vendor/symfony/console/Application.php(140): Behat\Testwork\Cli\Application->doRun()
#4 /home/jawira/PhpstormProjects/xxxxxxxx/vendor/behat/behat/bin/behat(34): Symfony\Component\Console\Application->run()
Behat#5 {main}
thrown in /home/jawira/PhpstormProjects/xxxxxxxx/vendor/symfony/console/Command/Command.php on line 258
```
Commits
-------
48a3636 Add "return 0" in DebugCommand.php
902b3c6 Add debug test
lorenzodalaqua
added a commit
to lorenzodalaqua/Behat
that referenced
this pull request
Jul 1, 2022
This is applicable to Scenarios which are a part of a Scenario Outline. Each example in an outline would be appended an index to its name in the output (ex: Chekote#1, Chekote#2, Chekote#3...), but in a behat --rerun, they are all appended Chekote#1, which breaks IFT detection. Not having the Example number is the way the script currently expects the output to be, so it was removed.
lorenzodalaqua
added a commit
to lorenzodalaqua/Behat
that referenced
this pull request
Jul 1, 2022
This is applicable to Scenarios which are a part of a Scenario Outline. Each example in an outline would be appended an index to its name in the output (ex: Chekote#1, Chekote#2, Chekote#3...), but in a behat --rerun, they are all appended Chekote#1, which breaks IFT detection. Not having the Example number is the way the script currently expects the output to be, so it was removed.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Steps to recreate:
Write a feature file with an undefined step
Execute the feature file with Behat
Expected Behavior
Behat should warn that the suite has undefined steps, and ask you to choose a context to generate the snippet.
Actual Behavior
The following PHP fatal error occurs:
Cause
The Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier class is being initialized with an empty string. When a snippet is undefined, the system attempts to present a list of all of the available contexts to generate the snippet within. One of the contexts that the system tries to list is the context defined in Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier. Since this is an empty string, it causes a PHP error when passed to resolveContextClass() via hasContextClass().
Fix
Add a falsy check on the class parameter to hasContextClass(), and return false the param is falsy rather than passing it to resolveContextClass().