From fdcca6fd8ea9f8c27940800fdb781665bb55963b Mon Sep 17 00:00:00 2001 From: jonathanjfshaw Date: Tue, 21 Jan 2025 12:38:33 +0000 Subject: [PATCH] snippetGenerator property change --- .../HasScenarioPassedConstraint.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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)) {