From 69b75457f49a08c7554020b6e41329232f300754 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Mon, 17 Feb 2025 00:26:59 +0100 Subject: [PATCH 1/3] Support PHPUnit 12 (#6826) --- composer.json | 14 +++++++------- src/Codeception/Test/Cest.php | 11 +++++++++++ src/Codeception/Test/Feature/CodeCoverage.php | 8 ++++++++ src/Codeception/Test/TestCaseWrapper.php | 11 +++++++++++ tests/data/claypit/tests/order/CodeTest.php | 4 ++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index d462bd24c0..2df065bcb2 100644 --- a/composer.json +++ b/composer.json @@ -22,12 +22,12 @@ "behat/gherkin": "^4.6.2", "codeception/lib-asserts": "^2.0", "codeception/stub": "^4.1", - "phpunit/phpunit": "^9.5.20 || ^10.0 || ^11.0", - "phpunit/php-code-coverage": "^9.2 || ^10.0 || ^11.0", - "phpunit/php-text-template": "^2.0 || ^3.0 || ^4.0", - "phpunit/php-timer": "^5.0.3 || ^6.0 || ^7.0", - "sebastian/comparator": "^4.0.5 || ^5.0 || ^6.0", - "sebastian/diff": "^4.0.3 || ^5.0 || ^6.0", + "phpunit/phpunit": "^9.5.20 || ^10.0 || ^11.0 || ^12.0", + "phpunit/php-code-coverage": "^9.2 || ^10.0 || ^11.0 || ^12.0", + "phpunit/php-text-template": "^2.0 || ^3.0 || ^4.0 || ^5.0", + "phpunit/php-timer": "^5.0.3 || ^6.0 || ^7.0 || ^8.0", + "sebastian/comparator": "^4.0.5 || ^5.0 || ^6.0 || ^7.0", + "sebastian/diff": "^4.0.3 || ^5.0 || ^6.0 || ^7.0", "symfony/console": ">=5.4.24 <8.0", "symfony/css-selector": ">=5.4.24 <8.0", "symfony/event-dispatcher": ">=5.4.24 <8.0", @@ -39,7 +39,7 @@ "require-dev": { "ext-simplexml": "*", "codeception/lib-innerbrowser": "*@dev", - "codeception/lib-web": "^1.0", + "codeception/lib-web": "*@dev", "codeception/module-asserts": "*@dev", "codeception/module-cli": "*@dev", "codeception/module-db": "*@dev", diff --git a/src/Codeception/Test/Cest.php b/src/Codeception/Test/Cest.php index 9de26ff606..f71c26e487 100644 --- a/src/Codeception/Test/Cest.php +++ b/src/Codeception/Test/Cest.php @@ -21,6 +21,7 @@ use PHPUnit\Runner\Version as PHPUnitVersion; use PHPUnit\Util\Test as TestUtil; use ReflectionMethod; +use SebastianBergmann\CodeCoverage\Version as CodeCoverageVersion; use function array_slice; use function file; @@ -258,6 +259,11 @@ public function getLinesToBeCovered(): array|bool if (PHPUnitVersion::series() < 10) { return TestUtil::getLinesToBeCovered($this->testClass, $this->testMethod); } + + if (version_compare(CodeCoverageVersion::id(), '12', '>=')) { + return (new CodeCoverage())->coversTargets($this->testClass, $this->testMethod)->asArray(); + } + return (new CodeCoverage())->linesToBeCovered($this->testClass, $this->testMethod); } @@ -266,6 +272,11 @@ public function getLinesToBeUsed(): array if (PHPUnitVersion::series() < 10) { return TestUtil::getLinesToBeUsed($this->testClass, $this->testMethod); } + + if (version_compare(CodeCoverageVersion::id(), '12', '>=')) { + return (new CodeCoverage())->usesTargets($this->testClass, $this->testMethod)->asArray(); + } + return (new CodeCoverage())->linesToBeUsed($this->testClass, $this->testMethod); } } diff --git a/src/Codeception/Test/Feature/CodeCoverage.php b/src/Codeception/Test/Feature/CodeCoverage.php index 89fd60b237..6a79886b2d 100644 --- a/src/Codeception/Test/Feature/CodeCoverage.php +++ b/src/Codeception/Test/Feature/CodeCoverage.php @@ -13,7 +13,9 @@ use Codeception\Test\Test as CodeceptTest; use PHPUnit\Runner\Version as PHPUnitVersion; use SebastianBergmann\CodeCoverage\Exception as CodeCoverageException; +use SebastianBergmann\CodeCoverage\Test\Target\TargetCollection; use SebastianBergmann\CodeCoverage\Test\TestStatus\TestStatus; +use SebastianBergmann\CodeCoverage\Version as CodeCoverageVersion; trait CodeCoverage { @@ -46,6 +48,12 @@ public function codeCoverageEnd(string $status, float $time): void Test::STATUS_FAIL, Test::STATUS_ERROR => TestStatus::failure(), default => TestStatus::unknown(), }; + if (version_compare(CodeCoverageVersion::id(), '12', '>=')) { + if (is_array($linesToBeCovered)) { + $linesToBeCovered = TargetCollection::fromArray($linesToBeCovered); + } + $linesToBeUsed = TargetCollection::fromArray($linesToBeUsed); + } $codeCoverage->stop(true, $status, $linesToBeCovered, $linesToBeUsed); } } catch (CodeCoverageException $exception) { diff --git a/src/Codeception/Test/TestCaseWrapper.php b/src/Codeception/Test/TestCaseWrapper.php index e10b5984d8..8f6f7ebc79 100644 --- a/src/Codeception/Test/TestCaseWrapper.php +++ b/src/Codeception/Test/TestCaseWrapper.php @@ -19,6 +19,7 @@ use PHPUnit\Runner\Version as PHPUnitVersion; use PHPUnit\Util\Test as TestUtil; use ReflectionClass; +use SebastianBergmann\CodeCoverage\Version as CodeCoverageVersion; /** * Wrapper for TestCase tests behaving like native Codeception test format @@ -120,6 +121,11 @@ public function getLinesToBeCovered(): array|bool if (PHPUnitVersion::series() < 10) { return TestUtil::getLinesToBeCovered($class, $method); } + + if (version_compare(CodeCoverageVersion::id(), '12', '>=')) { + return (new CodeCoverage())->coversTargets($class, $method)->asArray(); + } + return (new CodeCoverage())->linesToBeCovered($class, $method); } @@ -131,6 +137,11 @@ public function getLinesToBeUsed(): array if (PHPUnitVersion::series() < 10) { return TestUtil::getLinesToBeUsed($class, $method); } + + if (version_compare(CodeCoverageVersion::id(), '12', '>=')) { + return (new CodeCoverage())->usesTargets($class, $method)->asArray(); + } + return (new CodeCoverage())->linesToBeUsed($class, $method); } diff --git a/tests/data/claypit/tests/order/CodeTest.php b/tests/data/claypit/tests/order/CodeTest.php index 2be4c589bb..7e6140a6f9 100644 --- a/tests/data/claypit/tests/order/CodeTest.php +++ b/tests/data/claypit/tests/order/CodeTest.php @@ -1,6 +1,8 @@ '); From 7df4ce208773bd0de45ef9645cd235e0a0a5e800 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 20 Feb 2025 15:17:47 +0100 Subject: [PATCH 2/3] Fix missing absolute path resolving in ParamsLoader (#6828) --- src/Codeception/Lib/ParamsLoader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Codeception/Lib/ParamsLoader.php b/src/Codeception/Lib/ParamsLoader.php index b238186ffd..8ccabf3f5b 100644 --- a/src/Codeception/Lib/ParamsLoader.php +++ b/src/Codeception/Lib/ParamsLoader.php @@ -51,14 +51,14 @@ public static function load(array|string $paramStorage): array foreach ($loaderMappings as $method => $pattern) { if (preg_match($pattern, $paramStorage)) { try { - return self::$method($paramStorage); + return self::$method($paramsFile); } catch (Exception $e) { - throw new ConfigurationException("Failed loading params from {$paramStorage}\n" . $e->getMessage()); + throw new ConfigurationException("Failed loading params from {$paramsFile}\n" . $e->getMessage()); } } } - throw new ConfigurationException("Params can't be loaded from `{$paramStorage}`."); + throw new ConfigurationException("Params can't be loaded from `{$paramFile}`."); } /** From 6e06224627dcd89e7d4753f44ba4df35034b6314 Mon Sep 17 00:00:00 2001 From: Gustavo Nieves Date: Thu, 20 Feb 2025 09:44:36 -0500 Subject: [PATCH 3/3] 5.2.1 --- CHANGELOG-5.x.md | 5 +++++ src/Codeception/Codecept.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-5.x.md b/CHANGELOG-5.x.md index 745631fbc6..f37f3609c9 100644 --- a/CHANGELOG-5.x.md +++ b/CHANGELOG-5.x.md @@ -1,3 +1,8 @@ +#### 5.2.1 + +* Support PHPUnit 12 by @W0rma in #6826 +* Fix missing absolute path resolving in ParamsLoader by @garvinhicking in #6828 + #### 5.2.0 * Fix FAIL message color highlighting by @antonvolokha in #6754 diff --git a/src/Codeception/Codecept.php b/src/Codeception/Codecept.php index 1410893291..03536fb574 100644 --- a/src/Codeception/Codecept.php +++ b/src/Codeception/Codecept.php @@ -36,7 +36,7 @@ class Codecept /** * @var string */ - public const VERSION = '5.2.0'; + public const VERSION = '5.2.1'; protected ResultAggregator $resultAggregator;