diff --git a/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php b/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php index 62d1223..966c0f2 100644 --- a/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php +++ b/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php @@ -257,12 +257,22 @@ protected function setupSnippetGenerator() { $identifier = new \Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier($context); $this->snippetGenerator->setContextIdentifier($identifier); - // Modify the snippet generator's template so that it no longer - // refers to PendingException(). - $templateReflector = new \ReflectionProperty(get_class($this->snippetGenerator), 'templateTemplate'); - $templateReflector->setAccessible(true); - $templateReflector->setValue($this->snippetGenerator, $this->snippetTemplate); - } + // Determine the correct property name. + $reflector = new \ReflectionClass(get_class($this->snippetGenerator)); + $templateProperty = null; + if ($reflector->hasProperty('snippetTemplate')) { + $templateProperty = 'snippetTemplate'; + } elseif ($reflector->hasProperty('templateTemplate')) { + $templateProperty = 'templateTemplate'; + } + + if ($templateProperty !== null) { + // Modify the snippet generator's template to remove reference to pending exception. + $templateReflector = new \ReflectionProperty(get_class($this->snippetGenerator), $templateProperty); + $templateReflector->setAccessible(true); + $templateReflector->setValue($this->snippetGenerator, $this->snippetTemplate); + } + } protected function generateSnippet($step) { if (!is_null($this->snippetGenerator) && !is_null($this->environment)) { diff --git a/src/TestTraits/BehatProvidingTrait.php b/src/TestTraits/BehatProvidingTrait.php index e80d939..d25144d 100644 --- a/src/TestTraits/BehatProvidingTrait.php +++ b/src/TestTraits/BehatProvidingTrait.php @@ -25,7 +25,7 @@ trait BehatProvidingTrait { * A Behat feature. */ public static function parseBehatFeature($featureString, $keywords = NULL) { - $lexer = new Lexer(self::getBehatKeywords($keywords)); + $lexer = new Lexer(static::getBehatKeywords($keywords)); $parser = new Parser($lexer); $feature = $parser->parse($featureString); return $feature; @@ -71,7 +71,7 @@ public static function provideBehatFeature(FeatureNode $feature) { */ protected static function getBehatKeywords($keywords = NULL) { if (is_null($keywords)) { - $keywords = self::getBehatDefaultKeywords(); + $keywords = static::getBehatDefaultKeywords(); } return $keywords; } diff --git a/src/TestTraits/BehatTestTrait.php b/src/TestTraits/BehatTestTrait.php index 6e7a48b..7b7d172 100644 --- a/src/TestTraits/BehatTestTrait.php +++ b/src/TestTraits/BehatTestTrait.php @@ -14,8 +14,8 @@ trait BehatTestTrait { * breaking it down into individual scenarios for testing. */ public static function providerTestBehatScenario() { - $feature = self::parseBehatFeature(self::$feature); - return self::provideBehatFeature($feature); + $feature = static::parseBehatFeature(static::$feature); + return static::provideBehatFeature($feature); } /** diff --git a/tests/BehatProvidingTraitChildTest.php b/tests/BehatProvidingTraitChildTest.php new file mode 100644 index 0000000..3327610 --- /dev/null +++ b/tests/BehatProvidingTraitChildTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(ScenarioInterface::class, $this->getProvidedScenario()); + $this->assertEquals($title, $this->getProvidedScenario()->getTitle()); + } + + /** + * @Then getProvidedFeature returns a feature with the title :title + */ + public function getProvidedFeatureGets($title) { + $this->assertInstanceOf(KeywordNodeInterface::class, $this->getProvidedFeature()); + $this->assertEquals($title, $this->getProvidedFeature()->getTitle()); + } + +} + diff --git a/tests/BehatProvidingTraitTestParent.php b/tests/BehatProvidingTraitTestParent.php new file mode 100644 index 0000000..3b1b938 --- /dev/null +++ b/tests/BehatProvidingTraitTestParent.php @@ -0,0 +1,18 @@ +