8000 Support PHPUnit 12 (#6826) · Codeception/Codeception@69b7545 · GitHub
[go: up one dir, main page]

Skip to content

Commit 69b7545

Browse files
authored
Support PHPUnit 12 (#6826)
1 parent 5f74784 commit 69b7545

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
"behat/gherkin": "^4.6.2",
2323
"codeception/lib-asserts": "^2.0",
2424
"codeception/stub": "^4.1",
25-
"phpunit/phpunit": "^9.5.20 || ^10.0 || ^11.0",
26-
"phpunit/php-code-coverage": "^9.2 || ^10.0 || ^11.0",
27-
"phpunit/php-text-template": "^2.0 || ^3.0 || ^4.0",
28-
"phpunit/php-timer": "^5.0.3 || ^6.0 || ^7.0",
29-
"sebastian/comparator": "^4.0.5 || ^5.0 || ^6.0",
30-
"sebastian/diff": "^4.0.3 || ^5.0 || ^6.0",
25+
"phpunit/phpunit": "^9.5.20 || ^10.0 || ^11.0 || ^12.0",
26+
"phpunit/php-code-coverage": "^9.2 || ^10.0 || ^11.0 || ^12.0",
27+
"phpunit/php-text-template": "^2.0 || ^3.0 || ^4.0 || ^5.0",
28+
"phpunit/php-timer": "^5.0.3 || ^6.0 || ^7.0 || ^8.0",
29+
"sebastian/comparator": "^4.0.5 || ^5.0 || ^6.0 || ^7.0",
30+
"sebastian/diff": "^4.0.3 || ^5.0 || ^6.0 || ^7.0",
3131
"symfony/console": ">=5.4.24 <8.0",
3232
"symfony/css-selector": ">=5.4.24 <8.0",
3333
"symfony/event-dispatcher": ">=5.4.24 <8.0",
@@ -39,7 +39,7 @@
3939
"require-dev": {
4040
"ext-simplexml": "*",
4141
"codeception/lib-innerbrowser": "*@dev",
42-
"codeception/lib-web": "^1.0",
42+
"codeception/lib-web": "*@dev",
4343
"codeception/module-asserts": "*@dev",
4444
"codeception/module-cli": "*@dev",
4545
"codeception/module-db": "*@dev",

src/Codeception/Test/Cest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPUnit\Runner\Version as PHPUnitVersion;
2222
use PHPUnit\Util\Test as TestUtil;
2323
use ReflectionMethod;
24+
use SebastianBergmann\CodeCoverage\Version as CodeCoverageVersion;
2425

2526
use function array_slice;
2627
use function file;
@@ -258,6 +259,11 @@ public function getLinesToBeCovered(): array|bool
258259
if (PHPUnitVersion::series() < 10) {
259260
return TestUtil::getLinesToBeCovered($this->testClass, $this->testMethod);
260261
}
262+
263+
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
264+
return (new CodeCoverage())->coversTargets($this->testClass, $this->testMethod)->asArray();
265+
}
266+
261267
return (new CodeCoverage())->linesToBeCovered($this->testClass, $this->testMethod);
262268
}
263269

@@ -266,6 +272,11 @@ public function getLinesToBeUsed(): array
266272
if (PHPUnitVersion::series() < 10) {
267273
return TestUtil::getLinesToBeUsed($this->testClass, $this->testMethod);
268274
}
275+
276+
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
277+
return (new CodeCoverage())->usesTargets($this->testClass, $this->testMethod)->asArray();
278+
}
279+
269280
return (new CodeCoverage())->linesToBeUsed($this->testClass, $this->testMethod);
270281
}
271282
}

src/Codeception/Test/Feature/CodeCoverage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use Codeception\Test\Test as CodeceptTest;
1414
use PHPUnit\Runner\Version as PHPUnitVersion;
1515
use SebastianBergmann\CodeCoverage\Exception as CodeCoverageException;
16+
use SebastianBergmann\CodeCoverage\Test\Target\TargetCollection;
1617
use SebastianBergmann\CodeCoverage\Test\TestStatus\TestStatus;
18+
use SebastianBergmann\CodeCoverage\Version as CodeCoverageVersion;
1719

1820
trait CodeCoverage
1921
{
@@ -46,6 +48,12 @@ public function codeCoverageEnd(string $status, float $time): void
4648
Test::STATUS_FAIL, Test::STATUS_ERROR => TestStatus::failure(),
4749
default => TestStatus::unknown(),
4850
};
51+
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
52+
if (is_array($linesToBeCovered)) {
53+
$linesToBeCovered = TargetCollection::fromArray($linesToBeCovered);
54+
}
55+
$linesToBeUsed = TargetCollection::fromArray($linesToBeUsed);
56+
}
4957
$codeCoverage->stop(true, $status, $linesToBeCovered, $linesToBeUsed);
5058
}
5159
} catch (CodeCoverageException $exception) {

src/Codeception/Test/TestCaseWrapper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Runner\Version as PHPUnitVersion;
2020
use PHPUnit\Util\Test as TestUtil;
2121
use ReflectionClass;
22+
use SebastianBergmann\CodeCoverage\Version as CodeCoverageVersion;
2223

2324
/**
2425
* Wrapper for TestCase tests behaving like native Codeception test format
@@ -120,6 +121,11 @@ public function getLinesToBeCovered(): array|bool
120121
if (PHPUnitVersion::series() < 10) {
121122
return TestUtil::getLinesToBeCovered($class, $method);
122123
}
124+
125+
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
126+
return (new CodeCoverage())->coversTargets($class, $method)->asArray();
127+
}
128+
123129
return (new CodeCoverage())->linesToBeCovered($class, $method);
124130
}
125131

@@ -131,6 +137,11 @@ public function getLinesToBeUsed(): array
131137
if (PHPUnitVersion::series() < 10) {
132138
return TestUtil::getLinesToBeUsed($class, $method);
133139
}
140+
141+
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
142+
return (new CodeCoverage())->usesTargets($class, $method)->asArray();
143+
}
144+
134145
return (new CodeCoverage())->linesToBeUsed($class, $method);
135146
}
136147

tests/data/claypit/tests/order/CodeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
use Codeception\Module\OrderHelper;
4+
use PHPUnit\Framework\Attributes\After;
5+
use PHPUnit\Framework\Attributes\Before;
46

57
class CodeTest extends \Codeception\Test\Unit
68
{
@@ -22,6 +24,7 @@ public static function _tearDownAfterClass()
2224
/**
2325
* @before
2426
*/
27+
#[Before]
2528
public function before()
2629
{
2730
OrderHelper::appendToFile('<');
@@ -30,6 +33,7 @@ public function before()
3033
/**
3134
* @after
3235
*/
36+
#[After]
3337
public function after()
3438
{
3539
OrderHelper::appendToFile('>');

0 commit comments

Comments
 (0)
0