diff --git a/README.md b/README.md index 21b6e3b..265ead4 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,12 @@ You can define these undefined steps in your PHPUnit test class like this: ``` +You can specify individual scenarios to run because the scenario title is given as the data provider name. For example to test a scenario with title `Undefined`: +``` +phpunit --filter '@Undefined' +``` +More complex possibilities exist; see https://phpunit.de/manual/6.5/en/textui.html#textui.examples.filter-patterns. + ## Notes The code has not been tested with Behat's 'Outline' scenarios, but it should work. diff --git a/src/TestTraits/BehatProvidingTrait.php b/src/TestTraits/BehatProvidingTrait.php index bc5ed08..edee874 100644 --- a/src/TestTraits/BehatProvidingTrait.php +++ b/src/TestTraits/BehatProvidingTrait.php @@ -7,6 +7,7 @@ use Behat\Gherkin\Parser; use Behat\Gherkin\Keywords\ArrayKeywords; use Behat\Gherkin\Node\FeatureNode; +use Behat\Gherkin\Node\OutlineNode; trait BehatProvidingTrait { @@ -47,12 +48,12 @@ public function provideBehatFeature(FeatureNode $feature) { $scenarios = []; foreach ($feature->getScenarios() as $scenario) { if ($scenario instanceof OutlineNode) { - foreach ($outline->getExamples() as $example) { - $scenarios[] = [$example->getTitle(), $example, $feature]; + foreach ($scenario->getExamples() as $index => $example) { + $scenarios[$scenario->getTitle() . ' #' . $index] = [$example, $feature]; } } else { - $scenarios[] = [$scenario->getTitle(), $scenario, $feature]; + $scenarios[$scenario->getTitle()] = [$scenario, $feature]; } } return $scenarios; diff --git a/src/TestTraits/BehatScenarioTestingTrait.php b/src/TestTraits/BehatScenarioTestingTrait.php index af5ce8a..fe951d6 100644 --- a/src/TestTraits/BehatScenarioTestingTrait.php +++ b/src/TestTraits/BehatScenarioTestingTrait.php @@ -12,15 +12,21 @@ trait BehatScenarioTestingTrait { use BehatContainerTrait; use BehatEnvironmentTrait; + // Make the scenario and feature available to test methods, + // this can be useful for debugging output. + protected $behatFeature; + protected $behatScenario; + public static function assertBehatScenarioPassed($scenarioResults, $scenario = NULL, $stepResults = [], $snippetGenerator = NULL, $environment = NULL, $message = '', $callHandler = '') { - $constraint = new HasScenarioPassedConstraint($scenario, $stepResults, $callHandler, $snippetGenerator, $environment); self::assertThat($scenarioResults, $constraint, $message); } public function executeBehatScenario($scenario, $feature) { $tester = $this->getBehatContainer()->get(TesterExtension::SCENARIO_TESTER_ID); + $this->behatFeature = $feature; + $this->behatScenario = $scenario; $scenarioResults = $tester->test($this->getBehatEnvironment(), $feature, $scenario, false); return $scenarioResults; } diff --git a/src/TestTraits/BehatTestTrait.php b/src/TestTraits/BehatTestTrait.php index dd548a2..84f73ec 100644 --- a/src/TestTraits/BehatTestTrait.php +++ b/src/TestTraits/BehatTestTrait.php @@ -2,14 +2,6 @@ namespace PHPUnitBehat\TestTraits; -// proof read -// @todo coding standards -// github real -// packagist -// require in project -// merge branch -// refactor hasscenariopassedconstraint for reuse - trait BehatTestTrait { use BehatScenarioTestingTrait; @@ -31,7 +23,7 @@ public function providerTestBehatScenario() { * * @dataProvider providerTestBehatScenario */ - public function testBehatScenario($scenarioTitle, $scenario, $feature) { + public function testBehatScenario($scenario, $feature) { $this->assertBehatScenario($scenario, $feature); }