diff --git a/docs/APITesting.md b/docs/APITesting.md index dc1950dce..3e1bac17d 100644 --- a/docs/APITesting.md +++ b/docs/APITesting.md @@ -21,7 +21,7 @@ We will put all the api tests there. > **NOTE:** REST API testing requires the `codeception/module-rest` package to be installed. -The REST web service is accessed via HTTP with standard methods: `GET`, `POST`, `PUT`, `DELETE`. They allow users to receive and manipulate entities from the service. Accessing a WebService requires an HTTP client, so for using it you need the module `PhpBrowser` or one of framework modules set up. For example, we can use the `Symfony` module for Symfony2 applications in order to ignore web server and test web service internally. +The REST web service is accessed via HTTP with standard methods: `GET`, `POST`, `PUT`, `DELETE`. They allow users to receive and manipulate entities from the service. Accessing a WebService requires an HTTP client, so for using it you need the module `PhpBrowser` or one of framework modules set up. For example, we can use the `Symfony` module for Symfony applications in order to ignore web server and test web service internally. Configure modules in `Api.suite.yml`: @@ -137,8 +137,6 @@ To send a request with custom method use `send` action: $response = $I->send('TRACE', '/posts'); ``` -> sendAsJson methods were introduced in module-rest 1.4.1 - If API endpoint accepts JSON you can use `send` methods with `AsJson` suffix to convert data automatically. In this case `Content-Type` header is sent with `application/json` value and response if JSON is parsed: @@ -249,7 +247,7 @@ class Api extends \Codeception\Module public function seeResponseIsHtml() { $response = $this->getModule('REST')->response; - $this->assertRegExp('~^.*?<\/html>~m', $response); + $this->assertMatchesRegularExpression('~^.*?<\/html>~m', $response); } } @@ -361,7 +359,7 @@ $I->seeSoapResponseIncludes(\Codeception\Util\Xml::build() It's up to you to decide whether to use `XmlBuilder` or plain XML. `XmlBuilder` will return XML string as well. -You may extend current functionality by using `SOAP` module in your helper class. To access the SOAP response as `\DOMDocument` you can use `response` property of `SOAP` module. +You may extend current functionality by using `SOAP` module in your helper class. To access the SOAP response as `\DOMDocument` you can use `xmlResponse` property of `SOAP` module. ```php getModule('SOAP')->response; + $response = $this->getModule('SOAP')->xmlResponse; $this->assertTrue($response->schemaValidate($schema)); } } diff --git a/docs/AcceptanceTests.md b/docs/AcceptanceTests.md index 6d51b81d9..6faee3631 100644 --- a/docs/AcceptanceTests.md +++ b/docs/AcceptanceTests.md @@ -462,7 +462,7 @@ It is important to understand that SmartWait works only with a specific locators * `#locator` - CSS ID locator, works * `//locator` - general XPath locator, works -* `['css' => 'button'']` - strict locator, works +* `['css' => 'button']` - strict locator, works But it won't be executed for all other locator types. See the example: diff --git a/docs/AdvancedUsage.md b/docs/AdvancedUsage.md index 16d44070d..27f774be1 100644 --- a/docs/AdvancedUsage.md +++ b/docs/AdvancedUsage.md @@ -208,7 +208,7 @@ The concept of groups was taken from PHPUnit and behaves in the same way. You ca namespace Tests\Acceptance; use Codeception\Attribute\Group; -use Tests\Support\AcceptanceTester +use Tests\Support\AcceptanceTester; class UserCest { @@ -285,7 +285,7 @@ class EndpointCest ## Example Annotation -As well as the `\Codeception\Attribute\Examples` attribute, available for Cest tests, the `@example` attribute allows you to +As well as the `\Codeception\Attribute\Examples` attribute, available for Cest tests, the `@example` annotation allows you to inject test parameters in place of an actual [DataProvider](#dataprovider-attribute) for Unit tests. ```php @@ -311,7 +311,7 @@ class ExampleTest extends \Codeception\Test\Unit ## DataProvider Attribute -You can also use the `@dataProvider` annotation for creating dynamic examples for [Cest classes](#Cest-Classes), using a **protected method** for providing example data: +You can also use the `#[DataProvider]` attribute for creating dynamic examples for [Cest classes](#Cest-Classes), using a **protected method** for providing example data: ```php current('capabilities'); You can inject `\Codeception\Scenario` like this: ```php -use Codeception\Scenario $scenario; +use Codeception\Scenario; public function myTest(Scenario $scenario) { @@ -622,10 +622,9 @@ codecept run -o "settings: shuffle: true" Tests will be randomly reordered on each run. When tests are executed in shuffle mode a seed value will be printed. Copy this seed value from the output to be able to rerun tests in the same order. -```yaml +```bash $ codecept run -Codeception PHP Testing Framework v2.4.5 -Powered by PHPUnit 5.7.27 by Sebastian Bergmann and contributors. +Codeception PHP Testing Framework v5.3.7 https://stand-with-ukraine.pp.ua [Seed] 1872290562 ``` @@ -644,7 +643,7 @@ passing all dependencies as arguments. This may be useful when working with Help ```php Improve this guide diff --git a/docs/Customization.md b/docs/Customization.md index 393897afd..9e0d47981 100644 --- a/docs/Customization.md +++ b/docs/Customization.md @@ -19,10 +19,10 @@ php vendor/bin/codecept bootstrap --namespace frontend ``` This will bootstrap a new project with the `namespace: frontend` parameter in the `codeception.yml` file. -Helpers will be in the `frontend\Codeception\Module` namespace and Actor classes will be in the `frontend` namespace. +Actor classes will be in the `frontend\Support` namespace and Helpers will be in the `frontend\Support\Helper` namespace. Once each of your applications (bundles) has its own namespace and different Helper or Actor classes, -you can execute all the tests in a single runner. Run the Codeception tests as usual, using the meta-config we created earlier: +you can execute all the tests in a single runner. Run the Codeception tests as usual, using a meta-config which [includes all applications](#One-Runner-for-Multiple-Applications): ```bash php vendor/bin/codecept run @@ -137,9 +137,10 @@ All listed events are available as constants in `Codeception\Events` class. | `result.print.after` | After result was printed | [Result, Printer](https://github.com/Codeception/Codeception/blob/5.0/src/Codeception/Event/PrintResultEvent.php) There may be some confusion between `test.start`/`test.before` and `test.after`/`test.end`. -The start and end events are triggered by PHPUnit, but the before and after events are triggered by Codeception. -Thus, when you are using classical PHPUnit tests (extended from `PHPUnit\Framework\TestCase`), -the before/after events won't be triggered for them. During the `test.before` event you can mark a test +The start and end events are triggered by the suite around each test, while the before and after events are triggered +from inside the test and are also dispatched per group (see [Group Objects](#Group-Objects)). +All of them are triggered for every kind of test, including classical PHPUnit tests (extended from `PHPUnit\Framework\TestCase`). +During the `test.before` event you can mark a test as skipped or incomplete, which is not possible in `test.start`. You can learn more from [Codeception internal event listeners](https://github.com/Codeception/Codeception/tree/5.0/src/Codeception/Subscriber). @@ -183,13 +184,13 @@ Extensions have some basic methods you can use: * `writeln` - prints to the screen with a new-line character at the end * `getModule` - allows you to access a module * `hasModule` - checks if a module is enabled -* `getModuleNames` - list all enabled modules +* `getCurrentModuleNames` - list all enabled modules * `_reconfigure` - can be implemented instead of overriding the constructor ### Enabling Extension -Once you've implemented a simple extension class, you can require it in `tests/_bootstrap.php`, -load it with Composer's autoloader defined in `composer.json`, or store the class inside `tests/Support`dir. +Once you've implemented a simple extension class, you can require it in a [bootstrap file](#Bootstrap), +load it with Composer's autoloader defined in `composer.json`, or store the class inside `tests/Support` dir. You can then enable it in `codeception.yml` @@ -271,8 +272,6 @@ public function testAdminCreatingNewBlogPost(AcceptanceTester $I) This test will trigger the following events: * `test.before.admin` -* `step.before.admin` -* `step.after.admin` * `test.success.admin` * `test.fail.admin` * `test.after.admin` @@ -281,7 +280,7 @@ A group object is built to listen for these events. It is useful when an additio for some of your tests. Let's say you want to load fixtures for tests that belong to the `admin` group: ```php settings = $settings; } - public function loadTests($filename) + public function loadTests(string $filename): void { //Load file and create tests } - public function getTests() + public function getTests(): array { return $this->tests; } - public function getPattern() + public function getPattern(): string { return '~Myformat\.php$~'; } @@ -535,7 +534,7 @@ settings: ``` -You should also specify the path to the `log` directory, where the reports and logs will be saved. +You should also specify the path to the `output` directory, where the reports and logs will be saved. > Wildcards (`*`) can be used to specify multiple directories at once. diff --git a/docs/Data.md b/docs/Data.md index 9f9a44d20..886639ccf 100644 --- a/docs/Data.md +++ b/docs/Data.md @@ -34,7 +34,7 @@ modules: ```
-Use module parameters +Use module parameters to set the database credentials from environment variables or from application configuration files.
@@ -101,7 +101,7 @@ $I->see('Top 10 Testing Frameworks'); All added records will be deleted at the end of the test. If you want to check that a table record was created -use [`seeInDatabase`](https://codeception.com/docs/modules/Db#haveInDatabase) method: +use [`seeInDatabase`](https://codeception.com/docs/modules/Db#seeInDatabase) method: ```php $I->amOnPage('/posts/1'); @@ -161,7 +161,7 @@ $I->click('Delete'); $I->dontSeeRecord('posts', ['id' => $id]); ``` -Laravel5 module provides the method `have` which uses the [factory](https://laravel.com/docs/9.x/database-testing#creating-models-using-factories) method to generate models with fake data. +[Laravel](https://codeception.com/docs/modules/Laravel) module provides the method `have` which uses the [factory](https://laravel.com/docs/eloquent-factories) method to generate models with fake data. If you want to use ORM for integration testing only, you should enable the framework module with only the `ORM` part enabled: @@ -169,7 +169,7 @@ If you want to use ORM for integration testing only, you should enable the frame modules: enabled: - Laravel: - - part: ORM + part: ORM ``` Similarly for Yii2 framework: @@ -178,7 +178,7 @@ Similarly for Yii2 framework: modules: enabled: - Yii2: - - part: ORM + part: ORM ``` This way no web actions will be added to `$I` object. @@ -227,7 +227,7 @@ Doctrine also provides methods to create and check data: ### DataFactory Preparing data for testing is a very creative, although boring, task. If you create a record, -you need to fill in all the fields of the model. It is much easier to use [Faker](https://github.com/fzaninotto/Faker) +you need to fill in all the fields of the model. It is much easier to use [Faker](https://github.com/FakerPHP/Faker) for this task, which is more effective to set up data generation rules for models. Such a set of rules is called *factories* and are provided by the [DataFactory](https://codeception.com/docs/modules/DataFactory) module. @@ -299,7 +299,7 @@ class Categories extends \Codeception\Snapshot $this->i = $I; } - protected function fetchData() + protected function fetchData(): array|string|false { // fetch texts from all 'a.category' elements on a page return $this->i->grabMultiple('a.category'); @@ -310,7 +310,7 @@ class Categories extends \Codeception\Snapshot Inside a test you can inject the snapshot class and call `assert` method on it: ```php -public function testCategoriesAreTheSame(AcceptanceTester $I, \Tests\Snapshot\Categories $snapshot) +public function testCategoriesAreTheSame(AcceptanceTester $I, \Tests\Support\Snapshot\Categories $snapshot) { $I->amOnPage('/categories'); // if previously saved array of users does not match current set, test will fail @@ -332,7 +332,7 @@ The assertion performed by `assertData` will not display the typical diff output To have the diff displayed when running tests, you can call the snapshot method `shouldShowDiffOnFail`: ```php -public function testCategoriesAreTheSame(AcceptanceTester $I, \Tests\Snapshot\Categories $snapshot) +public function testCategoriesAreTheSame(AcceptanceTester $I, \Tests\Support\Snapshot\Categories $snapshot) { $I->amOnPage('/categories'); // I want to see the diff in case the snapshot data changes @@ -349,7 +349,7 @@ By default, all snapshot files are stored in json format, so if you have to work To fix this, you can call the snapshot method `shouldSaveAsJson(false)` and set the file extension by calling `setSnapshotFileExtension()`: ```php -public function testCategoriesAreTheSame(AcceptanceTester $I, \Tests\Snapshot\Categories $snapshot) +public function testCategoriesAreTheSame(AcceptanceTester $I, \Tests\Support\Snapshot\Categories $snapshot) { // I fetch an HTML page $I->amOnPage('/categories.html'); diff --git a/docs/FunctionalTests.md b/docs/FunctionalTests.md index f58708b04..5783aeb8a 100644 --- a/docs/FunctionalTests.md +++ b/docs/FunctionalTests.md @@ -90,7 +90,7 @@ modules: depends: Symfony # connect to Symfony ``` -By default this module will search for AppKernel in the `app` directory. +By default this module will search for the `App\Kernel` class in the `src` directory. Use the `kernel_class` and `app_path` options to change this. The module uses the Symfony Profiler to provide additional information and assertions. @@ -143,8 +143,8 @@ modules: enabled: - Phalcon5: bootstrap: 'app/config/bootstrap.php' - cleanup: true - savepoints: true + cleanup: true + savepoints: true ``` [See the full reference](https://codeception.com/docs/modules/Phalcon4) @@ -209,7 +209,7 @@ class Functional extends \Codeception\Module { function doSomethingWithMyService() { - $service = $this->getModule('Symfony')->grabServiceFromContainer('myservice'); + $service = $this->getModule('Symfony')->grabService('myservice'); $service->doSomething(); } } @@ -219,7 +219,7 @@ Also check all available *Public Properties* of the used modules to get full acc ## Error Reporting -By default Codeception uses the `E_ALL & ~E_DEPRECATED` error reporting level (PHP < 8.4: `E_ALL & ~E_STRICT & ~E_DEPRECATED`). +By default Codeception uses the `E_ALL & ~E_DEPRECATED` error reporting level. In functional tests you might want to change this level depending on your framework's error policy. The error reporting level can be set in the suite configuration file: diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index c5cf46406..79187a05e 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -80,24 +80,29 @@ This will generate the `SigninCest.php` file inside the `tests/Acceptance` direc ```php 'miles@example.com' ]); $I->see('Thank you for Signing Up!'); - $I->seeEmailIsSent('miles@example.com', 'Thank you for your registration'); + $I->seeEmailIsSent(); $I->seeInDatabase('users', ['email' => 'miles@example.com']); } ``` diff --git a/docs/ModulesAndHelpers.md b/docs/ModulesAndHelpers.md index c7812133d..7f33b8c19 100644 --- a/docs/ModulesAndHelpers.md +++ b/docs/ModulesAndHelpers.md @@ -42,7 +42,7 @@ The FunctionalTester class has its methods defined in modules. Actually, it does but rather acts as a proxy. It knows which module executes this action and passes parameters into it. To make your IDE see all of the FunctionalTester methods, you should run the `codecept build` command. It generates method signatures from enabled modules and saves them into a trait which is included in an actor. -In the current example, the `tests/support/_generated/FunctionalTesterActions.php` file will be generated. +In the current example, the `tests/Support/_generated/FunctionalTesterActions.php` file will be generated. By default, Codeception automatically rebuilds the Actions trait on each change of the suite configuration. ## Standard Modules @@ -64,7 +64,7 @@ it might declare a conflict rule to be used with other modules. For instance, We with all modules implementing the `Codeception\Lib\Interfaces\Web` interface. ```php -public function _conflicts() +public function _conflicts(): string { return 'Codeception\Lib\Interfaces\Web'; } @@ -189,10 +189,10 @@ In your helpers you can use these assertions: function seeCanCheckEverything($thing) { $this->assertTrue(isset($thing), "this thing is set"); - $this->assertFalse(empty($any), "this thing is not empty"); + $this->assertFalse(empty($thing), "this thing is not empty"); $this->assertNotNull($thing, "this thing is not null"); - $this->assertContains("world", $thing, "this thing contains 'world'"); - $this->assertNotContains("bye", $thing, "this thing doesn't contain 'bye'"); + $this->assertStringContainsString("world", $thing, "this thing contains 'world'"); + $this->assertStringNotContainsString("bye", $thing, "this thing doesn't contain 'bye'"); $this->assertEquals("hello world", $thing, "this thing is 'Hello world'!"); // ... } @@ -207,20 +207,20 @@ For example, for your module you might need to access the responses or internal Modules can interact with each other through the `getModule` method. Please note that this method will throw an exception if the required module was not loaded. -Let's imagine that we are writing a module that reconnects to a database. -It's supposed to use the dbh connection value from the Db module. +Let's imagine that we are writing a module that runs a custom query. +It's supposed to use the PDO connection of the Db module. ```php -function reconnectToDatabase() +function seeNumberOfUsers(int $num): void { - $dbh = $this->getModule('Db')->dbh; - $dbh->close(); - $dbh->open(); + $dbh = $this->getModule('Db')->_getDbh(); + $count = (int) $dbh->query('SELECT COUNT(*) FROM users')->fetchColumn(); + $this->assertSame($num, $count); } ``` By using the `getModule` function, you get access to all of the public methods and properties of the requested module. -The `dbh` property was defined as public specifically to be available to other modules. +The `_getDbh()` method was defined as public specifically to be available to other modules. Modules may also contain methods that are exposed for use in helper classes. Those methods start with a `_` prefix and are not available in Actor classes, so can be accessed only from modules and extensions. @@ -242,9 +242,9 @@ function seeNumResults($num) } ``` -In this example we use the API of the facebook/php-webdriver library, -a Selenium WebDriver client the module is build on. -You can also access the `webDriver` property of a module to get access to the `Facebook\WebDriver\RemoteWebDriver` instance +In this example we use the API of the php-webdriver/webdriver library, +a Selenium WebDriver client the module is built on. +You can also access the `webDriver` property of a module to get access to the `Facebook\WebDriver\Remote\RemoteWebDriver` instance for direct Selenium interaction. ### Extending a Module @@ -359,7 +359,7 @@ Here is how it is done in the Db module: ```php class Db extends \Codeception\Module { - protected $requiredFields = ['dsn', 'user', 'password']; + protected array $requiredFields = ['dsn', 'user', 'password']; // ... } ``` @@ -372,8 +372,8 @@ as well as their values. In the WebDriver module we use the default Selenium Ser ```php class WebDriver extends \Codeception\Module { - protected $requiredFields = ['browser', 'url']; - protected $config = ['host' => '127.0.0.1', 'port' => '4444']; + protected array $requiredFields = ['browser', 'url']; + protected array $config = ['host' => '127.0.0.1', 'port' => '4444']; // ... } @@ -390,7 +390,7 @@ modules: browser: 'firefox' - Db: cleanup: false - repopulate: false + populate: false ``` @@ -503,9 +503,9 @@ At the end of a test all configuration changes will be rolled back to the origin ### Runtime Configuration of a Test Sometimes it is needed to set custom configuration for a specific test only. -For [Cest](https://codeception.com/docs/07-AdvancedUsage#Cest-Classes) and [Test\Unit](https://codeception.com/docs/05-UnitTests) +For [Cest](https://codeception.com/docs/AdvancedUsage#Cest-Classes) and [Test\Unit](https://codeception.com/docs/UnitTests) formats you can use `#[Prepare]` attribute which executes the code before other hooks are executed. This allows `#[Prepare]` -to change the module configuration in runtime. `#[Prepare]` uses [dependency injection](https://codeception.com/docs/07-AdvancedUsage#Dependency-Injection) +to change the module configuration in runtime. `#[Prepare]` uses [dependency injection](https://codeception.com/docs/AdvancedUsage#Dependency-Injection) to automatically inject required modules into a method. To run a specific test only in Chrome browser, you can call `_reconfigure` from WebDriver module for a test itself using `#[Prepare]`. @@ -529,7 +529,7 @@ protected function useChrome(\Codeception\Module\WebDriver $webdriver) Prepare methods can invoke all methods of a module, as well as hidden API methods (starting with `_`). Use them to customize the module setup for a specific test. -To change module configuration for a specific group of tests use [GroupObjects](https://codeception.com/docs/08-Customization#Group-Objects). +To change module configuration for a specific group of tests use [GroupObjects](https://codeception.com/docs/Customization#Group-Objects). ## Conclusion diff --git a/docs/ParallelExecution.md b/docs/ParallelExecution.md index c3c2a15e8..2d1b07358 100644 --- a/docs/ParallelExecution.md +++ b/docs/ParallelExecution.md @@ -48,7 +48,7 @@ Splitting test by shards is done automatically with zero-config. However, in thi To get an aggregated report without an extra stage and without managing artifacts use [Testomat.io](https://testomat.io). This is a SaaS platform that can receive test results from different parallel run and show them in the one interface. -![](images/testomatio-report.png) +![](/images/testomatio-report.png) By running tests with Testomat.io reporter attached results will be sent to a centralized server. By default each execution will create its own report. To store results from different shards in one report set the Run title for them. You can use a common environment variable, like number of a build, to create the unique title which will be the same for all jobs. If build id is stored as $BUILDID variable, execution script for shard #3 can be following: @@ -60,7 +60,7 @@ TESTOMATIO={apiKey} TESTOMATIO_TITLE="Build $BUILDID" ./vendor/bin/codecept run While sharding provides a simplified setup for testing the complete pipeline schema may look like this. -![](images/codeception-pipeline.png) +![](/images/codeception-pipeline.png) * On the first stage, tests should be split into groups. The group file should be committed into the repository or passed to next stage as an artifact. * On the second stage tests are executed. XML, HTML, and CodeCoverage reports must be stored as artifacts. @@ -230,7 +230,7 @@ public function parallelRun() $this->taskCodecept() // use built-in Codecept task ->suite('Acceptance') // run acceptance tests ->group("paracept_$i") // for all paracept_* groups - ->xml("tests/_log/result_$i.xml") // save XML results + ->xml("result_paracept_$i.xml") // save XML results to tests/_output ); } return $parallel->run(); diff --git a/docs/UnitTests.md b/docs/UnitTests.md index 75a14d3f9..1367b66a7 100644 --- a/docs/UnitTests.md +++ b/docs/UnitTests.md @@ -107,7 +107,7 @@ There are pretty many assertions you can use inside tests. The most common are: * `$this->assertNull()` * `$this->assertEmpty()` -Assertion methods come from PHPUnit. [See the complete reference at phpunit.de](https://phpunit.de/manual/current/en/appendixes.assertions.html). +Assertion methods come from PHPUnit. [See the complete reference at phpunit.de](https://docs.phpunit.de/en/main/assertions.html). ### Fluent Assertions @@ -461,7 +461,7 @@ $this->assertUserCanPostToBlog($user, $blog); // instead of just calling a bunch of assertions $this->assertNotNull($user); $this->assertNotNull($blog); -$this->assertContain($user, $blog->getOwners()); +$this->assertContains($user, $blog->getOwners()); ``` With custom assertion methods you can improve readability of your tests and keep them focused around the specification. @@ -489,7 +489,7 @@ public function testSingleton() ## Error Reporting -By default Codeception uses the `E_ALL & ~E_DEPRECATED` error reporting level (PHP < 8.4: `E_ALL & ~E_STRICT & ~E_DEPRECATED`). +By default Codeception uses the `E_ALL & ~E_DEPRECATED` error reporting level. In unit tests you might want to change this level depending on your framework's error policy. The error reporting level can be set in the suite configuration file: diff --git a/docs/reference/Configuration.md b/docs/reference/Configuration.md index ccbe12097..253999f9c 100644 --- a/docs/reference/Configuration.md +++ b/docs/reference/Configuration.md @@ -19,7 +19,7 @@ Bootstrap script that will be executed before all suites. A script should be put ### `coverage` -[CodeCoverage](https://codeception.com/docs/11-Codecoverage#Configuration) settings. +[CodeCoverage](https://codeception.com/docs/Codecoverage#Configuration) settings. ### `extends` @@ -27,15 +27,15 @@ Allows you to specify a file (relative to the `codeception.yml` file) that holds ### `extensions` -Allows to enable and configure [Codeception extensions](https://codeception.com/docs/08-Customization#Extension), [Group Objects](https://codeception.com/docs/08-Customization#Group-Objects), and [Custom Commands](https://codeception.com/docs/08-Customization#Custom-Commands). +Allows to enable and configure [Codeception extensions](https://codeception.com/docs/Customization#Extension), [Group Objects](https://codeception.com/docs/Customization#Group-Objects), and [Custom Commands](https://codeception.com/docs/Customization#Custom-Commands). ### `gherkin` -[Gherkin options](https://codeception.com/docs/07-BDD#Configuration). +[Gherkin options](https://codeception.com/docs/BDD#Configuration). ### `include` -Include additional Codeception configurations for [multiple applications setup](https://codeception.com/docs/08-Customization#Namespaces). +Include additional Codeception configurations for [multiple applications setup](https://codeception.com/docs/Customization#Namespaces). ### `modules` @@ -53,11 +53,11 @@ modules: ### `namespace` -Sets the namespace under which all new tests and support classes will be generated. Allows to configure [multiple test setups for one runner](https://codeception.com/docs/08-Customization#Namespaces). +Sets the namespace under which all new tests and support classes will be generated. Allows to configure [multiple test setups for one runner](https://codeception.com/docs/Customization#Namespaces). ### `params` -Allows to pass [external parameters](https://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Parameters) into module configuration. +Allows to pass [external parameters](https://codeception.com/docs/ModulesAndHelpers#Dynamic-Configuration-With-Parameters) into module configuration. ### `paths` @@ -74,11 +74,11 @@ paths: ### `reporters` -Allows to [change default reporters](https://codeception.com/docs/08-Customization#Custom-Reporters) of Codeception +No longer supported since Codeception 5: a warning is printed if this option is set. Custom reporters must be implemented as [extensions](https://codeception.com/docs/Reporting#Custom-Reporter). ### `settings` -Provide additional options for the test runner. They may dramatically change the way Codeception is executed. For instance, take a note of `shuffle` option which allows to randomize tests execution order and `lint` option that toggles parsing a test file (using `php -l`) before loading it. +Provide additional options for the test runner. They may dramatically change the way Codeception is executed. For instance, take a note of `shuffle` option which allows to randomize tests execution order. Syntax example: {% highlight yaml %} @@ -90,21 +90,23 @@ Possible settings: * `backup_globals: true`: Controls whether PHPUnit attempts to backup global variables, see https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.backupGlobals * `be_strict_about_changes_to_global_state: false`: PHPUnit can be strict about tests that manipulate global state, see https://phpunit.de/manual/current/en/risky-tests.html#risky-tests.global-state-manipulation -* `colors: true`: By default this is false on Windows. Use [ANSICON](https://github.com/adoxa/ansicon) to colorize output. +* `colors: true`: Colorize console output. On older Windows consoles you may need [ANSICON](https://github.com/adoxa/ansicon) to display colors. * `convert_deprecations_to_exceptions: false` Converts E_DEPRECATED and E_USER_DEPRECATED events to exceptions. Introduced in Codeception 4.2.0 * `disallow_test_output: false`: PHPUnit can be strict about output during tests, see https://phpunit.de/manual/current/en/risky-tests.html#risky-tests.output-during-test-execution * `editor_url: 'atom://core/open/file?filename=%%file%%&line=%%line%%'`: In the console output, the test runner will replace all references to files with "clickable" URL's, allowing you to open the file directly in your IDE. Depending on your operating system, you may have to set up an appropriate uri handler. Syntax for some common editors (same as in [PHPStan](https://phpstan.org/user-guide/output-format#opening-file-in-an-editor)): * PhpStorm: `'phpstorm://open?file=%%file%%&line=%%line%%'` * Visual Studio Code: `'vscode://file/%%file%%:%%line%%'` * Atom: `'atom://core/open/file?filename=%%file%%&line=%%line%%'` -* `error_level: E_ALL & ~E_DEPRECATED`: Set the error_reporting level. You can specify either a predefined constant or an integer value, see https://www.php.net/manual/en/function.error-reporting.php and https://www.php.net/manual/en/errorfunc.constants.php. For PHP < 8.4 `E_ALL & ~E_STRICT & ~E_DEPRECATED` is used by default. +* `error_level: E_ALL & ~E_DEPRECATED`: Set the error_reporting level. You can specify either a predefined constant or an integer value, see https://www.php.net/manual/en/function.error-reporting.php and https://www.php.net/manual/en/errorfunc.constants.php. `E_STRICT` is deprecated as of PHP 8.4: remove it from your `error_level` if you still reference it, to avoid a deprecation notice. * `memory_limit: 1024M`: Tests (especially functional) can take a lot of memory. We set a high limit for them by default. -* `lint: true`: Enable/disable syntax of test files before loading. For PHP < 7 `exec('php -l')` is used. Disable if you need to speed up tests execution. -* `log_incomplete_skipped: false`: Log the incomplete and skipped tests into junit report ,see https://phpunit.de/manual/current/en/appendixes.configuration.html Section logging > junit * `report_useless_tests: false`: PHPUnit can be strict about tests that do not test anything, see https://phpunit.de/manual/current/en/risky-tests.html#risky-tests.useless-tests -* `shuffle: true`: Randomize test order +* `shuffle: false`: Set to `true` to randomize test order * `strict_xml: false`: Generate XML JUnit report using strict schema. Avoid putting additional report fields like steps or scenario names to it. Required for XML reports on Jenkins CI +### `support_namespace` + +Namespace of support classes (actors, helpers, page objects, step objects etc.), relative to `namespace`. `codecept bootstrap` sets it to `Support`, so actors are generated as `Tests\Support\AcceptanceTester`. + ## Suite Configuration: `Unit.suite.yml`, `Functional.suite.yml` etc. Each suite has its own configuration inside the directory set by `paths: tests: ` in `codeception.yml`. Alphabetical list of options: @@ -119,15 +121,15 @@ Bootstrap script that will be executed before current suite. A script should be ### `coverage` -Per suite [CodeCoverage](https://codeception.com/docs/11-Codecoverage#Configuration) settings. +Per suite [CodeCoverage](https://codeception.com/docs/Codecoverage#Configuration) settings. ### `env` -Override any configuration per [environment](https://codeception.com/docs/07-AdvancedUsage#Environments). +Override any configuration per [environment](https://codeception.com/docs/AdvancedUsage#Environments). ### `error_level` -[error level](https://codeception.com/docs/04-FunctionalTests#Error-Reporting) for runner in the current suite. Can be specified for unit, integration, functional tests. Passes value to `error_reporting` function. +[error level](https://codeception.com/docs/FunctionalTests#Error-Reporting) for runner in the current suite. Can be specified for unit, integration, functional tests. Passes value to `error_reporting` function. ### `extends` @@ -135,15 +137,15 @@ Allows you to specify a file (relative to `*.suite.yml`) that holds some already ### `gherkin` -Per suite [Gherkin](https://codeception.com/docs/07-BDD#Configuration) settings. +Per suite [Gherkin](https://codeception.com/docs/BDD#Configuration) settings. ### `groups` -[groups](https://codeception.com/docs/07-AdvancedUsage#Groups) with the list of tests of for corresponding group. +[groups](https://codeception.com/docs/AdvancedUsage#Groups) with the list of tests of for corresponding group. ### `formats` -[formats](https://codeception.com/docs/07-AdvancedUsage#Formats) with the list of extra test format classes. +[formats](https://codeception.com/docs/Customization#Formats) with the list of extra test format classes. ### `modules` @@ -155,7 +157,7 @@ modules: - PhpBrowser: # built-in modules are listed by their names url: http://localhost # module configuration - Db # Module without configuration (or inherited from `codeception.yml`) - - \Helper\Acceptance # helper names are listed by their class names, starting with `\` + - \Tests\Support\Helper\Acceptance # helper names are listed by their class names, starting with `\` # Additional modules configuration; can be used for modules which are not currently enabled config: @@ -170,15 +172,30 @@ modules: Default namespace of actor, support classes and tests. +### `shuffle` + +Set to `true` to randomize the execution order of tests in the current suite. + +### `step_decorators` + +List of [step decorators](https://codeception.com/docs/Customization#Step-Decorators) used to generate additional actions in the actor class. Set to `~` to disable them. + +{% highlight yaml %} +step_decorators: + - Codeception\Step\ConditionalAssertion + - Codeception\Step\TryTo + - Codeception\Step\Retry +{% endhighlight %} + ### `suite_namespace` -Default namespace for new tests of this suite (ignores `namespace` option) +Namespace of the tests of this suite. It is always computed as `namespace` + `\` + suite name (e.g. `Tests\Acceptance`), so a value set in the suite config is ignored. ## Configuration Templates: `*.dist.yml` To provide the same configuration template for your development team, you can create a `codeception.dist.yml` config file, which will be loaded before `codeception.yml`. The dist config provides shared options, while local `codeception.yml` files override them on a per-installation basis. Therefore, `codeception.yml` should be ignored by your VCS system. -Config templates can also be used for suite configuration, by creating a `suitename.Suite.dist.yml` file. +Config templates can also be used for suite configuration, by creating a `.suite.dist.yml` file (e.g. `Acceptance.suite.dist.yml`). Configuration loading order: diff --git a/for/laravel.md b/for/laravel.md index 3b55cbe70..f16ab6101 100644 --- a/for/laravel.md +++ b/for/laravel.md @@ -142,7 +142,7 @@ modules: depends: Laravel - \Helper\Api config: - - Laravel: + Laravel: environment_file: .env.testing ``` diff --git a/for/phalcon.md b/for/phalcon.md index 2be2084c4..e6dde6840 100644 --- a/for/phalcon.md +++ b/for/phalcon.md @@ -48,10 +48,10 @@ modules: - Asserts - \Helper\Unit - Phalcon4: - bootstrap: public/index.php - cleanup: true - savepoints: true - step_decorators: ~ + bootstrap: public/index.php + cleanup: true + savepoints: true +step_decorators: ~ ``` To generate a plain PHPUnit test for class `Users`, run: @@ -87,10 +87,10 @@ modules: # add a framework module here - \Helper\Functional - Phalcon4: - bootstrap: public/index.php - cleanup: true - savepoints: true - step_decorators: ~ + bootstrap: public/index.php + cleanup: true + savepoints: true +step_decorators: ~ ``` Then use [Cest](https://codeception.com/docs/07-AdvancedUsage) or Cept to create a test. diff --git a/for/symfony.md b/for/symfony.md index 55f093ed0..4b388ab52 100644 --- a/for/symfony.md +++ b/for/symfony.md @@ -1,4 +1,3 @@ - --- layout: page title: Codeception for Symfony @@ -7,6 +6,8 @@ sidebar: | --- + +
See Symfony Module
diff --git a/for/yii.md b/for/yii.md index 592e369e2..86575245c 100644 --- a/for/yii.md +++ b/for/yii.md @@ -136,8 +136,6 @@ modules: url: /api/v1 depends: Yii2 - \ApiBundle\Helper\Api - config: - - Yii2 ``` diff --git a/install.html b/install.html index 59c333e12..9f563b94f 100644 --- a/install.html +++ b/install.html @@ -8,7 +8,7 @@

Installation

Requirements

- PHP 5.6+ + PHP 8.2+ CURL enabled
diff --git a/quickstart.html b/quickstart.html index ad4a57445..b95880c09 100644 --- a/quickstart.html +++ b/quickstart.html @@ -81,9 +81,15 @@

4. Write a Basic Test

{% highlight php %} amOnPage('/'); $I->see('Home');