Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:

- name: Check test code style
run: composer cs-tests

- run: ./codecept build
- name: PHPStan
run: phpstan analyse src
run: phpstan

linux:
name: PHP ${{ matrix.php }}–${{ matrix.os }}–${{ matrix.mode }}
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"ext-json": "*",
"ext-mbstring": "*",
"behat/gherkin": "^4.12",
"codeception/lib-asserts": "^2.2",
"codeception/lib-asserts": "^3",
"codeception/stub": "^4.1",
"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",
"phpunit/phpunit": "^9.5.20 | ^10.0 | ^11.0 | ^12.0",
"phpunit/phpunit": "^11.0 | ^12.0",
"psy/psysh": "^0.11.2 | ^0.12",
"sebastian/comparator": "^4.0.5 | ^5.0 | ^6.0 | ^7.0",
"sebastian/diff": "^4.0.3 | ^5.0 | ^6.0 | ^7.0",
Expand Down Expand Up @@ -55,11 +55,13 @@
"symfony/dotenv": ">=5.4.24 <8.0",
"symfony/error-handler": ">=5.4.24 <8.0",
"symfony/process": ">=5.4.24 <8.0",
"vlucas/phpdotenv": "^5.1"
"vlucas/phpdotenv": "^5.1",
"phpstan/phpstan": "^2.1"
},
"conflict": {
"codeception/lib-innerbrowser": "<3.1.3",
"codeception/module-phpbrowser": "<2.5",
"codeception/lib-web": "<2",
"codeception/module-phpbrowser": "<3.0.2",
"codeception/module-filesystem": "<3.0"
},
"suggest": {
Expand Down
13 changes: 5 additions & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ parameters:

paths:
- src

- tests
excludePaths:
analyseAndScan:
- src/Codeception/Test/Cest.php
- src/Codeception/Test/Test.php
- src/Codeception/Test/Unit.php
- src/Codeception/Coverage/Subscriber/Printer.php
- src/PHPUnit/Wrapper/PhpUnit9/Test.php

- tests/data
parallel:
maximumNumberOfProcesses: 8
minimumNumberOfJobsPerProcess: 2
jobSize: 20
ignoreErrors:
- message: '#^Variable \$scenario might not be defined.#'
path: tests
8 changes: 2 additions & 6 deletions src/Codeception/Coverage/Subscriber/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,11 @@ protected function printPHPUnit(): void
private function createHtmlFacadeWriter(): HtmlFacadeReport
{
$generator = ', <a href="https://codeception.com">Codeception</a> and <a href="https://phpunit.de/">PHPUnit {PHPUnitVersion::id()}</a>';
return PHPUnitVersion::series() < 10 ?
new HtmlFacadeReport($this->settings['low_limit'], $this->settings['high_limit'], $generator) :
new HtmlFacadeReport($generator, null, Thresholds::from($this->settings['low_limit'], $this->settings['high_limit']));
return new HtmlFacadeReport($generator, null, Thresholds::from($this->settings['low_limit'], $this->settings['high_limit']));
}

private function createTextWriter(): TextReport
{
return PHPUnitVersion::series() < 10 ?
new TextReport($this->settings['low_limit'], $this->settings['high_limit'], $this->settings['show_uncovered'], $this->settings['show_only_summary']) :
new TextReport(Thresholds::from($this->settings['low_limit'], $this->settings['high_limit']), $this->settings['show_uncovered'], $this->settings['show_only_summary']);
return new TextReport(Thresholds::from($this->settings['low_limit'], $this->settings['high_limit']), $this->settings['show_uncovered'], $this->settings['show_only_summary']);
}
}
2 changes: 1 addition & 1 deletion src/Codeception/Coverage/SuiteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function applySettings(array $settings): void
{
try {
$this->coverage = PhpCodeCoverageFactory::build();
} catch (CodeCoverageException $e) {
} catch (\Exception $e) {
throw new Exception(
'XDebug is required to collect CodeCoverage. Please install xdebug extension and enable it in php.ini',
$e->getCode(),
Expand Down
11 changes: 1 addition & 10 deletions src/Codeception/Reporter/JUnitReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ private function getTestOutput(Test $test): string
if (!$testCase->expectsOutput()) {
$testOutput = $testCase->getActualOutputForAssertion();
}
} elseif (!$testCase->hasExpectationOnOutput()) {
$testOutput = $testCase->getActualOutputForAssertion();
}
}

Expand Down Expand Up @@ -318,14 +316,7 @@ private function addFault(Test $test, Throwable $t, string $type): void
$buffer = '';
}

if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(TestFailure::class)
) {
$exceptionString = TestFailure::exceptionToString($t);
} else {
$exceptionString = ThrowableToStringMapper::map($t);
}
$exceptionString = ThrowableToStringMapper::map($t);

$buffer .= $exceptionString . "\n" . StackTraceFilter::getFilteredStacktrace($t);

Expand Down
6 changes: 0 additions & 6 deletions src/Codeception/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ public function comment(string $comment): void

public function skip(string $message = ''): void
{
if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(SkippedTestError::class)
) {
throw new SkippedTestError($message);
}
throw new SkippedWithMessageException($message);
}

Expand Down
13 changes: 1 addition & 12 deletions src/Codeception/Step/Skip.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,13 @@

use Codeception\Lib\ModuleContainer;
use Codeception\Step as CodeceptionStep;
use PHPUnit\Framework\SkippedTestError;
use PHPUnit\Framework\SkippedWithMessageException;
use PHPUnit\Runner\Version as PHPUnitVersion;

class Skip extends CodeceptionStep
{
public function run(?ModuleContainer $container = null): void
{
$skipMessage = $this->getAction();

if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(SkippedTestError::class)
) {
throw new SkippedTestError($skipMessage);
}

throw new SkippedWithMessageException($skipMessage);
throw new SkippedWithMessageException($this->getAction());
}

public function __toString(): string
Expand Down
16 changes: 0 additions & 16 deletions src/Codeception/Subscriber/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,6 @@ public function errorHandler(int $errNum, string $errMsg, string $errFile, int $
return false;
}

if (version_compare(PHPUnitVersion::series(), '10.0', '<')) {
$map = [
E_DEPRECATED => 'PHPUnit\Framework\Error\Deprecated',
E_USER_DEPRECATED => 'PHPUnit\Framework\Error\Deprecated',
E_NOTICE => 'PHPUnit\Framework\Error\Notice',
E_USER_NOTICE => 'PHPUnit\Framework\Error\Notice',
E_WARNING => 'PHPUnit\Framework\Error\Warning',
E_USER_WARNING => 'PHPUnit\Framework\Error\Warning',
];
$className = $map[$errNum] ?? 'PHPUnit\Framework\Error\Error';

if (class_exists($className)) {
throw new $className($errMsg, $errNum, $errFile, $errLine);
}
}

$errMsgWithLocation = $errMsg . ' at ' . $errFile . ':' . $errLine;
throw match ($errNum) {
E_DEPRECATED, E_USER_DEPRECATED => new Deprecation($errMsgWithLocation, $errNum, $errFile, $errLine),
Expand Down
17 changes: 1 addition & 16 deletions src/Codeception/Suite.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,7 @@ public function run(ResultAggregator $result): void
$result->addTest($test);
$skip = $test->getMetadata()->getSkip();
if ($skip !== null) {
if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(SkippedTestError::class)
) {
$exception = new SkippedTestError($skip);
} else {
$exception = new SkippedWithMessageException($skip);
}
$exception = new SkippedWithMessageException($skip);
$failEvent = new FailEvent($test, $exception, 0);
$result->addSkipped($failEvent);
$this->dispatcher->dispatch($failEvent, Events::TEST_SKIPPED);
Expand All @@ -117,14 +110,6 @@ public function run(ResultAggregator $result): void
continue;
}

if ($test instanceof TestCaseWrapper) {
$testCase = $test->getTestCase();
if (PHPUnitVersion::series() < 10) {
$testCase->setBeStrictAboutChangesToGlobalState($this->beStrictAboutChangesToGlobalState);
$testCase->setBackupGlobals($this->backupGlobals);
}
}

$test->setEventDispatcher($this->dispatcher);
$test->reportUselessTests($this->reportUselessTests);
$test->collectCodeCoverage($this->collectCodeCoverage);
Expand Down
4 changes: 1 addition & 3 deletions src/Codeception/SuiteManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ protected function createSuite(string $name): Suite
$suite->beStrictAboutChangesToGlobalState(!empty($this->settings['be_strict_about_changes_to_global_state']));
$suite->disallowTestOutput(!empty($this->settings['disallow_test_output']));

if (PHPUnitVersion::series() >= 10) {
$suite->initPHPUnitConfiguration();
}
$suite->initPHPUnitConfiguration();

return $suite;
}
Expand Down
9 changes: 0 additions & 9 deletions src/Codeception/Test/Cest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,14 @@ public function fetchDependencies(): array

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);
}

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();
}
Expand Down
32 changes: 14 additions & 18 deletions src/Codeception/Test/Feature/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,22 @@ public function codeCoverageEnd(string $status, float $time): void
}

try {
if (PHPUnitVersion::series() < 10) {
$codeCoverage->stop(true, $linesToBeCovered, $linesToBeUsed);
} else {
$status = match ($status) {
Test::STATUS_OK => TestStatus::success(),
Test::STATUS_FAIL, Test::STATUS_ERROR => TestStatus::failure(),
default => TestStatus::unknown(),
};
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
$tcClass = 'SebastianBergmann\CodeCoverage\Test\Target\TargetCollection';
if (
class_exists($tcClass)
&& method_exists($tcClass, 'fromArray')
) {
$linesToBeCovered = $tcClass::fromArray($linesToBeCovered);
$linesToBeUsed = $tcClass::fromArray($linesToBeUsed);
}
$status = match ($status) {
Test::STATUS_OK => TestStatus::success(),
Test::STATUS_FAIL, Test::STATUS_ERROR => TestStatus::failure(),
default => TestStatus::unknown(),
};
if (version_compare(CodeCoverageVersion::id(), '12', '>=')) {
$tcClass = 'SebastianBergmann\CodeCoverage\Test\Target\TargetCollection';
if (
class_exists($tcClass)
&& method_exists($tcClass, 'fromArray')
) {
$linesToBeCovered = $tcClass::fromArray($linesToBeCovered);
$linesToBeUsed = $tcClass::fromArray($linesToBeUsed);
}
$codeCoverage->stop(true, $status, $linesToBeCovered, $linesToBeUsed);
}
$codeCoverage->stop(true, $status, $linesToBeCovered, $linesToBeUsed);
} catch (CodeCoverageException $exception) {
if ($status === CodeceptTest::STATUS_OK) {
$this->getResultAggregator()
Expand Down
9 changes: 1 addition & 8 deletions src/Codeception/Test/Feature/IgnoreIfMetadataBlocked.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ protected function ignoreIfMetadataBlockedStart(): void

if ($this->getMetadata()->getSkip() !== null) {
$skipMessage = (string)$this->getMetadata()->getSkip();
if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(SkippedTestError::class)
) {
$skippedTestError = new SkippedTestError($skipMessage);
} else {
$skippedTestError = new SkippedWithMessageException($skipMessage);
}
$skippedTestError = new SkippedWithMessageException($skipMessage);

$this->getResultAggregator()->addFailure(new FailEvent($this, $skippedTestError, 0));
return;
Expand Down
8 changes: 2 additions & 6 deletions src/Codeception/Test/Loader/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ protected function createTestsFromPhpUnitMethod(ReflectionClass $class, Reflecti

$result = [];
foreach ($data as $key => $item) {
if (PHPUnitVersion::series() < 10) {
$testInstance = new $className($methodName, $item, $key);
} else {
$testInstance = new $className($methodName);
$testInstance->setData($key, $item);
}
$testInstance = new $className($methodName);
$testInstance->setData($key, $item);
$result [] = $testInstance;
}

Expand Down
9 changes: 2 additions & 7 deletions src/Codeception/Test/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\IncompleteTestError;
use PHPUnit\Framework\SkippedTest;
use PHPUnit\Framework\SkippedTestError;
use PHPUnit\Runner\Version as PHPUnitVersion;
use RuntimeException;
use SebastianBergmann\Timer\Timer;
Expand All @@ -28,11 +27,7 @@
use function method_exists;

// phpcs:disable
if (PHPUnitVersion::series() < 10) {
require_once __DIR__ . '/../../PHPUnit/Wrapper/PhpUnit9/Test.php';
} else {
require_once __DIR__ . '/../../PHPUnit/Wrapper/PhpUnit10/Test.php';
}
require_once __DIR__ . '/../../PHPUnit/Wrapper/PhpUnit10/Test.php';
// phpcs:enable

/**
Expand Down Expand Up @@ -164,7 +159,7 @@ final public function realRun(ResultAggregator $result): void
} catch (IncompleteTestError $e) {
$status = self::STATUS_INCOMPLETE;
$eventType = Events::TEST_INCOMPLETE;
} catch (SkippedTest | SkippedTestError $e) {
} catch (SkippedTest $e) {
$status = self::STATUS_SKIPPED;
$eventType = Events::TEST_SKIPPED;
} catch (AssertionFailedError $e) {
Expand Down
Loading
Loading