From 186bd119fb99e284e133d293ce4adc88052bd966 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Mon, 16 Nov 2026 04:58:39 +0100 Subject: [PATCH 01/24] Bump Debian version in Dockerfile (bullseye -> trixie) (#6959) --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 17f1d11817..956c86f893 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG flavor=bullseye +ARG flavor=trixie FROM php:8.2-cli-${flavor} @@ -23,7 +23,7 @@ RUN set -eux; \ # Configure php \ echo "date.timezone = UTC" >> /usr/local/etc/php/php.ini; -ENV COMPOSER_ALLOW_SUPERUSER '1' +ENV COMPOSER_ALLOW_SUPERUSER=1 WORKDIR /codecept From 1c40f1d920fe7cef7aa336c7bc0e1a97b8777e62 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 16 Nov 2026 07:15:07 +0100 Subject: [PATCH 02/24] Remove leftover debug output of --override values in config:validate --- src/Codeception/Command/ConfigValidate.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Codeception/Command/ConfigValidate.php b/src/Codeception/Command/ConfigValidate.php index 770ea63821..9fa9a2660f 100644 --- a/src/Codeception/Command/ConfigValidate.php +++ b/src/Codeception/Command/ConfigValidate.php @@ -70,7 +70,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->write("Validating global config... "); $config = $this->getGlobalConfig(); - $output->writeln($input->getOption('override')); if (!empty($input->getOption('override'))) { $config = $this->overrideConfig($input->getOption('override')); } From f36f22acb48e641f9783b0d7448b1cfa78ac8d76 Mon Sep 17 00:00:00 2001 From: "Joey@macstudio" Date: Mon, 13 Jul 2026 06:25:37 +0800 Subject: [PATCH 03/24] fix: respect CoversNothing in Cest coverage --- src/Codeception/Test/Cest.php | 6 +++ src/Codeception/Test/Feature/CodeCoverage.php | 4 ++ tests/unit/Codeception/Test/CestTest.php | 41 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/Codeception/Test/Cest.php b/src/Codeception/Test/Cest.php index 3825e106db..6d921a7519 100644 --- a/src/Codeception/Test/Cest.php +++ b/src/Codeception/Test/Cest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\IncompleteTestError; use PHPUnit\Framework\SkippedTest; use PHPUnit\Metadata\Api\CodeCoverage; +use PHPUnit\Metadata\Parser\Registry as MetadataRegistry; use PHPUnit\Runner\Version as PHPUnitVersion; use PHPUnit\Util\Test as TestUtil; use ReflectionMethod; @@ -253,6 +254,11 @@ public function getLinesToBeCovered(): array|bool return TestUtil::getLinesToBeCovered($this->testClass, $this->testMethod); } + $metadata = MetadataRegistry::parser()->forClassAndMethod($this->testClass, $this->testMethod); + if ($metadata->isCoversNothing()->isNotEmpty()) { + return false; + } + if (version_compare(CodeCoverageVersion::id(), '12', '>=')) { return (new CodeCoverage())->coversTargets($this->testClass, $this->testMethod)->asArray(); } diff --git a/src/Codeception/Test/Feature/CodeCoverage.php b/src/Codeception/Test/Feature/CodeCoverage.php index 7c3bf61a4b..3b7cee5b64 100644 --- a/src/Codeception/Test/Feature/CodeCoverage.php +++ b/src/Codeception/Test/Feature/CodeCoverage.php @@ -54,6 +54,10 @@ public function codeCoverageEnd(string $status, float $time): void class_exists($tcClass) && method_exists($tcClass, 'fromArray') ) { + if ($linesToBeCovered === false) { + $codeCoverage->stop(false, $status); + return; + } $linesToBeCovered = $tcClass::fromArray($linesToBeCovered); $linesToBeUsed = $tcClass::fromArray($linesToBeUsed); } diff --git a/tests/unit/Codeception/Test/CestTest.php b/tests/unit/Codeception/Test/CestTest.php index 57a09d8f91..57536e9e3e 100644 --- a/tests/unit/Codeception/Test/CestTest.php +++ b/tests/unit/Codeception/Test/CestTest.php @@ -6,7 +6,9 @@ use Codeception\Attribute\Group; use Codeception\Test\Cest; use Codeception\Test\Descriptor; +use Codeception\Test\Test; use Codeception\Test\Unit; +use PHPUnit\Framework\Attributes\CoversNothing; final class CestTest extends Unit { @@ -39,4 +41,43 @@ public function testCestNamings() $this->assertSame(['bootstrap'], $cest->getMetadata()->getGroups()); } + + public function testCoversNothingDisablesCodeCoverage(): void + { + $cest = new Cest(new CoversNothingCest(), 'example', __FILE__); + + $this->assertFalse($cest->getLinesToBeCovered()); + + $cest->codeCoverageStart(); + $cest->codeCoverageEnd(Test::STATUS_OK, 0.0); + } + + public function testMethodLevelCoversNothingDisablesCodeCoverage(): void + { + $cest = new Cest(new MethodCoversNothingCest(), 'withoutCoverage', __FILE__); + $ordinaryCest = new Cest(new MethodCoversNothingCest(), 'withCoverage', __FILE__); + + $this->assertFalse($cest->getLinesToBeCovered()); + $this->assertSame([], $ordinaryCest->getLinesToBeCovered()); + } +} + +#[CoversNothing] +final class CoversNothingCest +{ + public function example(): void + { + } +} + +final class MethodCoversNothingCest +{ + #[CoversNothing] + public function withoutCoverage(): void + { + } + + public function withCoverage(): void + { + } } From d1262b6cb334ef503672cd69adb7d853ec1674b4 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 16 Nov 2026 14:09:53 +0100 Subject: [PATCH 04/24] test: verify CoversNothing Cests are excluded from collected coverage Replace the sentinel-only checks with a test that runs Cests through the real coverage start/end path and asserts via getTests() that class- and method-level #[CoversNothing] Cests are not recorded, with an ordinary Cest as positive control. The test is skipped when no coverage driver is available and resets the shared coverage instance afterwards. --- tests/unit/Codeception/Test/CestTest.php | 58 +++++++++++++++++------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/tests/unit/Codeception/Test/CestTest.php b/tests/unit/Codeception/Test/CestTest.php index 57536e9e3e..22573bbe1f 100644 --- a/tests/unit/Codeception/Test/CestTest.php +++ b/tests/unit/Codeception/Test/CestTest.php @@ -4,11 +4,13 @@ use Tests\Support\CodeTester; use Codeception\Attribute\Group; +use Codeception\Coverage\PhpCodeCoverageFactory; use Codeception\Test\Cest; use Codeception\Test\Descriptor; use Codeception\Test\Test; use Codeception\Test\Unit; use PHPUnit\Framework\Attributes\CoversNothing; +use SebastianBergmann\CodeCoverage\Exception as CodeCoverageException; final class CestTest extends Unit { @@ -42,42 +44,66 @@ public function testCestNamings() $this->assertSame(['bootstrap'], $cest->getMetadata()->getGroups()); } - public function testCoversNothingDisablesCodeCoverage(): void + public function testCoversNothingIsReportedAsCoverageTargetSentinel(): void { - $cest = new Cest(new CoversNothingCest(), 'example', __FILE__); - - $this->assertFalse($cest->getLinesToBeCovered()); - - $cest->codeCoverageStart(); - $cest->codeCoverageEnd(Test::STATUS_OK, 0.0); + $this->assertFalse((new Cest(new CoversNothingCest(), 'example', __FILE__))->getLinesToBeCovered()); + $this->assertFalse((new Cest(new MethodCoversNothingCest(), 'withoutCoverage', __FILE__))->getLinesToBeCovered()); + $this->assertSame([], (new Cest(new MethodCoversNothingCest(), 'withCoverage', __FILE__))->getLinesToBeCovered()); } - public function testMethodLevelCoversNothingDisablesCodeCoverage(): void + public function testCoversNothingCestDoesNotContributeToCodeCoverage(): void { - $cest = new Cest(new MethodCoversNothingCest(), 'withoutCoverage', __FILE__); - $ordinaryCest = new Cest(new MethodCoversNothingCest(), 'withCoverage', __FILE__); - - $this->assertFalse($cest->getLinesToBeCovered()); - $this->assertSame([], $ordinaryCest->getLinesToBeCovered()); + try { + $coverage = PhpCodeCoverageFactory::build(); + } catch (CodeCoverageException $e) { + $this->markTestSkipped('No code coverage driver available: ' . $e->getMessage()); + } + + $classLevel = new Cest(new CoversNothingCest(), 'example', __FILE__); + $methodLevel = new Cest(new MethodCoversNothingCest(), 'withoutCoverage', __FILE__); + $ordinary = new Cest(new MethodCoversNothingCest(), 'withCoverage', __FILE__); + + try { + foreach ([$classLevel, $methodLevel, $ordinary] as $cest) { + $cest->codeCoverageStart(); + $cest->getTestInstance()->{$cest->getTestMethod()}(); + $cest->codeCoverageEnd(Test::STATUS_OK, 0.0); + } + + $recordedTests = $coverage->getTests(); + } finally { + PhpCodeCoverageFactory::clear(); + } + + $this->assertArrayNotHasKey(Descriptor::getTestSignature($classLevel), $recordedTests); + $this->assertArrayNotHasKey(Descriptor::getTestSignature($methodLevel), $recordedTests); + $this->assertArrayHasKey( + Descriptor::getTestSignature($ordinary), + $recordedTests, + 'Control: a Cest without #[CoversNothing] must be recorded, otherwise the assertions above prove nothing' + ); } } #[CoversNothing] final class CoversNothingCest { - public function example(): void + public function example(): int { + return strlen('covered?'); } } final class MethodCoversNothingCest { #[CoversNothing] - public function withoutCoverage(): void + public function withoutCoverage(): int { + return strlen('covered?'); } - public function withCoverage(): void + public function withCoverage(): int { + return strlen('covered?'); } } From 51dee86d622b9b60aba414acb60f52518a73a608 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Tue, 17 Nov 2026 14:48:37 +0100 Subject: [PATCH 05/24] Update contributor docs and Docker test setup (#6962) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The contributor docs were largely outdated since 4.0 (module tests, web suite, MongoDB, `master` branch, …) and the Docker setup for running the internal tests didn't work. --- CONTRIBUTING.md | 15 ++- readme.md | 4 +- tests/README.md | 202 +++++++++++---------------------------- tests/compose.yaml | 22 +++++ tests/docker-compose.yml | 13 --- 5 files changed, 90 insertions(+), 166 deletions(-) create mode 100644 tests/compose.yaml delete mode 100644 tests/docker-compose.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7366301d5..61760608f5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,16 +2,21 @@ At Codeception we are glad to receive contributions and patches from the community. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. -Please check the guide for sending your contributions with Github at -https://github.com/Codeception/Codeception/wiki/Git-workflow-for-Codeception-contributors +1. [Fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) the repository, clone your fork and add the main repository as `upstream` remote: + `git remote add upstream git@github.com:Codeception/Codeception.git` +2. Before starting new work, update your local `main`: `git pull upstream main` +3. Create a new branch based on `main` for each bug fix or feature +4. Make your changes and add tests for them (see [Tests](#tests)) +5. Push the branch to your fork and open a pull request against `main`. Each pull request should contain a single change. + +Bigger changes should have an issue, so they can be discussed before you spend time on them. If there already is one, leave a comment that you are working on it. Small changes and documentation fixes don't need an issue. ## Coding Standards All contributions must follow [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standard. +Check it with `composer cs-prod` and `composer cs-tests` before sending a pull request. ## Code -**Bugfixes should be sent to the current stable branch, which is the same as major version number.** - -Breaking features and major improvements should be sent into `master`. When you send PRs to master, they will be added to release cycle only when the next stable branch is started. +**All pull requests should be sent to the `main` branch.** ## Tests diff --git a/readme.md b/readme.md index 9c4d3a79c0..3529d70dc3 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ Inspired by BDD, it provides an absolutely new way of writing acceptance, functi #### Contributions -At Codeception we are glad to receive contributions from the community. If you want to send additions or fixes to the code or the documentation please check the [Contributing guide](https://github.com/Codeception/Codeception/blob/5.0.0/CONTRIBUTING.md). +At Codeception we are glad to receive contributions from the community. If you want to send additions or fixes to the code or the documentation please check the [Contributing guide](https://github.com/Codeception/Codeception/blob/main/CONTRIBUTING.md). ### At a Glance @@ -92,4 +92,4 @@ This will create a default directory structure and default test suites. The documentation source files can be found at https://github.com/Codeception/codeception.github.com/tree/master/docs/. ## License -[MIT](https://github.com/Codeception/Codeception/blob/master/LICENSE) +[MIT](https://github.com/Codeception/Codeception/blob/main/LICENSE) diff --git a/tests/README.md b/tests/README.md index 2f59ce591d..af80b6bf44 100644 --- a/tests/README.md +++ b/tests/README.md @@ -8,111 +8,54 @@ There are 3 suites for testing * coverage - acceptance tests of code coverage * unit - all unit/integration/etc tests. +Tests of the modules (PhpBrowser, WebDriver, Db, REST, ...) are not part of this repository. +They live in the repository of each module, e.g. [module-phpbrowser](https://github.com/Codeception/module-phpbrowser). + ## Set up -1. Clone the repository to your local machine -1. Make sure you have the MongoDB extension enabled. It's not included in PHP by default, you can download it from https://pecl.php.net/package/mongodb -1. Run `composer install` in the cloned project directory -To run the web tests: -1. Start PHP's internal webserver in the project directory: +1. Clone the repository to your local machine +2. Run `composer install` in the cloned project directory +3. Generate the actor classes: ``` - php -S 127.0.0.1:8008 -t tests/data/app + php codecept build ``` -1. Start Selenium server -1. Run: +4. Some tests need the demo application. Start PHP's internal webserver in the project directory: ``` - php codecept run web --env chrome + php -S 127.0.0.1:8008 -t tests/data/app ``` -## Unit - -The most important tests in this suite are Module tests located in `test/unit/Codeception/Module`. Unlike you would expect, most of tests there are integrational tests. For example, `WebDriverTest` requires an actual Selenium Server to be running. - -### Testing a Module +The coverage suite additionally requires [Xdebug](https://xdebug.org/) or [PCOV](https://github.com/krakjoe/pcov). -These are basic steps if you want to add a test for a module: +## Running tests -1. Find corresponding module test in `tests/unit/Codeception/Module` -2. Start web server or selenium server if needed -3. Write a test -4. Execute only that test. **Do not start all test suite** - -Requirements: - -* PhpBrowser - demo application running on web server -* WebDriver, Selenium2 - demo application on web server + selenium server -* Frameworks (general all-framework tests) - demo application -* MongoDb, AMQP, etc - corresponding backends - -### Demo Application - -When a module requires a web server with the demo application running, you can find this app in `tests/data/app`. To execute tests for **PhpBrowser** or **WebDriver** you need to start a web server for this dir: +Run all suites like the CI does: ``` -php -S 127.0.0.1:8008 -t tests/data/app +php codecept run cli,unit,coverage ``` -If you run `FrameworkTest` for various frameworks, you don't need a web server running. - -It is a very basic PHP application developed with `glue` microframework. To add a new html page for a test: - -1. Create a new file in `tests/data/app/view` -1. Add a route in `tests/data/app/index.php` -1. Add a class in `tests/data/app/controllers.php` - -To see the page in the browser, open `http://localhost:8008/your-route` - -Then create a test in `tests/web/WebDriverTest.php`, and run it with `php codecept run web WebDriverTest::yourTest --env chrome` +Run a suite, a directory or a single test: -### How to write module tests - -Learn by examples! There are pretty much other tests already written. Please follow their structure. - -By default you are supposed to access module methods via `module` property. - -```php -module->amOnPage('/form/checkbox'); -$this->module->appendField('form input[name=terms]', 'I Agree123'); -?> +``` +php codecept run cli +php codecept run unit Codeception/Command +php codecept run cli ExtensionsCest ``` -To verify that form was submitted correctly you can use `data::get` method. - -Example: +Before sending a pull request, check the code style: -```php -module->amOnPage('/form/complex'); - $this->module->submitForm('form', array( - 'password' => '123456' - )); - $form = data::get('form'); - $this->assertSame('123456', $form['password']); -} -?> +``` +composer cs-prod +composer cs-tests ``` -There is also a convention to use `shouldFail` method to set expected fail. +## Unit -```php -setExpectedException('PHPUnit_Framework_AssertionFailedError'); -} - -public function testAppendFieldRadioButtonByValueFails() -{ - $this->shouldFail(); - $this->module->amOnPage('/form/radio'); - $this->module->appendField('form input[name=terms]','disagree123'); -} +Unit tests are located in `tests/unit` and follow the directory structure of `src`, e.g. the tests for `src/Codeception/Util/Annotation.php` are in `tests/unit/Codeception/Util/AnnotationTest.php`. -?> -``` +They are PHPUnit tests, most of them extend `Codeception\Test\Unit` or `Codeception\PHPUnit\TestCase`. + +Tests of console commands extend `BaseCommandRunner` (`tests/unit/Codeception/Command/BaseCommandRunner.php`), which executes a command, collects its output and records the files the command would create instead of writing them. ## Cli @@ -120,12 +63,10 @@ For most cases Codeception is self-tested using acceptance tests in *cli* suite. If you send Pull Request to Codeception core and you don't know how to get it tested, just create new cli test for that. Probably you will need some additional files, maybe another suite configurations, so add them. -That is why Codeception can't have code coverage reports, as we rely on acceptance tests in testing core. - You can run all cli tests with ``` -codecept run cli +php codecept run cli ``` Test cases are: @@ -156,83 +97,52 @@ $I->seeInThisFile('seeFileFound('); There are various test suites in `tests/data/claypit`. Maybe you will need to create a new suite for your tests. -## Coverage - -Acceptance tests that use demo application and `c3` collector, to check that a code coverage can be collected remotely. This tests are rarely updated, they should just work ) - ---- - -## Dockerized testing - -### Local testing and development with `docker-compose` - -Using `docker-compose` for test configurations - - cd tests - -Build the `codeception/codeception` image - - docker-compose build - -Start - - docker-compose up -d - -By default the image has `codecept` as its entrypoint, to run the tests simply supply the `run` command - - docker-compose run --rm codecept help +### Demo Application -Run suite +Some suites in `tests/data/claypit` (e.g. `remote`) send requests to the demo application in `tests/data/app`, which has to be running on `http://127.0.0.1:8008` (see [Set up](#set-up)). - docker-compose run --rm codecept run cli +It is a very basic PHP application developed with `glue` microframework. To add a new html page for a test: -Run folder +1. Create a new file in `tests/data/app/view` +2. Add a route in `tests/data/app/index.php` +3. Add a class in `tests/data/app/controllers.php` - docker-compose run --rm codecept run unit Codeception/Command +To see the page in the browser, open `http://127.0.0.1:8008/your-route` -Run single test +## Coverage - docker-compose run --rm codecept run cli ExtensionsCest +Acceptance tests that use demo application and `c3` collector, to check that a code coverage can be collected remotely. This tests are rarely updated, they should just work ) -Development bash +--- - docker-compose run --rm --entrypoint bash codecept +## Running tests with Docker -Cleanup +If you don't want to install PHP locally, you can run the tests in a container with [`tests/compose.yaml`](compose.yaml). +It uses the official `composer` image with Xdebug added, mounts the repository and starts the demo application in the background. +The container runs as user and group 1000, set `UID` and `GID` if your ids differ: - docker-compose run --rm codecept clean + export UID GID=$(id -g) -In parallel +Install the dependencies and generate the actor classes - docker-compose --project-name test-cli run -d --rm codecept run --html report-cli.html cli & \ - docker-compose --project-name test-unit-command run -d --rm codecept run --html report-unit-command.html unit Codeception/Command & \ - docker-compose --project-name test-unit-constraints run -d --rm codecept run --html report-unit-constraints.html unit Codeception/Constraints + docker compose -f tests/compose.yaml run --rm php composer install + docker compose -f tests/compose.yaml run --rm php php codecept build -### Adding services +Run the cli and unit suites, except the tests which require code coverage -Add Redis to `docker-compose.yml` + docker compose -f tests/compose.yaml run --rm php - services: - [...] - redis: - image: redis:3 +Run a folder or a single test -Update `host` + docker compose -f tests/compose.yaml run --rm php php codecept run unit Codeception/Command + docker compose -f tests/compose.yaml run --rm php php codecept run cli ExtensionsCest - protected static $config = [ - 'database' => 15, - 'host' => 'redis' - ]; +Open a shell -Run Redis tests + docker compose -f tests/compose.yaml run --rm php sh - docker-compose run --rm codecept run unit Codeception/Module/RedisTest +Run all suites including the tests which require code coverage (Xdebug is disabled by default, as it slows down the tests) -Further Examples + docker compose -f tests/compose.yaml run --rm -e XDEBUG_MODE=coverage php php codecept run cli,unit,coverage - firefox: - image: selenium/standalone-firefox-debug:2.52.0 - chrome: - image: selenium/standalone-chrome-debug:2.52.0 - mongo: - image: mongo +Note: the `Dockerfile` in the root of the repository builds the `codeception/codeception` image for running *your* tests, it is not meant for developing Codeception. diff --git a/tests/compose.yaml b/tests/compose.yaml new file mode 100644 index 0000000000..e6e1232994 --- /dev/null +++ b/tests/compose.yaml @@ -0,0 +1,22 @@ +# Runs the internal test suite in a container, see tests/README.md +services: + php: + build: + # Xdebug is required by the coverage suite + dockerfile_inline: | + FROM composer:2 + COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ + RUN install-php-extensions xdebug + # run as the host user, so that files created in the repository are not owned by root + user: "${UID:-1000}:${GID:-1000}" + working_dir: /repo + environment: + COMPOSER_HOME: /tmp/composer + # coverage is only collected when requested with `-e XDEBUG_MODE=coverage`, which also applies to the demo application + XDEBUG_MODE: "off" + volumes: + - ..:/repo + # start the demo application which is required by some tests, then run the given command + entrypoint: ["sh", "-c", "php -S 127.0.0.1:8008 -t tests/data/app >/dev/null 2>&1 & exec \"$$@\"", "--"] + # tests of the coverage group need Xdebug, which is disabled by default + command: ["php", "codecept", "run", "cli,unit", "--skip-group", "coverage"] diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml deleted file mode 100644 index 372a7f548a..0000000000 --- a/tests/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '2' -services: - codecept: - image: testing/codeception/codeception - build: .. - working_dir: /repo - volumes: - - ../tests:/repo/tests - - ../codeception.yml:/repo/codeception.yml - - ../src:/repo/src - - ../shim.php:/repo/shim.php - #redis: - # image: redis:3 From aa2b1e535da38079e460814a253eedaafa1e703e Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Tue, 17 Nov 2026 22:23:51 +0100 Subject: [PATCH 06/24] Build codecept.phar with Box and attach it to GitHub releases (#6960) * Build codecept.phar with Box and attach it to GitHub releases The phar is built by phar/build.sh from `git archive `, bundled with the same modules as the Robo build in codeception.github.com. The workflow runs on published releases and via workflow_dispatch for backfills. --- .gitattributes | 1 + .github/workflows/phar.yml | 61 ++++++++++++++++++++++++++++++++++ phar/.gitignore | 1 + phar/box.json | 67 ++++++++++++++++++++++++++++++++++++++ phar/build.sh | 39 ++++++++++++++++++++++ phar/composer.json | 30 +++++++++++++++++ phar/stub.php | 7 ++++ 7 files changed, 206 insertions(+) create mode 100644 .github/workflows/phar.yml create mode 100644 phar/.gitignore create mode 100644 phar/box.json create mode 100755 phar/build.sh create mode 100644 phar/composer.json create mode 100644 phar/stub.php diff --git a/.gitattributes b/.gitattributes index 4e91495f08..3cbf05f55d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -45,3 +45,4 @@ /Dockerfile export-ignore /nitpick.json export-ignore /ruleset.xml export-ignore +/phar export-ignore diff --git a/.github/workflows/phar.yml b/.github/workflows/phar.yml new file mode 100644 index 0000000000..d097841ebd --- /dev/null +++ b/.github/workflows/phar.yml @@ -0,0 +1,61 @@ +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: 'Release tag to build the phar for, e.g. 5.3.7' + required: true + +name: phar + +concurrency: + group: phar-${{ github.event.release.tag_name || inputs.tag }} + +permissions: + contents: write + +jobs: + phar: + name: Build and upload codecept.phar + runs-on: ubuntu-latest + env: + TAG: ${{ github.event.release.tag_name || inputs.tag }} + steps: + # build.sh and box.json come from the checked out ref: the release tag for release events, the selected + # branch for workflow_dispatch. Use workflow_dispatch to rebuild a release with a fixed build config. + # The Codeception sources always come from the tag. + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + ini-values: phar.readonly=0, memory_limit=-1 + tools: composer:v2 + + - name: Build phar + run: phar/build.sh "$TAG" + + - name: Smoke test + working-directory: ${{ runner.temp }} + run: | + mkdir smoke && cd smoke + cp "$GITHUB_WORKSPACE/phar/build/codecept.phar" . + php codecept.phar --version + php codecept.phar bootstrap --no-interaction + php codecept.phar build + php codecept.phar run + + - name: Create checksum + working-directory: phar/build + run: sha256sum codecept.phar > codecept.phar.sha256 + + - name: Upload to release + working-directory: phar/build + env: + GH_TOKEN: ${{ github.token }} + run: gh release upload "$TAG" codecept.phar codecept.phar.sha256 --clobber --repo "$GITHUB_REPOSITORY" diff --git a/phar/.gitignore b/phar/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/phar/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/phar/box.json b/phar/box.json new file mode 100644 index 0000000000..0d4151e96c --- /dev/null +++ b/phar/box.json @@ -0,0 +1,67 @@ +{ + "$schema": "https://raw.githubusercontent.com/box-project/box/4.7.1/res/schema.json", + "main": false, + "stub": "stub.php", + "output": "codecept.phar", + "compression": "GZ", + "compactors": [ + "KevinGH\\Box\\Compactor\\Php" + ], + "check-requirements": false, + "dump-autoload": false, + "finder": [ + { + "in": "vendor", + "notPath": "#^codeception/#", + "notName": [ + "*.md", + "*.markdown", + "*.rst", + "README*", + "CHANGELOG*", + "UPGRADE*", + "CONTRIBUTING*", + "composer.json", + "composer.lock", + "phpunit.xml*", + "phpstan*.neon*", + "psalm.xml*", + "phpcs.xml*", + ".php-cs-fixer*" + ], + "exclude": [ + "Tests", + "tests", + "benchmark", + "demo" + ] + } + ], + "finder-bin": [ + { + "in": "vendor/codeception", + "notName": [ + "*.md", + "*.markdown", + "*.rst", + "README*", + "CHANGELOG*", + "UPGRADE*", + "CONTRIBUTING*", + "composer.json", + "composer.lock", + "phpunit.xml*", + "phpstan*.neon*", + "psalm.xml*", + "phpcs.xml*", + ".php-cs-fixer*" + ], + "exclude": [ + "Tests", + "tests", + "benchmark", + "demo" + ] + } + ] +} diff --git a/phar/build.sh b/phar/build.sh new file mode 100755 index 0000000000..8fd53d5057 --- /dev/null +++ b/phar/build.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Builds codecept.phar for a release tag: phar/build.sh 5.3.7 +# +# The Codeception sources are taken from `git archive `, so export-ignore rules apply +# and the phar contains the tagged code even when this script runs on another branch. +# Result: phar/build/codecept.phar +set -euo pipefail + +BOX_VERSION=4.7.1 + +TAG=${1:-} +if [[ ! "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +PHAR_DIR=$(cd "$(dirname "$0")" && pwd) +ROOT_DIR=$(dirname "$PHAR_DIR") +BUILD_DIR="$PHAR_DIR/build" + +rm -rf "$BUILD_DIR" +mkdir -p "$BUILD_DIR/codeception" +git -c safe.directory="$ROOT_DIR" -C "$ROOT_DIR" archive "$TAG" | tar -x -C "$BUILD_DIR/codeception" +cp "$PHAR_DIR/composer.json" "$PHAR_DIR/box.json" "$PHAR_DIR/stub.php" "$BUILD_DIR/" + +cd "$BUILD_DIR" +composer config repositories.codeception "{\"type\": \"path\", \"url\": \"codeception\", \"options\": {\"symlink\": false, \"versions\": {\"codeception/codeception\": \"$TAG\"}}}" +composer require --no-update "codeception/codeception:$TAG" +# TODO: remove once module-ftp allows a phpseclib version without security advisories +COMPOSER_NO_SECURITY_BLOCKING=1 composer update --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress \ + --ignore-platform-req=ext-apcu \ + --ignore-platform-req=ext-mongodb \ + --ignore-platform-req=ext-phalcon + +curl -fsSL -o box.phar "https://github.com/box-project/box/releases/download/$BOX_VERSION/box.phar" +php -d phar.readonly=0 box.phar compile --no-interaction + +# --no-redirect: otherwise autoload.php runs the copy in ./vendor/codeception instead of the phar +php codecept.phar --version --no-redirect | grep -F "$TAG" diff --git a/phar/composer.json b/phar/composer.json new file mode 100644 index 0000000000..c98fc3e416 --- /dev/null +++ b/phar/composer.json @@ -0,0 +1,30 @@ +{ + "name": "codeception/phar-file", + "type": "project", + "description": "Dependencies bundled into codecept.phar, see build.sh", + "license": "MIT", + "require": { + "codeception/module-amqp": "*", + "codeception/module-apc": "*", + "codeception/module-asserts": "*", + "codeception/module-cli": "*", + "codeception/module-db": "*", + "codeception/module-filesystem": "*", + "codeception/module-ftp": "*", + "codeception/module-memcache": "*", + "codeception/module-mongodb": "*", + "codeception/module-phpbrowser": "*", + "codeception/module-queue": "*", + "codeception/module-redis": "*", + "codeception/module-rest": "*", + "codeception/module-sequence": "*", + "codeception/module-soap": "*", + "codeception/module-webdriver": "*", + "laravel-zero/phar-updater": "^1.0" + }, + "config": { + "platform": { + "php": "8.2.0" + } + } +} diff --git a/phar/stub.php b/phar/stub.php new file mode 100644 index 0000000000..52123853c4 --- /dev/null +++ b/phar/stub.php @@ -0,0 +1,7 @@ +#!/usr/bin/env php + Date: Wed, 18 Nov 2026 18:23:50 +0100 Subject: [PATCH 07/24] Build and push the Docker images with GitHub Actions (#6961) --- .github/workflows/docker.yml | 101 +++++++++++++++++++++++++++++++++++ Dockerfile | 20 +++++-- 2 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000000..cfc3114248 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,101 @@ +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: 'Release tag to build the images for, e.g. 5.3.7' + required: true + +name: docker + +concurrency: + group: docker-${{ github.event.release.tag_name || inputs.tag }} + +permissions: + contents: read + +env: + TAG: ${{ github.event.release.tag_name || inputs.tag }} + # set the repository variable DOCKERHUB_IMAGE to push to another image, e.g. on a fork + IMAGE: ${{ vars.DOCKERHUB_IMAGE || 'codeception/codeception' }} + +jobs: + docker: + name: Build and push ${{ matrix.flavor }} image + runs-on: ubuntu-latest + strategy: + matrix: + include: + - flavor: trixie + suffix: '' + - flavor: alpine + suffix: '-alpine' + steps: + # The Dockerfile comes from the checked out ref: the release tag for release events, the selected + # branch for workflow_dispatch. The Codeception sources always come from the tag. + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Prepare build context + run: | + if [[ ! "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid tag '$TAG', expected a release tag like 5.3.7" >&2 + exit 1 + fi + mkdir "$RUNNER_TEMP/codeception" + git archive "$TAG" | tar -x -C "$RUNNER_TEMP/codeception" + + # latest is only moved for the highest release version, so backfills and patch releases + # of older majors don't overwrite it + - name: Determine image tags + id: tags + env: + SUFFIX: ${{ matrix.suffix }} + run: | + LATEST_TAG=$(git tag --list | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1) + { + echo "list<> "$GITHUB_OUTPUT" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + + - name: Build image + uses: docker/build-push-action@v7 + with: + context: ${{ runner.temp }}/codeception + file: Dockerfile + build-args: | + flavor=${{ matrix.flavor }} + CODECEPTION_VERSION=${{ env.TAG }} + load: true + tags: codeception-smoke-test + + - name: Smoke test + run: docker run --rm codeception-smoke-test --version | grep -F "$TAG" + + - name: Log in to Docker Hub + uses: docker/login-action@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # reuses the layers of the build above + - name: Push image + uses: docker/build-push-action@v7 + with: + context: ${{ runner.temp }}/codeception + file: Dockerfile + build-args: | + flavor=${{ matrix.flavor }} + CODECEPTION_VERSION=${{ env.TAG }} + push: true + tags: ${{ steps.tags.outputs.list }} diff --git a/Dockerfile b/Dockerfile index 956c86f893..b864bfd412 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1 + ARG flavor=trixie FROM php:8.2-cli-${flavor} @@ -27,10 +29,20 @@ ENV COMPOSER_ALLOW_SUPERUSER=1 WORKDIR /codecept -# Install codeception -RUN set -eux; \ +# Version of the Codeception sources in the build context, e.g. 5.3.7. +# Defaults to Codecept::VERSION from the sources, so a plain `docker build .` works. +ARG CODECEPTION_VERSION + +# Install codeception from the build context (the workflow uses `git archive ` as context) +# TODO: remove COMPOSER_NO_SECURITY_BLOCKING once module-ftp allows a phpseclib version without security advisories +RUN --mount=type=bind,target=/tmp/codeception \ + set -eux; \ + version="${CODECEPTION_VERSION:-$(sed -n "s/.*const VERSION = '\(.*\)';/\1/p" /tmp/codeception/src/Codeception/Codecept.php)}"; \ + test -n "${version}"; \ + echo '{}' > composer.json; \ + composer config repositories.codeception "{\"type\": \"path\", \"url\": \"/tmp/codeception\", \"options\": {\"symlink\": false, \"versions\": {\"codeception/codeception\": \"${version}\"}}}"; \ composer require --no-update \ - codeception/codeception \ + "codeception/codeception:${version}" \ codeception/module-apc \ codeception/module-asserts \ codeception/module-cli \ @@ -45,7 +57,7 @@ RUN set -eux; \ codeception/module-sequence \ codeception/module-soap \ codeception/module-webdriver; \ - composer update --no-dev --prefer-dist --no-interaction --optimize-autoloader --apcu-autoloader; \ + COMPOSER_NO_SECURITY_BLOCKING=1 composer update --no-dev --prefer-dist --no-interaction --optimize-autoloader --apcu-autoloader; \ ln -s /codecept/vendor/bin/codecept /usr/local/bin/codecept; \ mkdir /project; From 752604d933c2bc173904d3f9e0a147431ce494f5 Mon Sep 17 00:00:00 2001 From: Faris Basha TM <72191505+farisbasha@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:10:18 +0530 Subject: [PATCH 08/24] Fix dead "See Source" links in ext/README.md (#6969) The extension docs link each extension source on the 4.0 branch, which no longer exists, so all seven links return 404. Link the files on main. --- ext/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/README.md b/ext/README.md index 242aed48e9..87ec1defad 100644 --- a/ext/README.md +++ b/ext/README.md @@ -2,7 +2,7 @@ ## DotReporter -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/DotReporter.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/DotReporter.php) DotReporter provides less verbose output for test execution. Like PHPUnit printer it prints dots "." for successful testes and "F" for failures. @@ -38,7 +38,7 @@ Use this extension as an example for building custom reporters. ## Logger -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/Logger.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/Logger.php) Log suites/tests/steps using Monolog library. Monolog should be installed additionally by Composer. @@ -65,7 +65,7 @@ extensions: ## Recorder -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/Recorder.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/Recorder.php) Saves a screenshot of each step in acceptance tests and shows them as a slideshow on one HTML page (here's an [example](https://codeception.com/images/recorder.gif)) Activated only for suites with WebDriver module enabled. @@ -124,7 +124,7 @@ public function testLogin(AcceptanceTester $I) ## RunBefore -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/RunBefore.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/RunBefore.php) Extension for execution of some processes before running tests. @@ -155,7 +155,7 @@ HINT: you can use different configurations per environment. ## RunFailed -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/RunFailed.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/RunFailed.php) Saves failed tests into tests/log/failed in order to rerun failed tests. @@ -184,7 +184,7 @@ On each execution failed tests are logged and saved into `tests/_output/failed` ## RunProcess -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/RunProcess.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/RunProcess.php) Extension to start and stop processes per suite. Can be used to start/stop selenium server, chromedriver, phantomjs, mailcatcher, etc. @@ -231,7 +231,7 @@ HINT: you can use different configurations per environment. ## SimpleReporter -[See Source](https://github.com/Codeception/Codeception/blob/4.0/ext/SimpleReporter.php) +[See Source](https://github.com/Codeception/Codeception/blob/main/ext/SimpleReporter.php) This extension demonstrates how you can implement console output of your own. Recommended to be used for development purposes only. From c2f42ed23ce3c956c3bd96cdfcce8831ef2b4274 Mon Sep 17 00:00:00 2001 From: W0rma Date: Fri, 20 Nov 2026 16:39:11 +0100 Subject: [PATCH 09/24] Add #[ExampleRow] attribute to describe a single example A single #[Examples('foo', 7)] attribute is treated as a list of examples, so every argument becomes a separate example. Changing that would break the existing #[Examples([1, 1], [2, 2])] syntax. The new repeatable #[ExampleRow] attribute always describes exactly one example, its arguments form the row: #[ExampleRow('foo', 7)] #[ExampleRow('bar', null)] #[Examples] keeps its current behavior. Rows from #[ExampleRow] are added after rows from @example/#[Examples] and before data provider rows. --- src/Codeception/Attribute/ExampleRow.php | 21 +++++++++++ src/Codeception/Test/DataProvider.php | 5 +++ .../data_provider/ExampleRowAttributeTest.php | 37 +++++++++++++++++++ .../Codeception/Test/DataProviderTest.php | 22 +++++++++++ 4 files changed, 85 insertions(+) create mode 100644 src/Codeception/Attribute/ExampleRow.php create mode 100644 tests/data/data_provider/ExampleRowAttributeTest.php diff --git a/src/Codeception/Attribute/ExampleRow.php b/src/Codeception/Attribute/ExampleRow.php new file mode 100644 index 0000000000..bad94dc84f --- /dev/null +++ b/src/Codeception/Attribute/ExampleRow.php @@ -0,0 +1,21 @@ +getAttributes(ExampleRow::class) as $exampleRow) { + $data[] = $exampleRow->getArguments(); + } + $providers = array_merge( $annotation->fetchAll('dataProvider'), $annotation->fetchAll('dataprovider') diff --git a/tests/data/data_provider/ExampleRowAttributeTest.php b/tests/data/data_provider/ExampleRowAttributeTest.php new file mode 100644 index 0000000000..c7a6b19338 --- /dev/null +++ b/tests/data/data_provider/ExampleRowAttributeTest.php @@ -0,0 +1,37 @@ +assertSame($expectedResult, $result); } + public static function exampleRowAttributeProvider(): array + { + return [ + 'single row' => ['testSingleRow', [['foo', 7]]], + 'multiple rows' => ['testMultipleRows', [['foo', null], ['bar', 8]]], + 'named arguments' => ['testNamedArguments', [['name' => 'foo', 'value' => 7]]], + 'array values' => ['testArrayValues', [[['a'], ['b']]]], + 'combined with examples' => ['testCombinedWithExamples', [['foo', 7], ['bar', 8], ['baz', 9]]], + ]; + } + + #[DataProviderAttribute('exampleRowAttributeProvider')] + public function testSupportsExampleRowAttribute(string $methodName, array $expectedResult) + { + require_once codecept_data_dir('data_provider/ExampleRowAttributeTest.php'); + $method = new ReflectionMethod(ExampleRowAttributeTest::class, $methodName); + $result = DataProvider::getDataForMethod($method); + + $this->assertSame($expectedResult, $result); + } + public function testCombinesExampleAndDataProviderAnnotations() { require_once codecept_data_dir('data_provider/CombinedAnnotationDataProviderTest.php'); From d9b1ba31c6b6963911843884751b72608d0a2fe2 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Fri, 20 Nov 2026 17:39:17 +0100 Subject: [PATCH 10/24] Respect coverage settings with php-code-coverage 14 (#6966) --- .../Coverage/Subscriber/Printer.php | 37 ++++++++++++++++--- tests/Support/CoverTester.php | 16 ++++++++ tests/coverage/LocalShowOnlySummaryCept.php | 15 ++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 tests/coverage/LocalShowOnlySummaryCept.php diff --git a/src/Codeception/Coverage/Subscriber/Printer.php b/src/Codeception/Coverage/Subscriber/Printer.php index 8fb17d1a04..6f9449ea7c 100644 --- a/src/Codeception/Coverage/Subscriber/Printer.php +++ b/src/Codeception/Coverage/Subscriber/Printer.php @@ -113,7 +113,13 @@ protected function printConsole(): void { if (class_exists(FacadeReport::class)) { $writer = FacadeReport::fromObject(self::$coverage); - $this->output->write($writer->renderText(null, showColors: $this->options['colors'])); + $this->output->write($writer->renderText( + null, + $this->createThresholds(), + $this->settings['show_uncovered'], + $this->settings['show_only_summary'], + $this->options['colors'] + )); } else { $writer = $this->createTextWriter(); $this->output->write($writer->process(self::$coverage, $this->options['colors'])); @@ -124,7 +130,11 @@ protected function printHtml(): void { if (class_exists(FacadeReport::class)) { $writer = FacadeReport::fromObject(self::$coverage); - $writer->renderHtml($this->absolutePath($this->options['coverage-html'])); + $writer->renderHtml( + $this->absolutePath($this->options['coverage-html']), + $this->htmlGenerator(), + thresholds: $this->createThresholds() + ); } else { $writer = $this->createHtmlFacadeWriter(); $writer->process(self::$coverage, $this->absolutePath($this->options['coverage-html'])); @@ -159,7 +169,12 @@ protected function printText(): void $writer = FacadeReport::fromObject(self::$coverage); file_put_contents( $this->absolutePath($this->options['coverage-text']), - $writer->renderText(null) + $writer->renderText( + null, + $this->createThresholds(), + $this->settings['show_uncovered'], + $this->settings['show_only_summary'] + ) ); } else { $writer = $this->createTextWriter(); @@ -203,18 +218,28 @@ protected function printPHPUnit(): void } } + private function htmlGenerator(): string + { + return ', Codeception and PHPUnit ' . PHPUnitVersion::id() . ''; + } + + private function createThresholds(): Thresholds + { + return Thresholds::from($this->settings['low_limit'], $this->settings['high_limit']); + } + private function createHtmlFacadeWriter(): HtmlFacadeReport { - $generator = ', Codeception and PHPUnit {PHPUnitVersion::id()}'; + $generator = $this->htmlGenerator(); 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'])); + new HtmlFacadeReport($generator, null, $this->createThresholds()); } 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']); + new TextReport($this->createThresholds(), $this->settings['show_uncovered'], $this->settings['show_only_summary']); } } diff --git a/tests/Support/CoverTester.php b/tests/Support/CoverTester.php index 496feeeb72..9afdaa772e 100644 --- a/tests/Support/CoverTester.php +++ b/tests/Support/CoverTester.php @@ -23,10 +23,26 @@ class CoverTester extends \Codeception\Actor { use _generated\CoverTesterActions; + // per-class rows print methods and lines on one line, summary rows don't + private const CLASS_COVERAGE_REGEX = '#Methods:.*Lines:#'; + public function seeCoverageStatsNotEmpty() { $this->seeShellOutputMatches( '#info\n\s+Methods:\s+\d+\.\d+% \( [01]/ 1\)\s+Lines:\s+\d+\.\d+% \( [345]/ [345]\)#s' ); } + + public function seeCoverageDetailsPerClass() + { + $this->seeShellOutputMatches(self::CLASS_COVERAGE_REGEX); + } + + public function dontSeeCoverageDetailsPerClass() + { + \PHPUnit\Framework\Assert::assertDoesNotMatchRegularExpression( + self::CLASS_COVERAGE_REGEX, + $this->grabShellOutput() + ); + } } diff --git a/tests/coverage/LocalShowOnlySummaryCept.php b/tests/coverage/LocalShowOnlySummaryCept.php new file mode 100644 index 0000000000..13c2de2097 --- /dev/null +++ b/tests/coverage/LocalShowOnlySummaryCept.php @@ -0,0 +1,15 @@ +wantTo('print only the summary of local code coverage'); +$I->amInPath('tests/data/sandbox'); +$I->executeCommand('run math MathTest --coverage', false, '-d pcov.directory=' . getcwd()); +$I->seeShellOutputMatches('#Summary:#'); +$I->seeCoverageDetailsPerClass(); + +$I->amGoingTo('enable show_only_summary'); +$I->executeCommand("run -o 'coverage: show_only_summary: true' math MathTest --coverage", false, '-d pcov.directory=' . getcwd()); +$I->seeShellOutputMatches('#Summary:#'); +$I->dontSeeCoverageDetailsPerClass(); From 067fe87f4905e1b88220022d0199bce8e72857a0 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Fri, 20 Nov 2026 17:40:09 +0100 Subject: [PATCH 11/24] Fix generate:test producing invalid code for suites without an actor (#6967) --- src/Codeception/Lib/Generator/Test.php | 2 +- tests/unit/Codeception/Command/GenerateTestTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Generator/Test.php b/src/Codeception/Lib/Generator/Test.php index 88cd2ff8e1..6b0994fe69 100644 --- a/src/Codeception/Lib/Generator/Test.php +++ b/src/Codeception/Lib/Generator/Test.php @@ -54,7 +54,7 @@ public function produce(): string $namespacePath = $this->settings['namespace'] . '\\' . ucfirst((string)$this->settings['suite']) . '\\' . $this->name; $ns = $this->getNamespaceHeader($namespacePath); - if ($ns) { + if ($ns && $actor) { $ns .= "\nuse " . $this->supportNamespace() . $actor . ";"; } diff --git a/tests/unit/Codeception/Command/GenerateTestTest.php b/tests/unit/Codeception/Command/GenerateTestTest.php index 48a667bd1e..ee9e7c35da 100644 --- a/tests/unit/Codeception/Command/GenerateTestTest.php +++ b/tests/unit/Codeception/Command/GenerateTestTest.php @@ -58,6 +58,18 @@ public function testGenerateWithSupportNamespaced() $this->assertIsValidPhp($this->content); } + public function testGenerateWithoutActor() + { + $this->config['actor'] = null; + $this->config['namespace'] = 'MiddleEarth'; + $this->config['support_namespace'] = 'Gondor'; + $this->execute(['suite' => 'shire', 'class' => 'HallUnderTheHill']); + $this->assertStringContainsString('namespace MiddleEarth\Unit;', $this->content); + $this->assertStringNotContainsString('use MiddleEarth\\Gondor\\', $this->content); + $this->assertStringNotContainsString('$tester', $this->content); + $this->assertIsValidPhp($this->content); + } + public function testValidPHP() { $this->execute(['suite' => 'shire', 'class' => 'HallUnderTheHill']); From 6c9f428e184b0222309d07704cf106610227c635 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Fri, 20 Nov 2026 17:40:59 +0100 Subject: [PATCH 12/24] Warn in config:validate when no suites are defined (#6965) --- .gitignore | 1 + src/Codeception/Command/ConfigValidate.php | 10 ++++++++++ tests/cli/ConfigValidateCest.php | 14 ++++++++++++++ tests/data/no_suites/_log/.gitkeep | 0 tests/data/no_suites/codeception.yml | 7 +++++++ tests/data/no_suites/tests/.gitkeep | 0 6 files changed, 32 insertions(+) create mode 100644 tests/data/no_suites/_log/.gitkeep create mode 100644 tests/data/no_suites/codeception.yml create mode 100644 tests/data/no_suites/tests/.gitkeep diff --git a/.gitignore b/.gitignore index 446c3cde61..fc7b6e8e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ tests/data/included_w/src/foo/AcmePack/tests/_support/_generated/* tests/data/included_mix/src/foo/AcmePack/tests/_log/* tests/data/included_mix/src/foo/AcmePack/tests/_support/_generated/* tests/data/included_mix/_log/* +tests/data/no_suites/_log/* tests/data/included_mix/support/_generated/* tests/data/claypit/tests/_log/* tests/data/claypit/tests/_output/* diff --git a/src/Codeception/Command/ConfigValidate.php b/src/Codeception/Command/ConfigValidate.php index 9fa9a2660f..bb0b6b312c 100644 --- a/src/Codeception/Command/ConfigValidate.php +++ b/src/Codeception/Command/ConfigValidate.php @@ -89,6 +89,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln("Available suites: " . implode(', ', $suites)); + if ($suites === [] && empty($config['include'])) { + $output->writeln(''); + $output->writeln(sprintf( + ' Warning: no suites found in %s ', + Configuration::testsDir() + )); + $output->writeln('Run codecept generate:suite to create one.'); + $output->writeln(''); + } + foreach ($suites as $suite) { $output->write("Validating suite {$suite}... "); $this->getSuiteConfig($suite); diff --git a/tests/cli/ConfigValidateCest.php b/tests/cli/ConfigValidateCest.php index db7c73b377..6040eb8b2a 100644 --- a/tests/cli/ConfigValidateCest.php +++ b/tests/cli/ConfigValidateCest.php @@ -38,4 +38,18 @@ public function validatesConfigWithOverrideOption(CliTester $I) $I->executeCommand('config:validate -o "params: foo: bar" --no-ansi'); $I->seeInShellOutput('foo => bar'); } + + public function warnsWhenNoSuitesDefined(CliTester $I) + { + $I->amInPath(codecept_data_dir('no_suites')); + $I->executeCommand('config:validate --no-ansi'); + $I->seeInShellOutput('Warning: no suites found'); + } + + public function doesNotWarnForIncludeOnlyConfig(CliTester $I) + { + $I->amInPath(codecept_data_dir('included_w')); + $I->executeCommand('config:validate --no-ansi'); + $I->dontSeeInShellOutput('Warning: no suites found'); + } } diff --git a/tests/data/no_suites/_log/.gitkeep b/tests/data/no_suites/_log/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/no_suites/codeception.yml b/tests/data/no_suites/codeception.yml new file mode 100644 index 0000000000..a5c6f4ebb8 --- /dev/null +++ b/tests/data/no_suites/codeception.yml @@ -0,0 +1,7 @@ +paths: + tests: tests + data: tests/_data + support: tests/_support + output: _log +settings: + colors: false diff --git a/tests/data/no_suites/tests/.gitkeep b/tests/data/no_suites/tests/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From e99199f37107d3b021ccdb4af4617fc1255092bb Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Fri, 20 Nov 2026 17:50:50 +0100 Subject: [PATCH 13/24] Allow PHP constants in YAML configuration files (#6963) --- .../Command/Shared/ConfigTrait.php | 2 +- src/Codeception/Configuration.php | 2 +- src/Codeception/Lib/ParamsLoader.php | 2 +- tests/cli/ConfigValidateCest.php | 6 ++++ tests/data/params/params_constants.yml | 3 ++ tests/unit/Codeception/ConfigurationTest.php | 34 +++++++++++++++++++ .../unit/Codeception/Lib/ParamsLoaderTest.php | 20 +++++++++++ 7 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/data/params/params_constants.yml create mode 100644 tests/unit/Codeception/Lib/ParamsLoaderTest.php diff --git a/src/Codeception/Command/Shared/ConfigTrait.php b/src/Codeception/Command/Shared/ConfigTrait.php index a7dae7a976..ee7d88ec68 100644 --- a/src/Codeception/Command/Shared/ConfigTrait.php +++ b/src/Codeception/Command/Shared/ConfigTrait.php @@ -55,7 +55,7 @@ protected function overrideConfig(array $configOptions): array } $yaml .= $value; try { - $config = Yaml::parse($yaml); + $config = Yaml::parse($yaml, Yaml::PARSE_CONSTANT); } catch (ParseException $e) { throw new \Codeception\Exception\ParseException("Overridden config can't be parsed: \n{$yaml}\n" . $e->getParsedLine()); } diff --git a/src/Codeception/Configuration.php b/src/Codeception/Configuration.php index e8441eb5dc..e96ea12b4d 100644 --- a/src/Codeception/Configuration.php +++ b/src/Codeception/Configuration.php @@ -360,7 +360,7 @@ protected static function getConfFromContents(string $contents, string $filename $contents = $template->produce(); } try { - $conf = Yaml::parse($contents); + $conf = Yaml::parse($contents, Yaml::PARSE_CONSTANT); } catch (ParseException $e) { throw new ConfigurationException( sprintf( diff --git a/src/Codeception/Lib/ParamsLoader.php b/src/Codeception/Lib/ParamsLoader.php index 2dbe7ed922..57fff7afce 100644 --- a/src/Codeception/Lib/ParamsLoader.php +++ b/src/Codeception/Lib/ParamsLoader.php @@ -84,7 +84,7 @@ private static function loadPhpFile(string $file): array */ private static function loadYamlFile(string $file): array { - $params = Yaml::parse(self::getFileContents($file)); + $params = Yaml::parse(self::getFileContents($file), Yaml::PARSE_CONSTANT); return self::validateParams($params['parameters'] ?? $params, $file); } diff --git a/tests/cli/ConfigValidateCest.php b/tests/cli/ConfigValidateCest.php index 6040eb8b2a..cd0a3222df 100644 --- a/tests/cli/ConfigValidateCest.php +++ b/tests/cli/ConfigValidateCest.php @@ -52,4 +52,10 @@ public function doesNotWarnForIncludeOnlyConfig(CliTester $I) $I->executeCommand('config:validate --no-ansi'); $I->dontSeeInShellOutput('Warning: no suites found'); } + + public function resolvesPhpConstantInOverrideOption(CliTester $I) + { + $I->executeCommand('config:validate -o "params: foo: !php/const PHP_INT_MAX" --no-ansi'); + $I->seeInShellOutput('foo => ' . PHP_INT_MAX); + } } diff --git a/tests/data/params/params_constants.yml b/tests/data/params/params_constants.yml new file mode 100644 index 0000000000..b648bb1159 --- /dev/null +++ b/tests/data/params/params_constants.yml @@ -0,0 +1,3 @@ +parameters: + global: !php/const PHP_INT_MAX + class: !php/const Codeception\Codecept::VERSION diff --git a/tests/unit/Codeception/ConfigurationTest.php b/tests/unit/Codeception/ConfigurationTest.php index 03ea197e52..33184544e9 100644 --- a/tests/unit/Codeception/ConfigurationTest.php +++ b/tests/unit/Codeception/ConfigurationTest.php @@ -67,4 +67,38 @@ public function testDefaultCustomCommandConfig() $this->assertArrayHasKey('extends', $defaultConfig); $this->assertNull($defaultConfig['extends']); } + + #[Group('core')] + public function testPhpConstantsInYamlConfig() + { + $configuration = new class extends \Codeception\Configuration { + public static function parse(string $contents): array + { + return self::getConfFromContents($contents); + } + }; + + $config = $configuration::parse(<<assertSame(PHP_INT_MAX, $config['global']); + $this->assertSame(\Codeception\Codecept::VERSION, $config['class']); + } + + #[Group('core')] + public function testUndefinedPhpConstantInYamlConfig() + { + $configuration = new class extends \Codeception\Configuration { + public static function parse(string $contents): array + { + return self::getConfFromContents($contents, 'codeception.yml'); + } + }; + + $this->expectException(\Codeception\Exception\ConfigurationException::class); + $this->expectExceptionMessage('Error loading Yaml config from codeception.yml'); + $configuration::parse('value: !php/const UNDEFINED_CONSTANT'); + } } diff --git a/tests/unit/Codeception/Lib/ParamsLoaderTest.php b/tests/unit/Codeception/Lib/ParamsLoaderTest.php new file mode 100644 index 0000000000..1ad8b697a6 --- /dev/null +++ b/tests/unit/Codeception/Lib/ParamsLoaderTest.php @@ -0,0 +1,20 @@ +assertSame(PHP_INT_MAX, $params['global']); + $this->assertSame(Codecept::VERSION, $params['class']); + } +} From 74e4c93f8e19e0d7e8758ae2077b81728439bec3 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Fri, 20 Nov 2026 17:55:18 +0100 Subject: [PATCH 14/24] Self-update from GitHub releases (#6970) --- .gitignore | 5 - composer.json | 1 + phar/composer.json | 1 + readme.md | 11 +- src/Codeception/Command/SelfUpdate.php | 12 +- .../Lib/SelfUpdate/GithubReleaseStrategy.php | 195 ++++++++++++++++++ .../SelfUpdate/GithubReleaseStrategyTest.php | 56 +++++ 7 files changed, 264 insertions(+), 17 deletions(-) create mode 100644 src/Codeception/Lib/SelfUpdate/GithubReleaseStrategy.php create mode 100644 tests/unit/Codeception/Lib/SelfUpdate/GithubReleaseStrategyTest.php diff --git a/.gitignore b/.gitignore index fc7b6e8e4e..2867aa9d00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,7 @@ .idea -.roboci composer.phar composer.lock vendor -package/codecept.phar -package/codecept5.phar -package/php54/codecept.phar tests/support/_generated tests/data/app/db tests/data/sandbox @@ -40,7 +36,6 @@ tests/data/bundled_suites/_output/ tests/data/snapshots/tests/_support/_generated tests/data/snapshots/tests/_data/Snapshot.UserSnapshot.json .DS_Store -robo.phar .env .php-cs-fixer.cache .php-cs-fixer.php diff --git a/composer.json b/composer.json index c2458b46a3..2caca5d868 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,7 @@ "codeception/module-phpbrowser": "*@dev", "codeception/module-webdriver": "*@dev", "codeception/util-universalframework": "*@dev", + "composer/semver": "^3.0", "doctrine/orm": "^3.3", "jetbrains/phpstorm-attributes": "^1.0", "laravel-zero/phar-updater": "^1.4", diff --git a/phar/composer.json b/phar/composer.json index c98fc3e416..31cbbfa62c 100644 --- a/phar/composer.json +++ b/phar/composer.json @@ -20,6 +20,7 @@ "codeception/module-sequence": "*", "codeception/module-soap": "*", "codeception/module-webdriver": "*", + "composer/semver": "^3.0", "laravel-zero/phar-updater": "^1.0" }, "config": { diff --git a/readme.md b/readme.md index 3529d70dc3..e26d8c25dc 100644 --- a/readme.md +++ b/readme.md @@ -50,19 +50,20 @@ composer require "codeception/codeception" --dev ### Phar -Download [codecept.phar](https://codeception.com/codecept.phar) +Download `codecept.phar` from the [latest release](https://github.com/Codeception/Codeception/releases/latest). +Phars of older versions are attached to their [releases](https://github.com/Codeception/Codeception/releases). +The phar requires PHP 8.2 or newer. Copy it into your project. -You can also make Codeception an executable and it put it into your `$PATH`, for instance: +You can also make Codeception an executable and put it into your `$PATH`, for instance: ``` -wget https://codeception.com/codecept.phar +wget https://github.com/Codeception/Codeception/releases/latest/download/codecept.phar chmod +x codecept.phar sudo mv codecept.phar /usr/local/bin/codecept - ``` You can then run Codecept in the command line using: `codecept bootstrap`, `codecept run`, etc @@ -73,6 +74,8 @@ Run CLI utility: php codecept.phar ``` +Update it to the latest release of the same major version with `php codecept.phar self-update`. + See also [Installation](https://codeception.com/install) | **[QuickStart](https://codeception.com/quickstart)** ## Getting Started diff --git a/src/Codeception/Command/SelfUpdate.php b/src/Codeception/Command/SelfUpdate.php index 3383a573ee..ea1e919c21 100644 --- a/src/Codeception/Command/SelfUpdate.php +++ b/src/Codeception/Command/SelfUpdate.php @@ -5,6 +5,7 @@ namespace Codeception\Command; use Codeception\Codecept; +use Codeception\Lib\SelfUpdate\GithubReleaseStrategy; use Exception; use Humbug\SelfUpdate\Updater; use Phar; @@ -16,7 +17,8 @@ use function sprintf; /** - * Auto-updates phar archive from official site: 'https://codeception.com/codecept.phar' . + * Updates the phar archive to the latest release of the same major version from GitHub: + * https://github.com/Codeception/Codeception/releases * * * `php codecept.phar self-update` * @@ -38,11 +40,6 @@ class SelfUpdate extends Command */ public const GITHUB_REPO = 'Codeception/Codeception'; - /** - * @var string - */ - public const PHAR_URL = 'https://codeception.com/php80/'; - /** * Holds the current script filename. */ @@ -66,8 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); $updater = new Updater(null, false); - $updater->getStrategy()->setPharUrl(self::PHAR_URL . 'codecept.phar'); - $updater->getStrategy()->setVersionUrl(self::PHAR_URL . 'codecept.version'); + $updater->setStrategyObject(new GithubReleaseStrategy($this->getCurrentVersion())); try { if ($updater->hasUpdate()) { diff --git a/src/Codeception/Lib/SelfUpdate/GithubReleaseStrategy.php b/src/Codeception/Lib/SelfUpdate/GithubReleaseStrategy.php new file mode 100644 index 0000000000..9dce935ee8 --- /dev/null +++ b/src/Codeception/Lib/SelfUpdate/GithubReleaseStrategy.php @@ -0,0 +1,195 @@ +request($updater, sprintf(self::DOWNLOAD_URL, $this->remoteVersion, 'codecept.phar')); + if ($status !== 200) { + throw new HttpRequestException(sprintf('Downloading codecept.phar %s failed with HTTP status %d', $this->remoteVersion, $status)); + } + if (!hash_equals((string)$this->remoteChecksum, hash('sha256', $phar))) { + throw new HttpRequestException(sprintf('Downloaded codecept.phar %s does not match its SHA-256 checksum', $this->remoteVersion)); + } + + file_put_contents($updater->getTempPharFile(), $phar); + } + + /** + * Returns the newest compatible release which has a phar attached, or the local version if there is none. + */ + public function getCurrentRemoteVersion(Updater $updater): string + { + [$status, $json] = $this->request($updater, self::PACKAGIST_URL); + if ($status !== 200) { + throw new HttpRequestException(sprintf('Request to %s failed with HTTP status %d', self::PACKAGIST_URL, $status)); + } + $package = json_decode($json, true, 512, JSON_THROW_ON_ERROR); + $releases = self::expandMinified($package['packages']['codeception/codeception'] ?? []); + + foreach (self::findUpdates($releases, $this->localVersion, $this->phpVersion) as $version) { + $checksumUrl = sprintf(self::DOWNLOAD_URL, $version, 'codecept.phar.sha256'); + [$status, $checksum] = $this->request($updater, $checksumUrl); + // releases without a phar (e.g. while the phar workflow is still running) are skipped + if ($status === 404) { + continue; + } + if ($status !== 200) { + throw new HttpRequestException(sprintf('Request to %s failed with HTTP status %d', $checksumUrl, $status)); + } + if (!preg_match('/^[0-9a-f]{64}\b/', strtolower(trim($checksum)), $matches)) { + throw new HttpRequestException(sprintf('%s does not contain a SHA-256 checksum', $checksumUrl)); + } + + $this->remoteChecksum = $matches[0]; + $this->remoteVersion = $version; + + return $version; + } + + return $this->localVersion; + } + + public function getCurrentLocalVersion(Updater $updater): string + { + return $this->localVersion; + } + + /** + * Returns the stable releases newer than $localVersion, of the same major version + * and supporting $phpVersion, newest first. + * + * @param array}> $releases + * @return string[] + */ + public static function findUpdates(array $releases, string $localVersion, string $phpVersion): array + { + $major = strstr($localVersion, '.', true) . '.'; + $versionParser = new VersionParser(); + + $versions = []; + foreach ($releases as $release) { + $version = $release['version']; + if ( + str_starts_with($version, $major) + && $versionParser->isStable($version) + && version_compare($version, $localVersion, '>') + && Semver::satisfies($phpVersion, $release['require']['php'] ?? '*') + ) { + $versions[] = $version; + } + } + + return Semver::rsort($versions); + } + + /** + * Packagist's p2 metadata only lists the fields which changed from the previous entry, + * see Composer\MetadataMinifier\MetadataMinifier::expand(). + * + * @param array> $versions + * @return array> + */ + public static function expandMinified(array $versions): array + { + $expanded = []; + $current = []; + foreach ($versions as $version) { + foreach ($version as $key => $value) { + if ($value === '__unset') { + unset($current[$key]); + } else { + $current[$key] = $value; + } + } + $expanded[] = $current; + } + + return $expanded; + } + + /** + * @return array{int, string} HTTP status and body of the final response + */ + private function request(Updater $updater, string $url): array + { + $context = stream_context_create(['http' => ['ignore_errors' => true]]); + + set_error_handler([$updater, 'throwHttpRequestException']); + try { + $body = file_get_contents($url, false, $context); + // $http_response_header is deprecated as of PHP 8.5 + if (function_exists('http_get_last_response_headers')) { + $http_response_header = http_get_last_response_headers(); + } + } finally { + restore_error_handler(); + } + if ($body === false) { + throw new HttpRequestException(sprintf('Request to URL failed: %s', $url)); + } + + // after redirects, the headers of all responses are listed, the last status line is the final one + $status = 0; + foreach ($http_response_header ?? [] as $header) { + if (preg_match('#^HTTP/\S+\s+(\d{3})#', $header, $matches)) { + $status = (int)$matches[1]; + } + } + + return [$status, $body]; + } +} diff --git a/tests/unit/Codeception/Lib/SelfUpdate/GithubReleaseStrategyTest.php b/tests/unit/Codeception/Lib/SelfUpdate/GithubReleaseStrategyTest.php new file mode 100644 index 0000000000..0e70b05a5b --- /dev/null +++ b/tests/unit/Codeception/Lib/SelfUpdate/GithubReleaseStrategyTest.php @@ -0,0 +1,56 @@ + '6.0.0', 'require' => ['php' => '^8.4']], + ['version' => '6.0.0-RC1', 'require' => ['php' => '^8.4']], + ['version' => '5.10.0-beta', 'require' => ['php' => '^8.2']], + ['version' => '5.4.1', 'require' => ['php' => '^8.3']], + ['version' => '5.4.0', 'require' => ['php' => '^8.3']], + ['version' => '5.3.7', 'require' => ['php' => '^8.2']], + ['version' => '5.3.6', 'require' => ['php' => '^8.2']], + ['version' => '5.3.5', 'require' => ['php' => '^8.2']], + ['version' => '50.0.0'], + ['version' => '4.2.2', 'require' => ['php' => '>=5.6.0 <9.0']], + ['version' => '4.2.1', 'require' => ['php' => '>=5.6.0 <9.0']], + ]; + + public function testFindsNewerStableReleasesOfSameMajorVersionNewestFirst(): void + { + $this->assertSame(['5.4.1', '5.4.0', '5.3.7', '5.3.6'], GithubReleaseStrategy::findUpdates(self::RELEASES, '5.3.5', '8.4.0')); + $this->assertSame(['4.2.2'], GithubReleaseStrategy::findUpdates(self::RELEASES, '4.2.1', '8.4.0')); + } + + public function testSkipsReleasesRequiringNewerPhp(): void + { + $this->assertSame(['5.3.7', '5.3.6'], GithubReleaseStrategy::findUpdates(self::RELEASES, '5.3.5', '8.2.10')); + } + + public function testFindsNothingIfThereIsNoNewerRelease(): void + { + $this->assertSame([], GithubReleaseStrategy::findUpdates(self::RELEASES, '5.4.1', '8.4.0')); + $this->assertSame([], GithubReleaseStrategy::findUpdates(self::RELEASES, '5.4.2', '8.4.0')); + $this->assertSame([], GithubReleaseStrategy::findUpdates(self::RELEASES, '7.0.0', '8.4.0')); + } + + public function testExpandsMinifiedPackagistMetadata(): void + { + $minified = [ + ['version' => '5.3.7', 'require' => ['php' => '^8.2'], 'suggest' => ['ext-xdebug' => '']], + ['version' => '5.3.6'], + ['version' => '5.2.2', 'require' => ['php' => '^8.1'], 'suggest' => '__unset'], + ]; + + $this->assertSame([ + ['version' => '5.3.7', 'require' => ['php' => '^8.2'], 'suggest' => ['ext-xdebug' => '']], + ['version' => '5.3.6', 'require' => ['php' => '^8.2'], 'suggest' => ['ext-xdebug' => '']], + ['version' => '5.2.2', 'require' => ['php' => '^8.1']], + ], GithubReleaseStrategy::expandMinified($minified)); + } +} From 554ee63148bdf85b6ae635c3618ead870e69536c Mon Sep 17 00:00:00 2001 From: W0rma Date: Sun, 22 Nov 2026 19:01:39 +0100 Subject: [PATCH 15/24] Make the PHP version of the Docker test setup configurable tests/compose.yaml used the composer image, which always ships the latest PHP version. Build the image from the official php image instead, so the internal test suite can be run with every supported PHP version, e.g. PHP_VERSION=8.5. The default is the lowest supported version (8.2), to catch the usage of features of newer PHP versions. Each PHP version gets its own image, so switching the version doesn't require a rebuild. --- tests/README.md | 8 +++++++- tests/compose.yaml | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/README.md b/tests/README.md index af80b6bf44..5cd7e03cba 100644 --- a/tests/README.md +++ b/tests/README.md @@ -118,7 +118,7 @@ Acceptance tests that use demo application and `c3` collector, to check that a c ## Running tests with Docker If you don't want to install PHP locally, you can run the tests in a container with [`tests/compose.yaml`](compose.yaml). -It uses the official `composer` image with Xdebug added, mounts the repository and starts the demo application in the background. +It uses the official `php` image with Composer and Xdebug added, mounts the repository and starts the demo application in the background. The container runs as user and group 1000, set `UID` and `GID` if your ids differ: export UID GID=$(id -g) @@ -145,4 +145,10 @@ Run all suites including the tests which require code coverage (Xdebug is disabl docker compose -f tests/compose.yaml run --rm -e XDEBUG_MODE=coverage php php codecept run cli,unit,coverage +Run the tests with another PHP version (default: 8.2, the lowest supported version). The dependencies have to be updated when switching the version, as `composer.lock` and `vendor` are shared with the host + + export PHP_VERSION=8.5 + docker compose -f tests/compose.yaml run --rm php composer update + docker compose -f tests/compose.yaml run --rm php + Note: the `Dockerfile` in the root of the repository builds the `codeception/codeception` image for running *your* tests, it is not meant for developing Codeception. diff --git a/tests/compose.yaml b/tests/compose.yaml index e6e1232994..d7d81a5bce 100644 --- a/tests/compose.yaml +++ b/tests/compose.yaml @@ -1,12 +1,14 @@ # Runs the internal test suite in a container, see tests/README.md services: php: + # one image per PHP version, set PHP_VERSION to run the tests with another version, e.g. PHP_VERSION=8.5 + image: codeception-tests:php${PHP_VERSION:-8.2} build: - # Xdebug is required by the coverage suite + # Xdebug is required by the coverage suite, git by composer to install the dev versions of the modules dockerfile_inline: | - FROM composer:2 + FROM php:${PHP_VERSION:-8.2}-cli-alpine COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ - RUN install-php-extensions xdebug + RUN apk add --no-cache git && install-php-extensions xdebug zip @composer # run as the host user, so that files created in the repository are not owned by root user: "${UID:-1000}:${GID:-1000}" working_dir: /repo From fcc2f497ed425d93b1987fa9cbbd33d500eb86bd Mon Sep 17 00:00:00 2001 From: W0rma Date: Fri, 20 Nov 2026 16:32:50 +0100 Subject: [PATCH 16/24] Allow a single #[Examples] attribute to describe one example A single #[Examples('foo', 7)] attribute was treated as a list of examples, so every argument became a separate example. Now a single attribute is only treated as a list of examples if all of its arguments are arrays (the existing #[Examples([1, 1], [2, 2])] syntax), otherwise its arguments form one example. --- src/Codeception/Util/Annotation.php | 23 ++++++++++--- .../SingleExamplesAttributeTest.php | 34 +++++++++++++++++++ .../Codeception/Test/DataProviderTest.php | 21 ++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 tests/data/data_provider/SingleExamplesAttributeTest.php diff --git a/src/Codeception/Util/Annotation.php b/src/Codeception/Util/Annotation.php index 76dadaf38d..56fd0286e0 100644 --- a/src/Codeception/Util/Annotation.php +++ b/src/Codeception/Util/Annotation.php @@ -109,13 +109,19 @@ public function fetch(string $annotation): ?string public function fetchAll(string $annotation): array { if (($attr = $this->attribute($annotation)) instanceof ReflectionAttribute) { - if (!$attr->isRepeated()) { - return $attr->getArguments(); - } - if ($annotation === 'example') { $annotation = 'examples'; } + + if (!$attr->isRepeated()) { + $arguments = $attr->getArguments(); + if ($annotation !== 'examples' || self::isListOfExamples($arguments)) { + return $arguments; + } + // A single #[Examples('foo', 7)] attribute describes one example + return [$arguments]; + } + $attrClass = "Codeception\\Attribute\\" . ucfirst($annotation); $attrs = array_filter($this->attributes(), static fn($a): bool => $a->getName() === $attrClass); @@ -151,6 +157,15 @@ public function raw(): string|false return $this->currentReflectedItem->getDocComment(); } + /** + * Legacy syntax: a single #[Examples([1, 1], [2, 2])] attribute where every argument is one example + */ + private static function isListOfExamples(array $arguments): bool + { + return array_is_list($arguments) + && array_filter($arguments, 'is_array') === $arguments; + } + /** * Returns an associative array value of annotation * Either JSON or Doctrine-annotation style allowed diff --git a/tests/data/data_provider/SingleExamplesAttributeTest.php b/tests/data/data_provider/SingleExamplesAttributeTest.php new file mode 100644 index 0000000000..7583136e14 --- /dev/null +++ b/tests/data/data_provider/SingleExamplesAttributeTest.php @@ -0,0 +1,34 @@ +assertSame($expectedResult, $result); } + public static function singleExamplesAttributeProvider(): array + { + return [ + 'scalar values' => ['testScalarValues', [['foo', 7]]], + 'null value' => ['testNullValue', [['foo', null]]], + 'named arguments' => ['testNamedArguments', [['name' => 'foo', 'value' => 7]]], + 'list of examples' => ['testListOfExamples', [['foo', 7], ['bar', 8]]], + 'single array argument' => ['testSingleArrayArgument', [['foo', 7]]], + ]; + } + + #[DataProviderAttribute('singleExamplesAttributeProvider')] + public function testSupportsSingleExamplesAttribute(string $methodName, array $expectedResult) + { + require_once codecept_data_dir('data_provider/SingleExamplesAttributeTest.php'); + $method = new ReflectionMethod(SingleExamplesAttributeTest::class, $methodName); + $result = DataProvider::getDataForMethod($method); + + $this->assertSame($expectedResult, $result); + } + public function testCombinesExampleAndDataProviderAnnotations() { require_once codecept_data_dir('data_provider/CombinedAnnotationDataProviderTest.php'); From 763f6b98b20e69a8c775fba883b4b8377b9d7fcd Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 26 Nov 2026 16:20:38 +0100 Subject: [PATCH 17/24] Update Configuration.php: Adding path to missing config file error message (#6939) --- src/Codeception/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Configuration.php b/src/Codeception/Configuration.php index e96ea12b4d..a6b412e33d 100644 --- a/src/Codeception/Configuration.php +++ b/src/Codeception/Configuration.php @@ -145,7 +145,7 @@ public static function config(?string $configFile = null): array $configDistFile = ($dir !== false ? $dir : dirname($configFile)) . DIRECTORY_SEPARATOR . 'codeception.dist.yml'; if (!file_exists($configFile) && !file_exists($configDistFile)) { - throw new ConfigurationException("Configuration file could not be found.\nRun bootstrap to initialize Codeception.", 404); + throw new ConfigurationException("Configuration file could not be found: Neither {$configFile} nor {$configDistFile} exists.\nRun bootstrap to initialize Codeception.", 404); } $tempConfig = self::$defaultConfig; From 87a32e4f3a97fd10bb527adc881b66ffd3df8998 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Fri, 27 Nov 2026 05:14:09 +0100 Subject: [PATCH 18/24] Build Docker images for all supported PHP versions (#6978) --- .github/workflows/docker.yml | 33 +++++++++++++++++++++++++++------ Dockerfile | 4 +++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index cfc3114248..35172260e4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,10 +22,14 @@ env: jobs: docker: - name: Build and push ${{ matrix.flavor }} image + name: Build and push PHP ${{ matrix.php }} ${{ matrix.flavor }} image runs-on: ubuntu-latest strategy: + # an image which fails to build must not prevent the others from being published + fail-fast: false matrix: + php: ['8.2', '8.3', '8.4', '8.5'] + flavor: [trixie, alpine] include: - flavor: trixie suffix: '' @@ -48,20 +52,31 @@ jobs: mkdir "$RUNNER_TEMP/codeception" git archive "$TAG" | tar -x -C "$RUNNER_TEMP/codeception" + # Every image is tagged with its PHP version, e.g. 5.3.7-php8.4-alpine. The images of the default + # PHP version of the Dockerfile are additionally tagged without it, e.g. 5.3.7-alpine. # latest is only moved for the highest release version, so backfills and patch releases # of older majors don't overwrite it - name: Determine image tags id: tags env: + PHP: ${{ matrix.php }} SUFFIX: ${{ matrix.suffix }} run: | LATEST_TAG=$(git tag --list | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1) + DEFAULT_PHP=$(sed -n 's/^ARG PHP_VERSION=//p' Dockerfile) + test -n "$DEFAULT_PHP" + VERSIONS=("$TAG") + if [[ "$TAG" == "$LATEST_TAG" ]]; then + VERSIONS+=(latest) + fi { echo "list<> "$GITHUB_OUTPUT" @@ -75,12 +90,17 @@ jobs: file: Dockerfile build-args: | flavor=${{ matrix.flavor }} + PHP_VERSION=${{ matrix.php }} CODECEPTION_VERSION=${{ env.TAG }} load: true tags: codeception-smoke-test - name: Smoke test - run: docker run --rm codeception-smoke-test --version | grep -F "$TAG" + env: + PHP: ${{ matrix.php }} + run: | + docker run --rm codeception-smoke-test --version | grep -F "$TAG" + docker run --rm --entrypoint php codeception-smoke-test -r 'echo PHP_MAJOR_VERSION, ".", PHP_MINOR_VERSION;' | grep -Fx "$PHP" - name: Log in to Docker Hub uses: docker/login-action@v4 @@ -96,6 +116,7 @@ jobs: file: Dockerfile build-args: | flavor=${{ matrix.flavor }} + PHP_VERSION=${{ matrix.php }} CODECEPTION_VERSION=${{ env.TAG }} push: true tags: ${{ steps.tags.outputs.list }} diff --git a/Dockerfile b/Dockerfile index b864bfd412..eba6632c14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,10 @@ # syntax=docker/dockerfile:1 ARG flavor=trixie +# The images are published for every PHP version supported by Codeception, this is the default one +ARG PHP_VERSION=8.5 -FROM php:8.2-cli-${flavor} +FROM php:${PHP_VERSION}-cli-${flavor} LABEL maintainer="Tobias Munk " From d73d7971aef962b13c39fba5b8423f065b252864 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sat, 28 Nov 2026 20:16:16 +0100 Subject: [PATCH 19/24] Fix PHP 8.6 deprecation warning (#6974) --- .github/workflows/build.yml | 6 ++++-- src/Codeception/Suite.php | 6 +++--- tests/coverage/LocalCept.php | 12 ++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b4cee8c3f..0f6a279b8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,7 +58,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: ['8.2', '8.3', '8.4', '8.5'] + php: ['8.2', '8.3', '8.4', '8.5', '8.6'] mode: ['stable', 'experimental'] exclude: - php: '8.3' @@ -67,6 +67,8 @@ jobs: mode: 'experimental' - php: '8.5' mode: 'experimental' + - php: '8.6' + mode: 'experimental' steps: - name: Checkout @@ -154,7 +156,7 @@ jobs: fail-fast: false matrix: os: [windows-latest] - php: ['8.2', '8.3', '8.4', '8.5'] + php: ['8.2', '8.3', '8.4', '8.5', '8.6'] steps: - name: Checkout diff --git a/src/Codeception/Suite.php b/src/Codeception/Suite.php index 018f1ca5e0..268bc755b2 100644 --- a/src/Codeception/Suite.php +++ b/src/Codeception/Suite.php @@ -141,12 +141,12 @@ public function reorderDependencies(): void } $queue = []; - $hashes = []; + $ids = []; foreach ($tests as $test) { - if (in_array(spl_object_hash($test), $hashes, true)) { + if (in_array(spl_object_id($test), $ids, true)) { continue; } - $hashes[] = spl_object_hash($test); + $ids[] = spl_object_id($test); $queue[] = $test; } $this->tests = $queue; diff --git a/tests/coverage/LocalCept.php b/tests/coverage/LocalCept.php index f7573f8e5f..7382fd48a3 100644 --- a/tests/coverage/LocalCept.php +++ b/tests/coverage/LocalCept.php @@ -14,7 +14,11 @@ $I->seeShellOutputMatches('#Classes:\s+100\.00\%#'); $I->seeShellOutputMatches('#Methods:\s+100\.00\%#'); -$I->amGoingTo('run local code coverage with path and branch coverage'); -$I->executeCommand("run -o 'coverage: path_coverage: true' math MathCest --coverage", false, '-d pcov.directory=' . getcwd()); -$I->seeShellOutputMatches('#Paths:\s+66\.6(6|7)\%#'); -$I->seeShellOutputMatches('#Branches:\s+80\.00\%#'); +// TODO: Xdebug 3.6 (the first version supporting PHP 8.6) segfaults with path coverage, +// remove the version check once https://bugs.xdebug.org/view.php?id=2445 is fixed +if (PHP_VERSION_ID < 80600) { + $I->amGoingTo('run local code coverage with path and branch coverage'); + $I->executeCommand("run -o 'coverage: path_coverage: true' math MathCest --coverage", false, '-d pcov.directory=' . getcwd()); + $I->seeShellOutputMatches('#Paths:\s+66\.6(6|7)\%#'); + $I->seeShellOutputMatches('#Branches:\s+80\.00\%#'); +} From aed95b55138b35386766c31043331a7319e7f960 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sat, 28 Nov 2026 20:17:23 +0100 Subject: [PATCH 20/24] Fix typos and outdated information in documentation (#6977) * Fix typos and grammar in documentation Fix spelling and grammar errors in docblocks that are rendered into the documentation on codeception.com (console commands, extensions, Module and InitTemplate API) and in markdown files. * Fix outdated class references and mention in markdown docs * Fix incorrect examples and outdated info in console command docs * Fix _before() signature in Module::_reconfigure() example * Fix outdated information in extension docs * Update example project to match current bootstrap output The example project was generated with codecept bootstrap in 2022 and never regenerated, so it still contains what bootstrap produced back then: - step_decorators was indented under modules in the Functional and Unit suites, which was a bootstrap bug fixed in #6624 - the Acceptance suite had no step decorators, while bootstrap now enables ConditionalAssertion, TryTo and Retry (#6624) - the comment in the Acceptance suite was reworded since then - the inherited methods in the actor docblocks were listed in a different order than the actor generator lists them now Update the configuration and actor files to what the current bootstrap command generates. The tests in the example are unchanged. * Document named arguments in #[ExampleRow] docblock --- CHANGELOG-5.x.md | 4 ++-- CONTRIBUTING.md | 4 ++-- example/tests/Acceptance.suite.yml | 13 ++++++++----- example/tests/Functional.suite.yml | 2 +- example/tests/Support/AcceptanceTester.php | 2 +- example/tests/Support/FunctionalTester.php | 2 +- example/tests/Support/UnitTester.php | 2 +- example/tests/Unit.suite.yml | 2 +- ext/DotReporter.php | 2 +- ext/Logger.php | 4 ++-- ext/Recorder.php | 5 ++--- ext/RunBefore.php | 2 +- ext/RunFailed.php | 2 +- readme.md | 2 +- src/Codeception/Attribute/ExampleRow.php | 5 +++++ src/Codeception/Command/Bootstrap.php | 4 ++-- src/Codeception/Command/Build.php | 4 ++-- src/Codeception/Command/ConfigValidate.php | 7 +++---- src/Codeception/Command/GenerateCest.php | 2 +- src/Codeception/Command/GenerateEnvironment.php | 2 +- src/Codeception/Command/GenerateSnapshot.php | 2 +- src/Codeception/Command/GenerateSuite.php | 9 ++++----- src/Codeception/Command/GenerateTest.php | 2 +- src/Codeception/Command/GherkinSnippets.php | 6 +++--- src/Codeception/Command/Run.php | 8 +++++++- src/Codeception/InitTemplate.php | 2 +- src/Codeception/Module.php | 10 +++++----- src/Codeception/README.md | 4 ++-- src/Codeception/Step/README.md | 2 +- src/Codeception/Subscriber/README.md | 2 +- src/Codeception/Util/README.md | 2 +- tests/README.md | 4 ++-- 32 files changed, 68 insertions(+), 57 deletions(-) diff --git a/CHANGELOG-5.x.md b/CHANGELOG-5.x.md index 05b0f2d45e..763c8af526 100644 --- a/CHANGELOG-5.x.md +++ b/CHANGELOG-5.x.md @@ -124,7 +124,7 @@ * Support symfony 7 by @W0rma in #6723 * Avoid infinite loop while waiting for all running tests to finish by @MarcelBolten in #6710 * Add missing "Attribute::IS_REPEATABLE" to DataProvider attribute by @Fahl-Design in #6715 -* Support binary data intest examples by @pongee in #6708 +* Support binary data in test examples by @pongee in #6708 * Improve rendering of $I->assertThat step by @jtheuerkauf in #6719 #### 5.0.12 @@ -365,7 +365,7 @@ Summary of all differences from Codeception 4 * Custom reporters implementing TestListener are no longer supported and must be converted to Extensions * Tests of all formats are reported as useless if they perform no assertions and `reports_useless_tests` setting is enabled * Added path_coverage setting to enable path and branch coverage #6158 by @s0lus -* Added optional value to `fail-fast` option (#6275) by #Verest +* Added optional value to `fail-fast` option (#6275) by @Verest * Module after and failed hooks are executed in reverse order (#6062) by WillemHoman * Removed `JSON` and `TAP` loggers * Removed code coverage blacklist functionality diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 61760608f5..ebf8a73719 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,12 +23,12 @@ Check it with `composer cs-prod` and `composer cs-tests` before sending a pull r Check the [tests/README.md](tests/README.md) to learn how to run and write internal tests. We encourage you to write a test for a patch you are implementing. If this doesn't seem possible, such PRs are still valid and can be accepted. -We also encourage to submit bug reports with a failing test or test environment (3rd party repo with Codeception installation) with demonstration of a failure. That makes easier to us to find the cause and fix it. +We also encourage you to submit bug reports with a failing test or test environment (3rd party repo with Codeception installation) with demonstration of a failure. That makes it easier for us to find the cause and fix it. ## Documentation ### Guides -If you want to contribute documentation to the guides you are asked to send your changes to website repository: [codeception.github.com](https://github.com/Codeception/codeception.github.com/tree/master/docs) +If you want to contribute documentation to the guides you are asked to send your changes to the website repository: [codeception.github.com](https://github.com/Codeception/codeception.github.com/tree/master/docs) ### Modules Documentation The documentation for each module is directly generated from the corresponding docblock which can be found in each module (src/Codeception/Module/*.php in corresponding codeception/module-NAME repository). diff --git a/example/tests/Acceptance.suite.yml b/example/tests/Acceptance.suite.yml index 9229b1f2fc..db00e7cfce 100644 --- a/example/tests/Acceptance.suite.yml +++ b/example/tests/Acceptance.suite.yml @@ -1,12 +1,15 @@ -# Codeception Test Suite Configuration +# Codeception Acceptance Test Suite Configuration # -# Suite for acceptance tests. -# Perform tests in browser using the WebDriver or PhpBrowser. -# If you need both WebDriver and PHPBrowser tests - create a separate suite. +# Perform tests in a browser by either emulating one using PhpBrowser, or in a real browser using WebDriver. +# If you need both WebDriver and PhpBrowser tests, create a separate suite for each. actor: AcceptanceTester modules: enabled: - PhpBrowser: url: http://localhost/myapp -step_decorators: ~ +# Add Codeception\Step\Retry trait to AcceptanceTester to enable retries +step_decorators: + - Codeception\Step\ConditionalAssertion + - Codeception\Step\TryTo + - Codeception\Step\Retry diff --git a/example/tests/Functional.suite.yml b/example/tests/Functional.suite.yml index 4ec7b28e5a..1b7276a25f 100644 --- a/example/tests/Functional.suite.yml +++ b/example/tests/Functional.suite.yml @@ -9,4 +9,4 @@ actor: FunctionalTester modules: enabled: # add a framework module here - step_decorators: ~ +step_decorators: ~ diff --git a/example/tests/Support/AcceptanceTester.php b/example/tests/Support/AcceptanceTester.php index eff633ebf7..6ccbabd2e7 100644 --- a/example/tests/Support/AcceptanceTester.php +++ b/example/tests/Support/AcceptanceTester.php @@ -6,8 +6,8 @@ /** * Inherited Methods - * @method void wantToTest($text) * @method void wantTo($text) + * @method void wantToTest($text) * @method void execute($callable) * @method void expectTo($prediction) * @method void expect($prediction) diff --git a/example/tests/Support/FunctionalTester.php b/example/tests/Support/FunctionalTester.php index e450e52602..71fb8e47ab 100644 --- a/example/tests/Support/FunctionalTester.php +++ b/example/tests/Support/FunctionalTester.php @@ -6,8 +6,8 @@ /** * Inherited Methods - * @method void wantToTest($text) * @method void wantTo($text) + * @method void wantToTest($text) * @method void execute($callable) * @method void expectTo($prediction) * @method void expect($prediction) diff --git a/example/tests/Support/UnitTester.php b/example/tests/Support/UnitTester.php index 78e265c7f8..710bfbdecb 100644 --- a/example/tests/Support/UnitTester.php +++ b/example/tests/Support/UnitTester.php @@ -6,8 +6,8 @@ /** * Inherited Methods - * @method void wantToTest($text) * @method void wantTo($text) + * @method void wantToTest($text) * @method void execute($callable) * @method void expectTo($prediction) * @method void expect($prediction) diff --git a/example/tests/Unit.suite.yml b/example/tests/Unit.suite.yml index 5c521f95ec..486d3c08ef 100644 --- a/example/tests/Unit.suite.yml +++ b/example/tests/Unit.suite.yml @@ -6,4 +6,4 @@ actor: UnitTester modules: enabled: - Asserts - step_decorators: ~ +step_decorators: ~ diff --git a/ext/DotReporter.php b/ext/DotReporter.php index 53d9ac3518..cea55d4e05 100644 --- a/ext/DotReporter.php +++ b/ext/DotReporter.php @@ -33,7 +33,7 @@ * ``` * * - * Enable this reporter with `--ext option` + * Enable this reporter with `--ext` option * * ``` * codecept run --ext DotReporter diff --git a/ext/Logger.php b/ext/Logger.php index 7f265b1b18..4d68541402 100644 --- a/ext/Logger.php +++ b/ext/Logger.php @@ -30,9 +30,9 @@ * ``` * * Codeception's core/internal stuff is logged into `tests/_output/codeception.log`. - * Test suites' steps are logged into `tests/_output/-.log`. + * Test suites' steps are logged into `tests/_output/-.log`. * - * To enable this module add to your `codeception.yml`: + * To enable this extension add to your `codeception.yml`: * * ``` yaml * extensions: diff --git a/ext/Recorder.php b/ext/Recorder.php index 0ddbd1533f..76396ff592 100644 --- a/ext/Recorder.php +++ b/ext/Recorder.php @@ -67,11 +67,11 @@ * #### Configuration * * * `delete_successful` (default: true) - delete screenshots for successfully passed tests (i.e. log only failed and errored tests). - * * `module` (default: WebDriver) - which module for screenshots to use. Set `AngularJS` if you want to use it with AngularJS module. Generally, the module should implement `Codeception\Lib\Interfaces\ScreenshotSaver` interface. + * * `module` (default: WebDriver) - which module for screenshots to use. The module should implement `Codeception\Lib\Interfaces\ScreenshotSaver` interface. * * `ignore_steps` (default: []) - array of step names that should not be recorded (given the step passed), * wildcards supported. Meta steps can also be ignored. * * `success_color` (default: success) - bootstrap values to be used for color representation for passed tests * * `failure_color` (default: danger) - bootstrap values to be used for color representation for failed tests - * * `error_color` (default: dark) - bootstrap values to be used for color representation for scenarios where there's an issue occurred while generating a recording + * * `error_color` (default: dark) - bootstrap values to be used for color representation for scenarios where an issue occurred while generating a recording * * `delete_orphaned` (default: false) - delete recording folders created via previous runs * * `include_microseconds` (default: false) - enable microsecond precision for recorded step time details * @@ -81,7 +81,6 @@ * extensions: * enabled: * - Codeception\Extension\Recorder: - * module: AngularJS # enable for Angular * delete_successful: false # keep screenshots of successful tests * ignore_steps: [have, grab*] * ``` diff --git a/ext/RunBefore.php b/ext/RunBefore.php index 3ad4bc954e..86ba77bf6e 100644 --- a/ext/RunBefore.php +++ b/ext/RunBefore.php @@ -25,7 +25,7 @@ * Can be configured in suite config: * * ```yaml - * # acceptance.suite.yml + * # Acceptance.suite.yml * extensions: * enabled: * - Codeception\Extension\RunBefore: diff --git a/ext/RunFailed.php b/ext/RunFailed.php index bf7765b7ac..36d3566e0a 100644 --- a/ext/RunFailed.php +++ b/ext/RunFailed.php @@ -32,7 +32,7 @@ * ``` * --override "extensions: config: Codeception\Extension\RunFailed: fail-group: another_group1" * ``` - * Remember: If you run tests and they generated custom-named fail group, to run this group, you should add override too + * Remember: If your test run generated a custom-named fail group, add the same override to run this group * * **This extension is enabled by default.** * diff --git a/readme.md b/readme.md index e26d8c25dc..644f277b25 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ $I->click('New'); $I->see('New Page'); $I->submitForm('form#new_page', ['title' => 'Movie Review']); $I->see('page created'); // notice generated -$I->see('Movie Review','h1'); // head of page of is our title +$I->see('Movie Review','h1'); // head of page is our title $I->seeInCurrentUrl('pages/movie-review'); // slug is generated $I->seeInDatabase('pages', ['title' => 'Movie Review']); // data is stored in database ``` diff --git a/src/Codeception/Attribute/ExampleRow.php b/src/Codeception/Attribute/ExampleRow.php index bad94dc84f..00dfc93a50 100644 --- a/src/Codeception/Attribute/ExampleRow.php +++ b/src/Codeception/Attribute/ExampleRow.php @@ -11,6 +11,11 @@ * * #[ExampleRow('foo', 7)] * #[ExampleRow('bar', 8)] + * + * Use named arguments to access values by key, e.g. $example['name']: + * + * #[ExampleRow(name: 'foo', value: 7)] + * #[ExampleRow(name: 'bar', value: 8)] */ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final readonly class ExampleRow diff --git a/src/Codeception/Command/Bootstrap.php b/src/Codeception/Command/Bootstrap.php index 6dbdd434b1..58c7063ee6 100644 --- a/src/Codeception/Command/Bootstrap.php +++ b/src/Codeception/Command/Bootstrap.php @@ -20,8 +20,8 @@ * * * `codecept bootstrap` - creates `tests` dir and `codeception.yml` in current dir. * * `codecept bootstrap --empty` - creates `tests` dir without suites - * * `codecept bootstrap --namespace Frontend` - creates tests, and use `Frontend` namespace for actor classes and helpers. - * * `codecept bootstrap --actor Wizard` - sets actor as Wizard, to have `TestWizard` actor in tests. + * * `codecept bootstrap --namespace Frontend` - creates tests, and uses `Frontend` namespace for actor classes and helpers. + * * `codecept bootstrap --actor Wizard` - sets actor suffix to Wizard, to have `AcceptanceWizard`, `FunctionalWizard`, and `UnitWizard` actors in tests. * * `codecept bootstrap path/to/the/project` - provide different path to a project, where tests should be placed * */ diff --git a/src/Codeception/Command/Build.php b/src/Codeception/Command/Build.php index 94b47903cf..7300406b35 100644 --- a/src/Codeception/Command/Build.php +++ b/src/Codeception/Command/Build.php @@ -15,8 +15,8 @@ use function implode; /** - * Generates Actor classes (initially Guy classes) from suite configs. - * Starting from Codeception 2.0 actor classes are auto-generated. Use this command to generate them manually. + * Generates Actor classes from suite configs. + * Actor classes are auto-generated. Use this command to generate them manually. * * * `codecept build` * * `codecept build path/to/project` diff --git a/src/Codeception/Command/ConfigValidate.php b/src/Codeception/Command/ConfigValidate.php index bb0b6b312c..651d2c04bc 100644 --- a/src/Codeception/Command/ConfigValidate.php +++ b/src/Codeception/Command/ConfigValidate.php @@ -18,12 +18,12 @@ /** * Validates and prints Codeception config. - * Use it do debug Yaml configs + * Use it to debug Yaml configs * * Check config: * - * * `codecept config`: check global config - * * `codecept config Unit`: check suite config + * * `codecept config:validate`: check global config + * * `codecept config:validate Unit`: check suite config * * Load config: * @@ -34,7 +34,6 @@ * * * `codecept config:validate -o "settings: shuffle: true"`: enable shuffle * * `codecept config:validate -o "settings: lint: false"`: disable linting - * * `codecept config:validate -o "reporters: report: \Custom\Reporter" --report`: use custom reporter * */ #[AsCommand( diff --git a/src/Codeception/Command/GenerateCest.php b/src/Codeception/Command/GenerateCest.php index 0ae28932c9..14c30ec9af 100644 --- a/src/Codeception/Command/GenerateCest.php +++ b/src/Codeception/Command/GenerateCest.php @@ -19,7 +19,7 @@ * * `codecept generate:cest suite Login` * * `codecept g:cest suite subdir/subdir/testnameCest.php` * * `codecept g:cest suite LoginCest -c path/to/project` - * * `codecept g:cest "App\Login"` + * * `codecept g:cest suite "App\Login"` * */ #[AsCommand( diff --git a/src/Codeception/Command/GenerateEnvironment.php b/src/Codeception/Command/GenerateEnvironment.php index c549a4bd6e..ac33879d7a 100644 --- a/src/Codeception/Command/GenerateEnvironment.php +++ b/src/Codeception/Command/GenerateEnvironment.php @@ -17,7 +17,7 @@ * * * `codecept g:env firefox` * - * Required to have `envs` path to be specified in `codeception.yml` + * Requires `envs` path to be specified in `codeception.yml` */ #[AsCommand( name: 'generate:environment', diff --git a/src/Codeception/Command/GenerateSnapshot.php b/src/Codeception/Command/GenerateSnapshot.php index 0ff6ca677e..8ddd445dc7 100644 --- a/src/Codeception/Command/GenerateSnapshot.php +++ b/src/Codeception/Command/GenerateSnapshot.php @@ -16,7 +16,7 @@ /** * Generates Snapshot. - * Snapshot can be used to test dynamical data. + * Snapshots can be used to test dynamic data. * If suite name is provided, an actor class will be included into placeholder * * * `codecept g:snapshot UserEmails` diff --git a/src/Codeception/Command/GenerateSuite.php b/src/Codeception/Command/GenerateSuite.php index c2211162e2..fab5a50891 100644 --- a/src/Codeception/Command/GenerateSuite.php +++ b/src/Codeception/Command/GenerateSuite.php @@ -20,12 +20,11 @@ use function ucfirst; /** - * Create new test suite. Requires suite name and actor name + * Creates new test suite. Requires suite name, actor name is optional. * - * * `` - * * `codecept g:suite Api` -> api + ApiTester - * * `codecept g:suite Integration Code` -> integration + CodeTester - * * `codecept g:suite Frontend Front` -> frontend + FrontTester + * * `codecept g:suite Api` -> Api + ApiTester + * * `codecept g:suite Integration Code` -> Integration + Code + * * `codecept g:suite Frontend Front` -> Frontend + Front * */ #[AsCommand( diff --git a/src/Codeception/Command/GenerateTest.php b/src/Codeception/Command/GenerateTest.php index 5110db9df7..67e8e69212 100644 --- a/src/Codeception/Command/GenerateTest.php +++ b/src/Codeception/Command/GenerateTest.php @@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Generates skeleton for Unit Test that extends `Codeception\TestCase\Test`. + * Generates skeleton for Unit Test that extends `Codeception\Test\Unit`. * * * `codecept g:test Unit User` * * `codecept g:test Unit "App\User"` diff --git a/src/Codeception/Command/GherkinSnippets.php b/src/Codeception/Command/GherkinSnippets.php index 7c5cb2eae6..68871c1132 100644 --- a/src/Codeception/Command/GherkinSnippets.php +++ b/src/Codeception/Command/GherkinSnippets.php @@ -20,10 +20,10 @@ * * Usage: * - * * `codecept gherkin:snippets Acceptance` - snippets from all feature of acceptance tests - * * `codecept gherkin:snippets Acceptance/feature/users` - snippets from `feature/users` dir of acceptance tests + * * `codecept gherkin:snippets Acceptance` - snippets from all features of acceptance tests + * * `codecept gherkin:snippets Acceptance feature/users` - snippets from `feature/users` dir of acceptance tests * * `codecept gherkin:snippets Acceptance user_account.feature` - snippets from a single feature file - * * `codecept gherkin:snippets Acceptance/feature/users/user_accout.feature` - snippets from feature file in a dir + * * `codecept gherkin:snippets Acceptance feature/users/user_account.feature` - snippets from feature file in a dir */ #[AsCommand( name: 'gherkin:snippets', diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 4babc44e1a..991062ac8e 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -60,7 +60,7 @@ * * Verbosity modes: * - * * `codecept run -v`: + * * `codecept run -v`: print enabled modules of each suite and more detailed results * * `codecept run --steps`: print step-by-step execution * * `codecept run -vv`: print steps and debug information * * `codecept run --debug`: alias for `-vv` @@ -113,6 +113,7 @@ * --coverage-text Generate CodeCoverage text report in file (default: "coverage.txt") * --coverage-phpunit Generate CodeCoverage PHPUnit report in file (default: "coverage-phpunit") * --coverage-cobertura Generate CodeCoverage Cobertura report in file (default: "coverage-cobertura") + * --coverage-crap4j Generate CodeCoverage report in Crap4J XML format (default: "crap4j.xml") * --no-exit Don't finish with exit code * --group (-g) Groups of tests to be executed (multiple values allowed) * --skip (-s) Skip selected suites (multiple values allowed) @@ -120,6 +121,11 @@ * --env Run tests in selected environments. (multiple values allowed, environments can be merged with ',') * --fail-fast (-f) Stop after nth failure (defaults to 1) * --no-rebuild Do not rebuild actor classes on start + * --ext (-e) Run with extension enabled (multiple values allowed) + * --shard Execute subset of tests to run tests on different machines, e.g. 1/3, 2/3, 3/3 + * --filter Filter tests by name + * --grep Filter tests by name (alias to --filter) + * --no-artifacts Don't report about artifacts * --help (-h) Display this help message. * --quiet (-q) Do not output any message. Almost the same as `--silent` * --verbose (-v|vv|vvv) Increase the verbosity of messages: `v` for normal output, `vv` for steps and debug, `vvv` for Codeception-internal debug diff --git a/src/Codeception/InitTemplate.php b/src/Codeception/InitTemplate.php index 216d4bd56a..a4cf212494 100644 --- a/src/Codeception/InitTemplate.php +++ b/src/Codeception/InitTemplate.php @@ -73,7 +73,7 @@ public function initDir(string $workDir): void } /** - * Override this class to create customized setup. + * Override this method to create customized setup. * * @return mixed */ diff --git a/src/Codeception/Module.php b/src/Codeception/Module.php index 91e4ae7d60..e20c67fe36 100644 --- a/src/Codeception/Module.php +++ b/src/Codeception/Module.php @@ -24,12 +24,12 @@ abstract class Module use Asserts; /** - * By setting it to false module wan't inherit methods of parent class. + * By setting it to false module won't inherit methods of parent class. */ public static bool $includeInheritedActions = true; /** - * Allows to explicitly set what methods have this class. + * Allows to explicitly set which methods this class has. */ public static array $onlyActions = []; @@ -91,8 +91,8 @@ public function _setConfig(array $config): void * ```php * getMetadata()->getGroups()) { + * public function _before(TestInterface $test) { + * if (in_array('cleanup', $test->getMetadata()->getGroups())) { * $this->getModule('Db')->_reconfigure(['cleanup' => true]); * } * } @@ -249,7 +249,7 @@ protected function debugSection(string $title, mixed $msg): void } /** - * Short text message to an amount of chars + * Shortens text message to a given number of chars */ protected function shortenMessage(string $message, int $chars = 150): string { diff --git a/src/Codeception/README.md b/src/Codeception/README.md index db54b5072a..1e4a27afb7 100644 --- a/src/Codeception/README.md +++ b/src/Codeception/README.md @@ -4,7 +4,7 @@ The most important classes are defined in root of Codeception. * `Codecept` - starts event dispatcher, loads subscribers, starts SuiteManager * `SuiteManager` - starts modules, starts test runner -* `TestLoader` - loads tests from files +* `Test\Loader` - loads tests from files * `Configuration` - loads YAML configuration * `Events` - defines all Codeception events -* `TestCase` - applies Codeception feature to `PHPUnit\Framework\TestCase` class. \ No newline at end of file +* `Test\Unit` - base class for unit tests, applies Codeception features to `PHPUnit\Framework\TestCase` class. \ No newline at end of file diff --git a/src/Codeception/Step/README.md b/src/Codeception/Step/README.md index c17b97369c..a6b6b685e6 100644 --- a/src/Codeception/Step/README.md +++ b/src/Codeception/Step/README.md @@ -1,4 +1,4 @@ # Steps -Steps are used in scenarios. They do not keep any logic, but responsible for formatting. Exception +Steps are used in scenarios. They do not keep any logic, but are responsible for formatting. Exception for `ConditionalAssertion` which acts like `Assertion` but acts differently on fail. \ No newline at end of file diff --git a/src/Codeception/Subscriber/README.md b/src/Codeception/Subscriber/README.md index 8672cc9d98..88918e13db 100644 --- a/src/Codeception/Subscriber/README.md +++ b/src/Codeception/Subscriber/README.md @@ -3,4 +3,4 @@ Where this is possible Codeception uses the Observer pattern to separate different parts of framework and make them act independently. -Events are defined in `Codeception\Event`). New features can be added seamlessly when they are created in Subscribers. \ No newline at end of file +Events are defined in `Codeception\Events`. New features can be added seamlessly when they are created in Subscribers. \ No newline at end of file diff --git a/src/Codeception/Util/README.md b/src/Codeception/Util/README.md index 967f006879..776cfe34b9 100644 --- a/src/Codeception/Util/README.md +++ b/src/Codeception/Util/README.md @@ -1,4 +1,4 @@ # Util Classes Codeception Util classes are used by various parts of framework and can be used in tests or in other projects. They do -not depend on Codeception core, nor they do know of Codeception itself. Thus, some of those classes have static methods. \ No newline at end of file +not depend on Codeception core, nor do they know of Codeception itself. Thus, some of those classes have static methods. \ No newline at end of file diff --git a/tests/README.md b/tests/README.md index 5cd7e03cba..9cf4433234 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,6 +1,6 @@ # Codeception Internal Tests -In case you submit a pull request, you will be asked for writing a test. +In case you submit a pull request, you will be asked to write a test. There are 3 suites for testing @@ -111,7 +111,7 @@ To see the page in the browser, open `http://127.0.0.1:8008/your-route` ## Coverage -Acceptance tests that use demo application and `c3` collector, to check that a code coverage can be collected remotely. This tests are rarely updated, they should just work ) +Acceptance tests that use demo application and `c3` collector, to check that a code coverage can be collected remotely. These tests are rarely updated, they should just work ) --- From c3d5c7c1df57704dec59e0cb1fcbf40b8974a493 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sat, 28 Nov 2026 20:21:27 +0100 Subject: [PATCH 21/24] Remove outdated files (#6988) * Replace ext/README.md with link to extensions documentation * Remove obsolete TestGuy actors from included test fixtures The functional suite directories of the jazz, shire and jazz/pianist fixtures contain a TestGuy.php that was generated by the build task of Codeception 1.x, which wrote the actor with all module actions inlined into the suite directory. Since actors moved to the support directory (330c495da), the build command generates tests/_helpers/TestGuy.php and _generated/TestGuyActions.php instead. Those files exist in all three fixtures, and the Jazz namespace is autoloaded from the support directory, so Jazz\TestGuy is always loaded from there. The copies in the functional directories are neither generated nor loaded anymore and were only kept up to date by hand. * Remove unused test support classes and fixtures Helper\Shire and Shire\Codeception\Module\EmulateModuleHelper do not match the Tests\Support\ PSR-4 rule added in #6943, so Composer warned about them on every dump-autoload. Neither class is referenced anywhere. Tests\Support\Helper\TestHelper is an empty module that no suite enables, and tests/data/doctrine2_entities is a leftover from the Doctrine2 module, which moved out of core in 2019. --- ext/README.md | 239 +--------- tests/Support/Helper/Shire.php | 7 - tests/Support/Helper/TestHelper.php | 7 - .../Module/EmulateModuleHelper.php | 30 -- .../doctrine2_entities/EntityWithUuid.php | 31 -- .../jazz/pianist/tests/functional/TestGuy.php | 408 ------------------ .../jazz/tests/functional/TestGuy.php | 408 ------------------ .../shire/tests/functional/TestGuy.php | 408 ------------------ 8 files changed, 2 insertions(+), 1536 deletions(-) delete mode 100644 tests/Support/Helper/Shire.php delete mode 100644 tests/Support/Helper/TestHelper.php delete mode 100644 tests/Support/Shire/Codeception/Module/EmulateModuleHelper.php delete mode 100644 tests/data/doctrine2_entities/EntityWithUuid.php delete mode 100644 tests/data/included/jazz/pianist/tests/functional/TestGuy.php delete mode 100644 tests/data/included/jazz/tests/functional/TestGuy.php delete mode 100644 tests/data/included/shire/tests/functional/TestGuy.php diff --git a/ext/README.md b/ext/README.md index 87ec1defad..74f416259c 100644 --- a/ext/README.md +++ b/ext/README.md @@ -1,240 +1,5 @@ # Official Extensions -## DotReporter - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/DotReporter.php) - -DotReporter provides less verbose output for test execution. -Like PHPUnit printer it prints dots "." for successful testes and "F" for failures. - -![](https://cloud.githubusercontent.com/assets/220264/26132800/4d23f336-3aab-11e7-81ba-2896a4c623d2.png) - -```bash - .......... - .......... - .......... - .......... - .......... - .......... - .......... - .......... - -Time: 2.07 seconds, Memory: 20.00MB - -OK (80 tests, 124 assertions) -``` - - -Enable this reporter with `--ext option` - -``` -codecept run --ext DotReporter -``` - -Failures and Errors are printed by a standard Codeception reporter. -Use this extension as an example for building custom reporters. - - - -## Logger - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/Logger.php) - -Log suites/tests/steps using Monolog library. -Monolog should be installed additionally by Composer. - -``` -composer require monolog/monolog -``` - -Steps are logged into `tests/_output/codeception.log` - -To enable this module add to your `codeception.yml`: - -``` yaml -extensions: - enabled: [Codeception\Extension\Logger] -``` - -#### Config - -* `max_files` (default: 3) - how many log files to keep - - - - -## Recorder - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/Recorder.php) - -Saves a screenshot of each step in acceptance tests and shows them as a slideshow on one HTML page (here's an [example](https://codeception.com/images/recorder.gif)) -Activated only for suites with WebDriver module enabled. - -The screenshots are saved to `tests/_output/record_*` directories, open `index.html` to see them as a slideshow. - -#### Installation - -Add this to the list of enabled extensions in `codeception.yml` or `acceptance.suite.yml`: - -``` yaml -extensions: - enabled: - - Codeception\Extension\Recorder -``` - -#### Configuration - -* `delete_successful` (default: true) - delete screenshots for successfully passed tests (i.e. log only failed and errored tests). -* `module` (default: WebDriver) - which module for screenshots to use. Set `AngularJS` if you want to use it with AngularJS module. Generally, the module should implement `Codeception\Lib\Interfaces\ScreenshotSaver` interface. -* `ignore_steps` (default: []) - array of step names that should not be recorded (given the step passed), * wildcards supported. Meta steps can also be ignored. -* `success_color` (default: success) - bootstrap values to be used for color representation for passed tests -* `failure_color` (default: danger) - bootstrap values to be used for color representation for failed tests -* `error_color` (default: dark) - bootstrap values to be used for color representation for scenarios where there's an issue occurred while generating a recording -* `delete_orphaned` (default: false) - delete recording folders created via previous runs -* `include_microseconds` (default: false) - enable microsecond precision for recorded step time details - -#### Examples: - -``` yaml -extensions: - enabled: - - Codeception\Extension\Recorder: - module: AngularJS # enable for Angular - delete_successful: false # keep screenshots of successful tests - ignore_steps: [have, grab*] -``` -#### Skipping recording of steps with annotations - -It is also possible to skip recording of steps for specified tests by using the @skipRecording annotation. - -```php -/** -* @skipRecording login -* @skipRecording amOnUrl -*\/ -public function testLogin(AcceptanceTester $I) -{ - $I->login(); - $I->amOnUrl('https://codeception.com'); -} -``` - - - - -## RunBefore - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/RunBefore.php) - -Extension for execution of some processes before running tests. - -Processes can be independent and dependent. -Independent processes run independently of each other. -Dependent processes run sequentially one by one. - -Can be configured in suite config: - -```yaml -# acceptance.suite.yml -extensions: - enabled: - - Codeception\Extension\RunBefore: - - independent_process_1 - - - - dependent_process_1_1 - - dependent_process_1_2 - - independent_process_2 - - - - dependent_process_2_1 - - dependent_process_2_2 -``` - -HINT: you can use different configurations per environment. - - - -## RunFailed - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/RunFailed.php) - -Saves failed tests into tests/log/failed in order to rerun failed tests. - -To rerun failed tests just run the `failed` group: - -``` -php codecept run -g failed -``` - -To change failed group name add: -``` ---override "extensions: config: Codeception\Extension\RunFailed: fail-group: another_group1" -``` -Remember: if you run tests and they generated custom-named fail group, to run this group, you should add override too - -Starting from Codeception 2.1 **this extension is enabled by default**. - -``` yaml -extensions: - enabled: [Codeception\Extension\RunFailed] -``` - -On each execution failed tests are logged and saved into `tests/_output/failed` file. - - - -## RunProcess - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/RunProcess.php) - -Extension to start and stop processes per suite. -Can be used to start/stop selenium server, chromedriver, phantomjs, mailcatcher, etc. - -Can be configured in suite config: - -```yaml -# acceptance.suite.yml -extensions: - enabled: - - Codeception\Extension\RunProcess: - - chromedriver -``` - -Multiple parameters can be passed as array: - -```yaml -# acceptance.suite.yml - -extensions: - enabled: - - Codeception\Extension\RunProcess: - - php -S 127.0.0.1:8000 -t tests/data/app - - java -jar ~/selenium-server.jar -``` - -In the end of a suite all launched processes will be stopped. - -To wait for the process to be launched use `sleep` option. -In this case you need configuration to be specified as object: - -```yaml -extensions: - enabled: - - Codeception\Extension\RunProcess: - 0: java -jar ~/selenium-server.jar - 1: mailcatcher - sleep: 5 # wait 5 seconds for processes to boot -``` - -HINT: you can use different configurations per environment. - - - -## SimpleReporter - -[See Source](https://github.com/Codeception/Codeception/blob/main/ext/SimpleReporter.php) - -This extension demonstrates how you can implement console output of your own. -Recommended to be used for development purposes only. - - +The documentation for the official extensions is available at [codeception.com/extensions](https://codeception.com/extensions). +It is generated from the docblocks of the extension classes in this directory. diff --git a/tests/Support/Helper/Shire.php b/tests/Support/Helper/Shire.php deleted file mode 100644 index 2151069e2b..0000000000 --- a/tests/Support/Helper/Shire.php +++ /dev/null @@ -1,7 +0,0 @@ -assertions; - } - - public function seeFeaturesEquals($expected) - { - Assert::assertEquals($expected, $this->scenario->getFeature()); - } - - public function _before(\Codeception\TestInterface $test) - { - $this->scenario = $test->getScenario(); - } -} diff --git a/tests/data/doctrine2_entities/EntityWithUuid.php b/tests/data/doctrine2_entities/EntityWithUuid.php deleted file mode 100644 index e1b80b94c5..0000000000 --- a/tests/data/doctrine2_entities/EntityWithUuid.php +++ /dev/null @@ -1,31 +0,0 @@ -id = Uuid::uuid4(); - } - - public function getId(): UuidInterface - { - return $this->id; - } -} diff --git a/tests/data/included/jazz/pianist/tests/functional/TestGuy.php b/tests/data/included/jazz/pianist/tests/functional/TestGuy.php deleted file mode 100644 index 00d80e8180..0000000000 --- a/tests/data/included/jazz/pianist/tests/functional/TestGuy.php +++ /dev/null @@ -1,408 +0,0 @@ -scenario->runStep(new \Codeception\Step\Condition('amInPath', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Opens a file and stores it's content. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $filename - * @see \Codeception\Module\Filesystem::openFile() - */ - public function openFile($filename) - { - return $this->scenario->runStep(new \Codeception\Step\Action('openFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes a file - * - * ``` php - * deleteFile('composer.lock'); - * ?> - * ``` - * - * @param $filename - * @see \Codeception\Module\Filesystem::deleteFile() - */ - public function deleteFile($filename) - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes directory with all subdirectories - * - * ``` php - * deleteDir('vendor'); - * ?> - * ``` - * - * @param $dirname - * @see \Codeception\Module\Filesystem::deleteDir() - */ - public function deleteDir($dirname) - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Copies directory with all contents - * - * ``` php - * copyDir('vendor','old_vendor'); - * ?> - * ``` - * - * @param $src - * @param $dst - * @see \Codeception\Module\Filesystem::copyDir() - */ - public function copyDir($src, $dst) - { - return $this->scenario->runStep(new \Codeception\Step\Action('copyDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file has `text` in it. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeInThisFile() - */ - public function canSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeInThisFile', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file has `text` in it. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::seeInThisFile() - */ - public function seeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeInThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks the strict matching of file contents. - * Unlike `seeInThisFile` will fail if file has something more than expected lines. - * Better to use with HEREDOC strings. - * Matching is done after removing "\r" chars from file content. - * - * ``` php - * openFile('process.pid'); - * $I->seeFileContentsEqual('3192'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeFileContentsEqual() - */ - public function canSeeFileContentsEqual($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeFileContentsEqual', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks the strict matching of file contents. - * Unlike `seeInThisFile` will fail if file has something more than expected lines. - * Better to use with HEREDOC strings. - * Matching is done after removing "\r" chars from file content. - * - * ``` php - * openFile('process.pid'); - * $I->seeFileContentsEqual('3192'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::seeFileContentsEqual() - */ - public function seeFileContentsEqual($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeFileContentsEqual', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file doesn't contain `text` in it - * - * ``` php - * openFile('composer.json'); - * $I->dontSeeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::dontSeeInThisFile() - */ - public function cantSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInThisFile', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file doesn't contain `text` in it - * - * ``` php - * openFile('composer.json'); - * $I->dontSeeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::dontSeeInThisFile() - */ - public function dontSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('dontSeeInThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes a file - * @see \Codeception\Module\Filesystem::deleteThisFile() - */ - public function deleteThisFile() - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists in path. - * Opens a file when it's exists - * - * ``` php - * seeFileFound('UserModel.php','app/models'); - * ?> - * ``` - * - * @param $filename - * @param string|null $path - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeFileFound() - */ - public function canSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeFileFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists in path. - * Opens a file when it's exists - * - * ``` php - * seeFileFound('UserModel.php','app/models'); - * ?> - * ``` - * - * @param $filename - * @param string|null $path - * @see \Codeception\Module\Filesystem::seeFileFound() - */ - public function seeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeFileFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file does not exist in path - * - * @param $filename - * @param string|null $path - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::dontSeeFileFound() - */ - public function cantSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeFileFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file does not exist in path - * - * @param $filename - * @param string|null $path - * @see \Codeception\Module\Filesystem::dontSeeFileFound() - */ - public function dontSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('dontSeeFileFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Erases directory contents - * - * ``` php - * cleanDir('logs'); - * ?> - * ``` - * - * @param $dirname - * @see \Codeception\Module\Filesystem::cleanDir() - */ - public function cleanDir($dirname) - { - return $this->scenario->runStep(new \Codeception\Step\Action('cleanDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Saves contents to file - * - * @param $filename - * @param $contents - * @see \Codeception\Module\Filesystem::writeToFile() - */ - public function writeToFile($filename, $contents) - { - return $this->scenario->runStep(new \Codeception\Step\Action('writeToFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * Conditional Assertion: Test won't be stopped on fail - * @see \Jazz\Pianist\Codeception\Module\TestHelper::seeEquals() - */ - public function canSeeEquals($expected, $actual) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeEquals', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Jazz\Pianist\Codeception\Module\TestHelper::seeEquals() - */ - public function seeEquals($expected, $actual) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeEquals', func_get_args())); - } -} diff --git a/tests/data/included/jazz/tests/functional/TestGuy.php b/tests/data/included/jazz/tests/functional/TestGuy.php deleted file mode 100644 index c2663c4879..0000000000 --- a/tests/data/included/jazz/tests/functional/TestGuy.php +++ /dev/null @@ -1,408 +0,0 @@ -scenario->runStep(new \Codeception\Step\Condition('amInPath', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Opens a file and stores it's content. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $filename - * @see \Codeception\Module\Filesystem::openFile() - */ - public function openFile($filename) - { - return $this->scenario->runStep(new \Codeception\Step\Action('openFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes a file - * - * ``` php - * deleteFile('composer.lock'); - * ?> - * ``` - * - * @param $filename - * @see \Codeception\Module\Filesystem::deleteFile() - */ - public function deleteFile($filename) - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes directory with all subdirectories - * - * ``` php - * deleteDir('vendor'); - * ?> - * ``` - * - * @param $dirname - * @see \Codeception\Module\Filesystem::deleteDir() - */ - public function deleteDir($dirname) - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Copies directory with all contents - * - * ``` php - * copyDir('vendor','old_vendor'); - * ?> - * ``` - * - * @param $src - * @param $dst - * @see \Codeception\Module\Filesystem::copyDir() - */ - public function copyDir($src, $dst) - { - return $this->scenario->runStep(new \Codeception\Step\Action('copyDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file has `text` in it. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeInThisFile() - */ - public function canSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeInThisFile', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file has `text` in it. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::seeInThisFile() - */ - public function seeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeInThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks the strict matching of file contents. - * Unlike `seeInThisFile` will fail if file has something more than expected lines. - * Better to use with HEREDOC strings. - * Matching is done after removing "\r" chars from file content. - * - * ``` php - * openFile('process.pid'); - * $I->seeFileContentsEqual('3192'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeFileContentsEqual() - */ - public function canSeeFileContentsEqual($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeFileContentsEqual', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks the strict matching of file contents. - * Unlike `seeInThisFile` will fail if file has something more than expected lines. - * Better to use with HEREDOC strings. - * Matching is done after removing "\r" chars from file content. - * - * ``` php - * openFile('process.pid'); - * $I->seeFileContentsEqual('3192'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::seeFileContentsEqual() - */ - public function seeFileContentsEqual($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeFileContentsEqual', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file doesn't contain `text` in it - * - * ``` php - * openFile('composer.json'); - * $I->dontSeeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::dontSeeInThisFile() - */ - public function cantSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInThisFile', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file doesn't contain `text` in it - * - * ``` php - * openFile('composer.json'); - * $I->dontSeeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::dontSeeInThisFile() - */ - public function dontSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('dontSeeInThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes a file - * @see \Codeception\Module\Filesystem::deleteThisFile() - */ - public function deleteThisFile() - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists in path. - * Opens a file when it's exists - * - * ``` php - * seeFileFound('UserModel.php','app/models'); - * ?> - * ``` - * - * @param $filename - * @param string|null $path - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeFileFound() - */ - public function canSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeFileFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists in path. - * Opens a file when it's exists - * - * ``` php - * seeFileFound('UserModel.php','app/models'); - * ?> - * ``` - * - * @param $filename - * @param string|null $path - * @see \Codeception\Module\Filesystem::seeFileFound() - */ - public function seeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeFileFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file does not exist in path - * - * @param $filename - * @param string|null $path - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::dontSeeFileFound() - */ - public function cantSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeFileFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file does not exist in path - * - * @param $filename - * @param string|null $path - * @see \Codeception\Module\Filesystem::dontSeeFileFound() - */ - public function dontSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('dontSeeFileFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Erases directory contents - * - * ``` php - * cleanDir('logs'); - * ?> - * ``` - * - * @param $dirname - * @see \Codeception\Module\Filesystem::cleanDir() - */ - public function cleanDir($dirname) - { - return $this->scenario->runStep(new \Codeception\Step\Action('cleanDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Saves contents to file - * - * @param $filename - * @param $contents - * @see \Codeception\Module\Filesystem::writeToFile() - */ - public function writeToFile($filename, $contents) - { - return $this->scenario->runStep(new \Codeception\Step\Action('writeToFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * Conditional Assertion: Test won't be stopped on fail - * @see \Jazz\Codeception\Module\TestHelper::seeEquals() - */ - public function canSeeEquals($expected, $actual) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeEquals', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Jazz\Codeception\Module\TestHelper::seeEquals() - */ - public function seeEquals($expected, $actual) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeEquals', func_get_args())); - } -} diff --git a/tests/data/included/shire/tests/functional/TestGuy.php b/tests/data/included/shire/tests/functional/TestGuy.php deleted file mode 100644 index 23458114b2..0000000000 --- a/tests/data/included/shire/tests/functional/TestGuy.php +++ /dev/null @@ -1,408 +0,0 @@ -scenario->runStep(new \Codeception\Step\Condition('amInPath', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Opens a file and stores it's content. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $filename - * @see \Codeception\Module\Filesystem::openFile() - */ - public function openFile($filename) - { - return $this->scenario->runStep(new \Codeception\Step\Action('openFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes a file - * - * ``` php - * deleteFile('composer.lock'); - * ?> - * ``` - * - * @param $filename - * @see \Codeception\Module\Filesystem::deleteFile() - */ - public function deleteFile($filename) - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes directory with all subdirectories - * - * ``` php - * deleteDir('vendor'); - * ?> - * ``` - * - * @param $dirname - * @see \Codeception\Module\Filesystem::deleteDir() - */ - public function deleteDir($dirname) - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Copies directory with all contents - * - * ``` php - * copyDir('vendor','old_vendor'); - * ?> - * ``` - * - * @param $src - * @param $dst - * @see \Codeception\Module\Filesystem::copyDir() - */ - public function copyDir($src, $dst) - { - return $this->scenario->runStep(new \Codeception\Step\Action('copyDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file has `text` in it. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeInThisFile() - */ - public function canSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeInThisFile', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file has `text` in it. - * - * Usage: - * - * ``` php - * openFile('composer.json'); - * $I->seeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::seeInThisFile() - */ - public function seeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeInThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks the strict matching of file contents. - * Unlike `seeInThisFile` will fail if file has something more than expected lines. - * Better to use with HEREDOC strings. - * Matching is done after removing "\r" chars from file content. - * - * ``` php - * openFile('process.pid'); - * $I->seeFileContentsEqual('3192'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeFileContentsEqual() - */ - public function canSeeFileContentsEqual($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeFileContentsEqual', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks the strict matching of file contents. - * Unlike `seeInThisFile` will fail if file has something more than expected lines. - * Better to use with HEREDOC strings. - * Matching is done after removing "\r" chars from file content. - * - * ``` php - * openFile('process.pid'); - * $I->seeFileContentsEqual('3192'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::seeFileContentsEqual() - */ - public function seeFileContentsEqual($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeFileContentsEqual', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file doesn't contain `text` in it - * - * ``` php - * openFile('composer.json'); - * $I->dontSeeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::dontSeeInThisFile() - */ - public function cantSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInThisFile', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks If opened file doesn't contain `text` in it - * - * ``` php - * openFile('composer.json'); - * $I->dontSeeInThisFile('codeception/codeception'); - * ?> - * ``` - * - * @param $text - * @see \Codeception\Module\Filesystem::dontSeeInThisFile() - */ - public function dontSeeInThisFile($text) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('dontSeeInThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Deletes a file - * @see \Codeception\Module\Filesystem::deleteThisFile() - */ - public function deleteThisFile() - { - return $this->scenario->runStep(new \Codeception\Step\Action('deleteThisFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists in path. - * Opens a file when it's exists - * - * ``` php - * seeFileFound('UserModel.php','app/models'); - * ?> - * ``` - * - * @param $filename - * @param string|null $path - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::seeFileFound() - */ - public function canSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeFileFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists in path. - * Opens a file when it's exists - * - * ``` php - * seeFileFound('UserModel.php','app/models'); - * ?> - * ``` - * - * @param $filename - * @param string|null $path - * @see \Codeception\Module\Filesystem::seeFileFound() - */ - public function seeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeFileFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file does not exist in path - * - * @param $filename - * @param string|null $path - * Conditional Assertion: Test won't be stopped on fail - * @see \Codeception\Module\Filesystem::dontSeeFileFound() - */ - public function cantSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeFileFound', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file does not exist in path - * - * @param $filename - * @param string|null $path - * @see \Codeception\Module\Filesystem::dontSeeFileFound() - */ - public function dontSeeFileFound($filename, ?string $path = null) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('dontSeeFileFound', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Erases directory contents - * - * ``` php - * cleanDir('logs'); - * ?> - * ``` - * - * @param $dirname - * @see \Codeception\Module\Filesystem::cleanDir() - */ - public function cleanDir($dirname) - { - return $this->scenario->runStep(new \Codeception\Step\Action('cleanDir', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Saves contents to file - * - * @param $filename - * @param $contents - * @see \Codeception\Module\Filesystem::writeToFile() - */ - public function writeToFile($filename, $contents) - { - return $this->scenario->runStep(new \Codeception\Step\Action('writeToFile', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * Conditional Assertion: Test won't be stopped on fail - * @see \Shire\Codeception\Module\TestHelper::seeEquals() - */ - public function canSeeEquals($expected, $actual) - { - return $this->scenario->runStep(new \Codeception\Step\ConditionalAssertion('seeEquals', func_get_args())); - } - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Shire\Codeception\Module\TestHelper::seeEquals() - */ - public function seeEquals($expected, $actual) - { - return $this->scenario->runStep(new \Codeception\Step\Assertion('seeEquals', func_get_args())); - } -} From cca700d0a8ba77a16fcdd1da50669ba0ab255726 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sat, 28 Nov 2026 20:24:18 +0100 Subject: [PATCH 22/24] Fix TypeError for repeated #[Depends] attributes in unit tests (#6980) When #[Depends] is used more than once on a test, the dependencies are stored as one array per attribute, but TestCaseWrapper::fetchDependencies() and Unit::fetchDependencies() expected one string per dependency. Loading such a test failed with "str_contains(): Argument #1 ($haystack) must be of type string, array given". Flatten the dependencies like Cest::fetchDependencies() already does since #6676. Co-authored-by: Christian Lerch --- src/Codeception/Test/TestCaseWrapper.php | 15 ++++++----- src/Codeception/Test/Unit.php | 15 ++++++----- .../Codeception/Test/TestCaseWrapperTest.php | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/Codeception/Test/TestCaseWrapper.php b/src/Codeception/Test/TestCaseWrapper.php index a9ff64dcb1..617a9ac9af 100644 --- a/src/Codeception/Test/TestCaseWrapper.php +++ b/src/Codeception/Test/TestCaseWrapper.php @@ -90,12 +90,15 @@ public function getScenario(): ?Scenario public function fetchDependencies(): array { $class = $this->testCase::class; - return array_map( - static fn(string $dep): string => str_contains($dep, ':') || !method_exists($class, $dep) - ? $dep - : "$class:$dep", - $this->metadata->getDependencies() - ); + $names = []; + foreach ($this->metadata->getDependencies() as $dependency) { + foreach ((array)$dependency as $required) { + $names[] = str_contains($required, ':') || !method_exists($class, $required) + ? $required + : $class . ':' . $required; + } + } + return $names; } public function getReportFields(): array diff --git a/src/Codeception/Test/Unit.php b/src/Codeception/Test/Unit.php index 619c023326..c79f6a594a 100644 --- a/src/Codeception/Test/Unit.php +++ b/src/Codeception/Test/Unit.php @@ -151,12 +151,15 @@ public function getReportFields(): array public function fetchDependencies(): array { - return array_map( - fn($dep): string => !str_contains((string)$dep, ':') && method_exists($this, $dep) - ? self::class . ":{$dep}" - : $dep, - $this->getMetadata()->getDependencies() - ); + $names = []; + foreach ($this->getMetadata()->getDependencies() as $dependency) { + foreach ((array)$dependency as $required) { + $names[] = !str_contains((string)$required, ':') && method_exists($this, $required) + ? self::class . ":{$required}" + : $required; + } + } + return $names; } public function getFileName(): string diff --git a/tests/unit/Codeception/Test/TestCaseWrapperTest.php b/tests/unit/Codeception/Test/TestCaseWrapperTest.php index 7512f2675c..54aa181d70 100644 --- a/tests/unit/Codeception/Test/TestCaseWrapperTest.php +++ b/tests/unit/Codeception/Test/TestCaseWrapperTest.php @@ -3,10 +3,12 @@ declare(strict_types=1); use Tests\Support\CodeTester; +use Codeception\Attribute\Depends; use Codeception\Attribute\Group; use Codeception\Test\TestCaseWrapper; use Codeception\Test\Unit; use Codeception\Test\Descriptor; +use PHPUnit\Framework\TestCase; #[Group('testCaseWrapper')] final class TestCaseWrapperTest extends Unit @@ -35,4 +37,28 @@ public function testNamings() $this->assertSame(['testCaseWrapper', 'core'], $test->getMetadata()->getGroups()); } + + public function testRepeatedDependsAttributesAreFlattened() + { + $testCase = new class ('testTarget') extends TestCase { + #[Depends('testFirst')] + #[Depends('OtherTest:testSecond', 'testThird')] + public function testTarget(): void + { + } + + public function testFirst(): void + { + } + + public function testThird(): void + { + } + }; + + $this->assertSame( + [$testCase::class . ':testFirst', 'OtherTest:testSecond', $testCase::class . ':testThird'], + (new TestCaseWrapper($testCase))->fetchDependencies() + ); + } } From 1119770d3b80367550a1868e7ddf9b367ae3e409 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sun, 29 Nov 2026 23:00:49 +0100 Subject: [PATCH 23/24] Fix "Array to string conversion" for array groups in included apps (#6982) Groups defined as a list of paths (e.g. `infection: [path/to/Test.php]`) crashed when the configuration had an `include` section, because runIncludedSuites() assumed every group value is a single path string. Prefix each path individually and leave absolute paths untouched, so groups passed via `-o` (as Infection does) and nested includes work too. Fixes #6673 --- src/Codeception/Command/Run.php | 6 +++++- tests/cli/IncludedCest.php | 19 +++++++++++++++++++ tests/data/included/codeception.yml | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 991062ac8e..1a63c321f2 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -534,7 +534,11 @@ protected function runIncludedSuites( $config = Configuration::config($currentDir); if (!empty($defaultConfig['groups'])) { - $groups = array_map(fn ($g): string => $absolutePath . $g, $defaultConfig['groups']); + $toAbsolute = fn (string $path): string => codecept_is_path_absolute($path) ? $path : $absolutePath . $path; + $groups = array_map( + fn (string|array $g): string|array => is_array($g) ? array_map($toAbsolute, $g) : $toAbsolute($g), + $defaultConfig['groups'] + ); Configuration::append(['groups' => $groups]); } diff --git a/tests/cli/IncludedCest.php b/tests/cli/IncludedCest.php index 768e7c1a9f..163c36580f 100644 --- a/tests/cli/IncludedCest.php +++ b/tests/cli/IncludedCest.php @@ -179,6 +179,25 @@ public function runIncludedGroup(CliTester $I) $I->seeInShellOutput('2 tests'); } + #[Before('moveToIncluded')] + public function runIncludedGroupDefinedAsArray(CliTester $I) + { + $I->executeCommand('run -g array_group', false); + $I->dontSeeInShellOutput('Array to string conversion'); + $I->dontSeeInShellOutput('No tests executed'); + $I->seeInShellOutput('2 tests'); + } + + #[Before('moveToIncluded')] + public function runIncludedGroupOverriddenWithAbsolutePaths(CliTester $I) + { + $testFile = codecept_data_dir('included/jazz/tests/unit/SimpleTest.php'); + $I->executeCommand("run -g override_group -o \"groups: override_group: [{$testFile}]\"", false); + $I->dontSeeInShellOutput('Array to string conversion'); + $I->dontSeeInShellOutput('No tests executed'); + $I->seeInShellOutput('2 tests'); + } + public function includedSuitesAreNotRunTwice(CliTester $I) { $I->amInPath('tests/data/included_two_config_files'); diff --git a/tests/data/included/codeception.yml b/tests/data/included/codeception.yml index 2c2222c884..4511d5543c 100644 --- a/tests/data/included/codeception.yml +++ b/tests/data/included/codeception.yml @@ -5,6 +5,7 @@ include: groups: group: group.txt + array_group: [jazz/tests/unit/SimpleTest.php] paths: tests: tests From a129bbf0c0598df5aa470e655737947ac048f389 Mon Sep 17 00:00:00 2001 From: Dieter Beck Date: Sun, 29 Nov 2026 23:02:16 +0100 Subject: [PATCH 24/24] Fix class detection for readonly anonymous classes (#6987) The parser looked for `new` at a fixed offset before the `class` keyword, so `new readonly class (...)` was treated as a class declaration. This caused an "Uninitialized string offset" warning, or a bogus class name like `12` for `new readonly class(12)`. Use PhpToken and treat `class` as a declaration only when the next significant token is a name. Fixes #6755 --- src/Codeception/Lib/Parser.php | 64 +++++++---------------- tests/data/ReadonlyAnonymousClassCest.php | 29 ++++++++++ tests/unit/Codeception/Lib/ParserTest.php | 13 +++++ 3 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 tests/data/ReadonlyAnonymousClassCest.php diff --git a/src/Codeception/Lib/Parser.php b/src/Codeception/Lib/Parser.php index 48cfec213e..12e02db0ae 100644 --- a/src/Codeception/Lib/Parser.php +++ b/src/Codeception/Lib/Parser.php @@ -11,6 +11,7 @@ use Codeception\Test\Metadata; use Exception; use ParseError; +use PhpToken; class Parser { @@ -99,18 +100,21 @@ public static function load(string $file): void */ public static function getClassesFromFile(string $file): array { - $sourceCodeTokens = token_get_all(file_get_contents($file), TOKEN_PARSE); + $tokens = PhpToken::tokenize(file_get_contents($file), TOKEN_PARSE); $classes = []; $namespace = ''; - foreach ($sourceCodeTokens as $i => $token) { - if ($token[0] === T_NAMESPACE) { - $namespace = self::extractNamespace($sourceCodeTokens, $i); + foreach ($tokens as $i => $token) { + if ($token->is(T_NAMESPACE)) { + $name = self::nextSignificantToken($tokens, $i); + $namespace = $name?->is([T_STRING, T_NAME_QUALIFIED]) ? $name->text . '\\' : ''; } - if ($token[0] === T_CLASS) { - $class = self::extractClass($sourceCodeTokens, $i); - if ($class) { - $classes[] = $namespace . $class; + // Only a class declaration has a name right after the keyword, unlike + // anonymous classes (`new readonly class (...)`), `Foo::class` and named arguments (`class: ...`) + if ($token->is(T_CLASS)) { + $name = self::nextSignificantToken($tokens, $i); + if ($name?->is(T_STRING)) { + $classes[] = $namespace . $name->text; } } } @@ -119,48 +123,18 @@ public static function getClassesFromFile(string $file): array return $classes; } - private static function extractNamespace(array $tokens, int $index): string + /** + * @param PhpToken[] $tokens + */ + private static function nextSignificantToken(array $tokens, int $index): ?PhpToken { - $namespace = ''; $counter = count($tokens); for ($j = $index + 1; $j < $counter; ++$j) { - if ($tokens[$j] === '{' || $tokens[$j] === ';') { - break; - } - if ($tokens[$j][0] === T_STRING || $tokens[$j][0] === T_NAME_QUALIFIED) { - $namespace .= $tokens[$j][1] . '\\'; + if (!$tokens[$j]->isIgnorable()) { + return $tokens[$j]; } } - return $namespace; - } - - private static function extractClass(array $tokens, int $index): ?string - { - // class at the beginning of file - if (!isset($tokens[$index - 2])) { - return $tokens[$index + 2][1] ?? null; - } - // new class - if (isset($tokens[$index - 2]) && $tokens[$index - 2][0] === T_NEW) { - return null; - } - // :: class - if (isset($tokens[$index - 1]) && $tokens[$index - 1][0] === T_WHITESPACE && isset($tokens[$index - 2]) && $tokens[$index - 2][0] === T_DOUBLE_COLON) { - return null; - } - // ::class - if (isset($tokens[$index - 1]) && $tokens[$index - 1][0] === T_DOUBLE_COLON) { - return null; - } - // class{ - if (isset($tokens[$index + 1]) && $tokens[$index + 1] === '{') { - return null; - } - // class { - if (isset($tokens[$index + 2]) && $tokens[$index + 1][0] === T_WHITESPACE && $tokens[$index + 2] === '{') { - return null; - } - return $tokens[$index + 2][1] ?? null; + return null; } /* diff --git a/tests/data/ReadonlyAnonymousClassCest.php b/tests/data/ReadonlyAnonymousClassCest.php new file mode 100644 index 0000000000..6d1c7e6164 --- /dev/null +++ b/tests/data/ReadonlyAnonymousClassCest.php @@ -0,0 +1,29 @@ +assertSame([\Tests\Unit\AnonymousClassWithAttributeCest::class], $classes); } + + /** + * @Issue https://github.com/Codeception/Codeception/issues/6755 + */ + #[Group('core')] + public function testParseTestContainingReadonlyAnonymousClass() + { + if (PHP_VERSION_ID < 80300) { + $this->markTestSkipped('Readonly anonymous classes require PHP 8.3'); + } + $classes = Parser::getClassesFromFile(codecept_data_dir('ReadonlyAnonymousClassCest.php')); + $this->assertSame([\Tests\Unit\ReadonlyAnonymousClassCest::class], $classes); + } }