From 4060948aa629a30bc9a44fed5fe3704c11034f96 Mon Sep 17 00:00:00 2001 From: victor-aston Date: Tue, 19 Nov 2024 13:31:31 +0200 Subject: [PATCH] Support PhpUnit 10 and Symfony 7 (#16) * #1118: Added PhpUnit 10 and Symfony 7 requirements for composer.json. Updated CI tests to test PHPUnit 10 version for latest PHP 8.x versions. * 1118 - Add new property * 1118 - Add new property * 1118 - Add new property * 1118 - Add new property * 1118 - Add new property --------- Co-authored-by: Yevhen Korniievskyi Co-authored-by: AstonVictor --- .github/workflows/ci.yml | 6 ++++++ composer.json | 4 ++-- .../Testwork/Environment/PHPUnitEnvironment.php | 10 ++++++++++ .../Constraint/HasScenarioPassedConstraint.php | 7 +++++++ src/TestTraits/BehatProvidingTrait.php | 16 ++++++++++++++-- tests/AssertionFailedWrapperErrorTest.php | 2 +- 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32d94d0..55ff60e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,12 @@ jobs: php: 8.0 - phpunit: 9.5.26 php: 8.1 + - phpunit: 10.5.38 + php: 8.1 + - phpunit: 10.5.38 + php: 8.2 + - phpunit: 10.5.38 + php: 8.3 steps: - uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index ab287a1..fdb8936 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,9 @@ ], "require": { "php": "^7.0 || ^8.0", - "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10", "behat/behat": "^3.0.0", - "symfony/dependency-injection": "^4.0 || ^5.0 || ^6.0" + "symfony/dependency-injection": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { diff --git a/src/Behat/Testwork/Environment/PHPUnitEnvironment.php b/src/Behat/Testwork/Environment/PHPUnitEnvironment.php index 9260f1d..a358f4d 100644 --- a/src/Behat/Testwork/Environment/PHPUnitEnvironment.php +++ b/src/Behat/Testwork/Environment/PHPUnitEnvironment.php @@ -34,6 +34,16 @@ class PHPUnitEnvironment implements ContextEnvironment */ protected $contextClasses = array(); + /** + * @var Suite + */ + protected $suite; + + /** + * @var TestCase + */ + protected $testCase; + /** * Specifies the current PhpUnit test case. * diff --git a/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php b/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php index 8f09e04..62d1223 100644 --- a/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php +++ b/src/PHPUnit/Framework/Constraint/HasScenarioPassedConstraint.php @@ -16,6 +16,13 @@ class HasScenarioPassedConstraint extends Constraint { + /** + * The behat environment. + * + * @var \PHPUnitBehat\Behat\Testwork\Environment\PHPUnitEnvironment + */ + protected $environment; + /** * The behat scenario. * diff --git a/src/TestTraits/BehatProvidingTrait.php b/src/TestTraits/BehatProvidingTrait.php index a2e376a..5f7ca20 100644 --- a/src/TestTraits/BehatProvidingTrait.php +++ b/src/TestTraits/BehatProvidingTrait.php @@ -108,7 +108,13 @@ public function getBehatDefaultKeywords() { * @return \Behat\Gherkin\Node\KeywordNodeInterface */ protected function getProvidedFeature() { - $data = $this->getProvidedData(); + $data = NULL; + if (method_exists($this, 'getProvidedData')) { + $data = $this->getProvidedData(); + } + elseif (method_exists($this, 'providedData')) { + $data = $this->providedData(); + } if (is_array($data) && $feature = $data[1]) { if ($feature instanceof KeywordNodeInterface) { return $feature; @@ -128,7 +134,13 @@ protected function getProvidedFeature() { * The current scenario or example. */ protected function getProvidedScenario() { - $data = $this->getProvidedData(); + $data = NULL; + if (method_exists($this, 'getProvidedData')) { + $data = $this->getProvidedData(); + } + elseif (method_exists($this, 'providedData')) { + $data = $this->providedData(); + } if (is_array($data) && $scenario = $data[0]) { if ($scenario instanceof ScenarioInterface) { return $scenario; diff --git a/tests/AssertionFailedWrapperErrorTest.php b/tests/AssertionFailedWrapperErrorTest.php index b391951..c4a9ac4 100644 --- a/tests/AssertionFailedWrapperErrorTest.php +++ b/tests/AssertionFailedWrapperErrorTest.php @@ -8,7 +8,7 @@ /** * */ -class AssertionFailedWrappedErrorTest extends TestCase { +class AssertionFailedWrapperErrorTest extends TestCase { use TestDefinitionsTrait;