diff --git a/docs/AcceptanceTests.md b/docs/AcceptanceTests.md index 7c73cb36d..48e169313 100644 --- a/docs/AcceptanceTests.md +++ b/docs/AcceptanceTests.md @@ -361,33 +361,37 @@ In the next section, we will overview the most popular solutions. ### Local Setup -### Selenium Server +Codeception can control browsers either through Selenium Server or directly through a browser driver +(ChromeDriver for Chrome, GeckoDriver for Firefox). -[Selenium](https://www.selenium.dev) is required to launch and control browsers from Codeception. -Selenium Server is required to be installed and started before running tests. +#### Selenium Server -The fastest way of getting Selenium is using [selenium-standalone](https://www.npmjs.com/package/selenium-standalone) NodeJS Package. -It automatically installs Selenium and all required dependencies and starts server. It requires **NodeJS and Java** to be installed. +[Selenium](https://www.selenium.dev) Server starts browser sessions and passes commands from Codeception to them. +It requires **Java** to be installed. [Download](https://www.selenium.dev/downloads/) the latest Selenium Server jar +and launch it in standalone mode in a separate terminal: -``` -npm install selenium-standalone -g -selenium-standalone install +```bash +java -jar selenium-server-.jar standalone ``` -Launch this command in a separate terminal: +There is no need to install ChromeDriver or GeckoDriver separately: +[Selenium Manager](https://www.selenium.dev/documentation/selenium_manager/) downloads the matching driver for the installed browser automatically. -``` -selenium-standalone start +Alternatively, run Selenium Server with a browser inside Docker using the [official image](https://github.com/SeleniumHQ/docker-selenium): + +```bash +docker run --net=host --shm-size 2g selenium/standalone-chrome ``` -![](https://raw.githubusercontent.com/webdriverio/selenium-standalone/HEAD/screencast.gif) +> The [RunProcess](https://codeception.com/extensions#RunProcess) extension can start and stop Selenium automatically. Now, you are ready to run WebDriver tests using Codeception. -> Alternatively, Selenium Server can be installed manually. [Download it](https://www.selenium.dev/downloads/) from the official site and launch a server with Java: `java -jar selenium-server-....jar`. In this case ChromeDriver and GeckoDriver must be installed separately. +#### ChromeDriver or GeckoDriver -* For more information refer to [Installation Instructions](https://codeception.com/docs/modules/WebDriver#Selenium-Recommended) -* Enable [RunProcess](https://codeception.com/extensions#RunProcess) extension to start/stop Selenium automatically *(optional)*. +If you don't plan to use Selenium, tests can be executed directly through ChromeDriver or GeckoDriver. +In this case the driver must be installed and started before running tests. +See the [WebDriver module reference](https://codeception.com/docs/modules/WebDriver#Local-Chrome-andor-Firefox) for how to start each driver and configure the module. ### Configuration @@ -557,7 +561,7 @@ For more options see [`performOn()` reference](https://codeception.com/docs/modu When a web site acts unpredictably you may need to react to that change. This happens if a site is configured for A/B testing, or shows different popups, based on environment. -Since Codeception 3.0 you can have some actions to fail silently, if they are errored. +You can have some actions to fail silently, if they are errored. Let's say, you open a page and sometimes there is a popup which should be closed. We may try to hit the "close" button but if this action fails (no popup on page) we just continue the test. @@ -634,8 +638,8 @@ class AcceptanceTester extends \Codeception\Actor ### Cloud Testing -Some environments are hard to reproduce manually, testing Internet Explorer 6-8 on Windows XP may be a hard thing, -especially if you don't have Windows XP installed. This is where Cloud Testing services come to help you. +Some environments are hard to reproduce manually, testing Safari on macOS or browsers on mobile devices may be a hard thing, +especially if you don't have such a device. This is where Cloud Testing services come to help you. Services such as [SauceLabs](https://saucelabs.com), [BrowserStack](https://www.browserstack.com/) and [others](https://codeception.com/docs/modules/WebDriver#Cloud-Testing) can create virtual machines on demand and set up Selenium Server and the desired browser. Tests are executed on a remote machine in a cloud, diff --git a/docs/BDD.md b/docs/BDD.md index ad0665928..e1805ff88 100644 --- a/docs/BDD.md +++ b/docs/BDD.md @@ -170,7 +170,7 @@ Scenario -- INCOMPLETE Step definition for `I have product with $600 price in my cart` not found in contexts -Step definition for `I have product with $1000 price` not found in contexts +Step definition for `I have product with $1000 price in my cart` not found in contexts Step definition for `I go to checkout process` not found in contexts Step definition for `I should see that total number of products is 2` not found in contexts Step definition for `my order amount is $1600` not found in contexts @@ -292,7 +292,7 @@ class AcceptanceTester extends \Codeception\Actor ``` Please note that `:num1` placeholder can be used for strings and numbers (may contain currency sign). -In current case `:num1` matches `$600` and `$num1` is assigned to be 600. If you need to receive exact string, wrap the value into quotes: `"600$"` +In current case `:num1` matches `$600` and `$num1` is assigned to be 600. If you need to receive exact string, wrap the value into quotes: `"$600"` By default they throw Incomplete exceptions to ensure test with missing steps won't be accidentally marked as successful. We will need to implement those steps. As we are in acceptance suite we are probably using [PhpBrowser](https://codeception.com/docs/modules/PhpBrowser) or [WebDriver](https://codeception.com/docs/modules/WebDriver) modules. This means that we can use their methods inside Tester file, as we do with writing tests using `$I->`. You can use `amOnPage`, `click`, `see` methods inside a step definitions, so each Gherkin scenario step to be extended with basic Codeception steps. Let's show how it can be implemented in our case: diff --git a/docs/Codecoverage.md b/docs/Codecoverage.md index 2529f9dad..7cf18f3c6 100644 --- a/docs/Codecoverage.md +++ b/docs/Codecoverage.md @@ -39,9 +39,6 @@ That's ok for now. But what files should be present in final coverage report? Pass an array of files or directory to include/exclude sections. The path ending with '\*' matches the directory. Also you can use '\*' mask in a file name, i.e. `app/models/*Model.php` to match all models. -There is a shortcut if you don't need that complex filters: - - ```yaml coverage: enabled: true diff --git a/docs/ContinuousIntegration.md b/docs/ContinuousIntegration.md index 86a8a3f8d..a1c98f9ab 100644 --- a/docs/ContinuousIntegration.md +++ b/docs/ContinuousIntegration.md @@ -101,7 +101,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Install PHP uses: shivammathur/setup-php@v2 with: diff --git a/docs/Customization.md b/docs/Customization.md index ab2d1c2df..52e5248c1 100644 --- a/docs/Customization.md +++ b/docs/Customization.md @@ -28,7 +28,7 @@ you can execute all the tests in a single runner. Run the Codeception tests as u php vendor/bin/codecept run ``` -This will launch the test suites for all three applications and merge the reports from all of them. +This will launch the test suites for all included applications and merge the reports from all of them. This is very useful when you run your tests on a Continuous Integration server and you want to get a single report in JUnit and HTML format. The code coverage report will be merged too. @@ -119,6 +119,8 @@ All listed events are available as constants in `Codeception\Events` class. | Event | When? | Triggered by |:--------------------:| --------------------------------------- | --------------------------: +| `module.init` | Before modules are initialized | [Suite, Settings](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/SuiteEvent.php) +| `suite.init` | After modules are initialized | [Suite, Settings](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/SuiteEvent.php) | `suite.before` | Before suite is executed | [Suite, Settings](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/SuiteEvent.php) | `test.start` | Before test is executed | [Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php) | `test.before` | At the very beginning of test execution | [Codeception Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php) @@ -129,6 +131,8 @@ All listed events are available as constants in `Codeception\Events` class. | `test.error` | After test ended with error | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php) | `test.incomplete` | After executing incomplete test | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php) | `test.skipped` | After executing skipped test | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php) +| `test.warning` | After test ended with warning | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php) +| `test.useless` | After test performed no assertions | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php) | `test.success` | After executing successful test | [Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php) | `test.after` | At the end of test execution | [Codeception Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php) | `test.end` | After test execution | [Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php) @@ -234,7 +238,7 @@ extensions: The passed in configuration is accessible via the `config` property: `$this->config['param']`. -Check out a very basic extension [Notifier](https://github.com/Codeception/Notifier). +Check out the [extensions shipped with Codeception](https://github.com/Codeception/Codeception/tree/main/ext) for examples. ### Custom Commands diff --git a/docs/Data.md b/docs/Data.md index 069ac5fbe..be76b2957 100644 --- a/docs/Data.md +++ b/docs/Data.md @@ -203,7 +203,7 @@ modules: Doctrine is also a popular ORM, unlike some others it implements the DataMapper pattern and is not bound to any framework. The [Doctrine](https://codeception.com/docs/modules/Doctrine) module requires an `EntityManager` instance to work with. -It can be obtained from a Symfony framework or Zend Framework (configured with Doctrine): +It can be obtained from a Symfony framework or Laminas (configured with Doctrine): ```yaml modules: diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 748a7bb6f..db230263b 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -291,8 +291,10 @@ There are plenty of useful Codeception commands: * `generate:helper` *filename* - Generates a sample Helper File * `generate:pageobject` *suite* *filename* - Generates a sample Page object * `generate:stepobject` *suite* *filename* - Generates a sample Step object +* `generate:snapshot` *suite* *filename* - Generates a sample Snapshot class * `generate:environment` *env* - Generates a sample Environment configuration * `generate:groupobject` *group* - Generates a sample Group Extension +* `generate:scenarios` *suite* - Generates text representation for all scenarios ## Conclusion diff --git a/docs/ModulesAndHelpers.md b/docs/ModulesAndHelpers.md index 578c62971..f7ffd0e55 100644 --- a/docs/ModulesAndHelpers.md +++ b/docs/ModulesAndHelpers.md @@ -401,7 +401,7 @@ Use `$this->config['parameter']` to get its value. Modules can be dynamically configured from environment variables. Parameter storage should be specified in the global `codeception.yml` configuration inside the `params` section. -Parameters can be loaded from environment vars, from yaml (Symfony format), .env (Laravel format), ini, or php files. +Parameters can be loaded from environment vars, from yaml (Symfony format), .env (Laravel format), ini, php, or xml files. Use the `params` section of the global configuration file `codeception.yml` to specify how to load them. You can specify several sources for parameters to be loaded from. @@ -413,11 +413,11 @@ params: - env # load params from environment vars ``` -Example: load parameters from YAML file (Symfony): +Example: load parameters from YAML file: ```yaml params: - - app/config/parameters.yml + - config/parameters.yml ``` Example: load parameters from php file (Yii) @@ -427,6 +427,13 @@ params: - config/params.php ``` +Example: load parameters from XML file: + +```yaml +params: + - config/parameters.xml +``` + Example: load parameters from .Env files (Laravel): ```yaml diff --git a/docs/ParallelExecution.md b/docs/ParallelExecution.md index c3c520969..5180df135 100644 --- a/docs/ParallelExecution.md +++ b/docs/ParallelExecution.md @@ -15,7 +15,7 @@ In this guide we will overview possible options. ## Sharding Minimal setup can be implemented by executing several independent CI jobs, each running a part of the tests. -Sharding in Codeception allows to combine stages 1 and 2 so tests could be split by groups on the fly. +Sharding in Codeception allows to combine the splitting and running stages (see [Building Pipeline](#Building-Pipeline)) so tests could be split by groups on the fly. In this case a pipeline could be simplified to one stage with several jobs. ![](/images/codeception-sharding.png) @@ -142,7 +142,7 @@ parallel:merge-results #### Step 1: Split Tests -Codeception can organize tests into [groups](https://codeception.com/docs/AdvancedUsage#Groups). Starting from 2.0 it can load information about a group from a file. Sample text file with a list of file names can be treated as a dynamically configured group. Take a look into sample group file: +Codeception can organize tests into [groups](https://codeception.com/docs/AdvancedUsage#Groups). It can load information about a group from a file. Sample text file with a list of file names can be treated as a dynamically configured group. Take a look into sample group file: ```bash @@ -212,7 +212,7 @@ php vendor/bin/codecept run Acceptance -g paracept_2 #### Step 2: Running Tests -At this point you should decide if tests are executed on the same job or use multiple jobs for them. We recommend using multiple jobs, as in this case the burden of parallelization goes to CI server. This makes a lot of sense as a single machine has limited resources. If you split tests into CI jobs, you are limited only to the number of agents (build servers) that the CI can provide. For cloud-based services like GitHub Actions, GitLab CI, CircleCI, etc, this number is unlimited. +At this point you should decide if tests are executed on the same job or use multiple jobs for them. We recommend using multiple jobs, as in this case the burden of parallelization goes to CI server. This makes a lot of sense as a single machine has limited resources. If you split tests into CI jobs, you are limited only to the number of agents (build servers) that the CI can provide. For cloud-based services like GitHub Actions, GitLab CI, CircleCI, etc, this number depends on your plan. > Please refer to documentation of your CI platform to learn how to set up multiple jobs running in parallel. Then proceed to merging of results. diff --git a/docs/Reporting.md b/docs/Reporting.md index ccbd0266d..390b589b3 100644 --- a/docs/Reporting.md +++ b/docs/Reporting.md @@ -3,9 +3,7 @@ layout: doc title: Reporting - Codeception Docs --- - - -## Reporting +# Reporting Clear reports give a picture of the current state of the system. Which tests are passed, which tests are failed, and if failed what was the reason. Reports may vary on the level of detail and by the technical information collected. Codeception provides built-in reporters and a customizable API to create your own reporter. diff --git a/docs/ReusingTestCode.md b/docs/ReusingTestCode.md index 39799f589..cf6798938 100644 --- a/docs/ReusingTestCode.md +++ b/docs/ReusingTestCode.md @@ -84,12 +84,12 @@ This trait was created by running `codecept build` and is regenerated each time ## PageObjects -For acceptance and functional testing, we will not only need to have common actions being reused across different tests, +For acceptance testing, we will not only need to have common actions being reused across different tests, we should have buttons, links and form fields being reused as well. For those cases we need to implement the [PageObject pattern](https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/), which is widely used by test automation engineers. The PageObject pattern represents a web page as a class and the DOM elements on that page as its properties, and some basic interactions as its methods. -PageObjects are very important when you are developing a flexible architecture of your acceptance or functional tests. +PageObjects are very important when you are developing a flexible architecture of your acceptance tests. Do not hard-code complex CSS or XPath locators in your tests but rather move them into PageObject classes. Codeception can generate a PageObject class for you with command: diff --git a/docs/UnitTests.md b/docs/UnitTests.md index 219fd79d3..3872bfca5 100644 --- a/docs/UnitTests.md +++ b/docs/UnitTests.md @@ -394,8 +394,9 @@ you will have issues figuring out what tests will be affected by the introductio That's why it's pretty important not just to cover your application with unit tests, but make unit tests self-explanatory. We do this for scenario-driven acceptance and functional tests, and we should do this for unit and integration tests as well. -For this case we have a stand-alone project [Specify](https://github.com/Codeception/Specify) -(which is included in the phar package) for writing specifications inside unit tests: +For this case we have a stand-alone project [Specify](https://github.com/Codeception/Specify) for writing specifications inside unit tests: + +> Specify supports only PHPUnit 8 and 9. ```php DomainAssert supports only PHPUnit 7 to 9. + It allows to reuse business rules inside assertion methods: ```php @@ -471,6 +474,8 @@ With custom assertion methods you can improve readability of your tests and keep Static methods, class methods, date and time functions can be easily replaced with AspectMock. For instance, you can test singletons! +> The latest AspectMock release requires PHP 7.4 and PHPUnit 9, so it can't be installed together with Codeception 5. + ```php - Continue to Functional Testing Guide » + Continue to Functional Testing Guide » Codeception will also use **Eloquent to cleanup changes to database** by wrapping tests into transaction and rolling it back in the end of a test. This makes tests isolated and fast. Laravel module allows to access services from DIC container, user authentication methods, fixture generators, check form validations and more. @@ -69,7 +68,7 @@ Codeception will also use **Eloquent to cleanup changes to database** by wrappin To create first functional test for `Login` you should run: ``` -php vendor/bin/codecept g:cest functional Login +php vendor/bin/codecept g:cest Functional Login ``` ## Unit Tests @@ -84,7 +83,7 @@ Enable Laravel module in `Unit.suite.yml` to have its methods inside a testcase.
- Continue to Unit Testing Guide ». + Continue to Unit Testing Guide ».
@@ -93,13 +92,12 @@ Enable Laravel module in `Unit.suite.yml` to have its methods inside a testcase. To test an application in a real environment by using its UI you should use a real browser. Codeception uses Selenium Webdriver and corresponding WebDriver module to interact with a browser. You should configure `Acceptance.suite.yml` to use WebDriver module and a browser of your choice. ```yaml -class_name: AcceptanceTester +actor: AcceptanceTester modules: enabled: - WebDriver: url: 'https://localhost/' # put your local url browser: firefox - - \Helper\Acceptance ``` Browser can be specified as `firefox`, `chrome`, or others. @@ -109,7 +107,7 @@ Acceptance tests will be executed in development environment using real web serv You can also use Eloquent to create data for acceptance tests. This way you can use data factories and models to prepare and cleanup data for tests. You should enable Laravel module with ORM part to add ActiveRecord methods: ```yaml -class_name: AcceptanceTester +actor: AcceptanceTester modules: enabled: - WebDriver: @@ -118,7 +116,6 @@ modules: - Laravel: part: ORM cleanup: false # can't wrap into transaction - - \Helper\Acceptance ``` Laravel module won't be able to wrap test execution in a transaction but methods like `haveRecord` or `haveModel` will delete objects they created when test ends. @@ -128,19 +125,18 @@ Laravel module won't be able to wrap test execution in a transaction but methods API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests you should create a suite for them ``` -php vendor/bin/codecept g:suite api +php vendor/bin/codecept g:suite Api ``` -You will need to enable `REST`, `Laravel` module in `tests/api.suite.yml`: +You will need to enable `REST`, `Laravel` module in `tests/Api.suite.yml`: ```yaml -class_name: ApiTester +actor: ApiTester modules: enabled: - REST: url: /api/v1 depends: Laravel - - \Helper\Api config: Laravel: environment_file: .env.testing @@ -152,7 +148,7 @@ Laravel module actions like `amOnPage` or `see` should not be available for test
- Continue to REST API Testing Guide ». + Continue to REST API Testing Guide ».
### BDD @@ -175,5 +171,5 @@ In the same manner features can be set up as functional tests.
- Continue to Behavior Driven Development Guide » + Continue to Behavior Driven Development Guide »
diff --git a/for/phalcon.md b/for/phalcon.md index e6dde6840..c68118cac 100644 --- a/for/phalcon.md +++ b/for/phalcon.md @@ -46,7 +46,6 @@ actor: UnitTester modules: enabled: - Asserts - - \Helper\Unit - Phalcon4: bootstrap: public/index.php cleanup: true @@ -64,7 +63,7 @@ Actions of the Phalcon module will be accessible from `$this->tester` inside a t
- Continue to Unit Testing Guide ». + Continue to Unit Testing Guide ».
## Functional Tests @@ -85,7 +84,6 @@ actor: FunctionalTester modules: enabled: # add a framework module here - - \Helper\Functional - Phalcon4: bootstrap: public/index.php cleanup: true @@ -93,7 +91,7 @@ modules: step_decorators: ~ ``` -Then use [Cest](https://codeception.com/docs/07-AdvancedUsage) or Cept to create a test. +Then use [Cest](https://codeception.com/docs/AdvancedUsage) or Cept to create a test. ``` vendor/bin/codecept g:cest Functional Login ``` @@ -133,7 +131,7 @@ class LoginCest
- Continue to Functional Testing Guide » + Continue to Functional Testing Guide »
### Acceptance Testing @@ -141,16 +139,15 @@ class LoginCest Sample configuration of `tests/Acceptance.suite.yml`: ```yaml -class_name: AcceptanceTester +actor: AcceptanceTester modules: enabled: - WebDriver: url: 'https://localhost/' # put your local url browser: chrome - - \Helper\Acceptance ``` -Browser can be specified as `chrome`, `firefox`, `phantomjs`, or others. +Browser can be specified as `chrome`, `firefox`, or others. To create a sample test called, run: @@ -162,7 +159,7 @@ This will create the file `tests/Acceptance/LoginCest.php`. Each method of a cla
- Continue to Acceptance Testing Guide » + Continue to Acceptance Testing Guide »
To run the tests you will need chrome browser, [selenium server running](https://codeception.com/docs/modules/WebDriver#Selenium). If this requirements met acceptance tests can be executed as @@ -173,13 +170,13 @@ vendor/bin/codecept run Acceptance ### BDD -If you prefer to describe application with feature files, Codeception can turn them to acceptance tests. It is recommended to store feature files in `features` directory (like Behat does it) but symlinking it to `tests/acceptance/features` so they can be treated as tests too. +If you prefer to describe application with feature files, Codeception can turn them to acceptance tests. It is recommended to store feature files in `features` directory (like Behat does it) but symlinking it to `tests/Acceptance/features` so they can be treated as tests too. ``` ln -s $PWD/features tests/Acceptance ``` -Codeception allows to combine tests written in different formats. If you are about to write a regression test it probably should not be described as a product's feature. That's why feature-files are a subset of all acceptance tests, and they are stored in subfolder of `tests/acceptance`. +Codeception allows to combine tests written in different formats. If you are about to write a regression test it probably should not be described as a product's feature. That's why feature-files are a subset of all acceptance tests, and they are stored in subfolder of `tests/Acceptance`. There are no standard Gherkin steps built in. By writing your feature files you can get code snippets which should be added to `AcceptanceTester` class. @@ -189,7 +186,7 @@ vendor/bin/codecept gherkin:snippets
- Continue to Behavior Driven Development Guide » + Continue to Behavior Driven Development Guide »
### API Tests @@ -197,13 +194,13 @@ vendor/bin/codecept gherkin:snippets API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests, you should create a suite for them: ``` -vendor/bin/codecept g:suite api +vendor/bin/codecept g:suite Api ``` -You will need to enable `REST` and `Phalcon` module in `tests/api.suite.yml`: +You will need to enable `REST` and `Phalcon` module in `tests/Api.suite.yml`: ```yaml -class_name: ApiTester +actor: ApiTester modules: enabled: - Phalcon4: @@ -213,7 +210,6 @@ modules: - REST: url: /v1 depends: Phalcon4 - - \Helper\Api ``` Phalcon [module](/docs/modules/Phalcon4) actions like `amOnPage` or `see` should not be available for testing API. This is why Phalcon module is not enabled but declared with `depends` for REST module. But Phalcon module should be configured to load Kernel class from `app_path`. @@ -221,7 +217,7 @@ Phalcon [module](/docs/modules/Phalcon4) actions like `amOnPage` or `see` should
- Continue to REST API Testing Guide ». + Continue to REST API Testing Guide ».
[Edit this page on GitHub](https://github.com/Codeception/codeception.github.com/blob/master/for/phalcon.md) diff --git a/for/yii.md b/for/yii.md index 86575245c..ae55ebbd0 100644 --- a/for/yii.md +++ b/for/yii.md @@ -38,7 +38,7 @@ Run them by executing in terminal: Unit tests are located in `tests/Unit` directory and are supposed to contain all kind of unit and integration testing. Each test case extends `Codeception\Test\Unit` class, which is standard Codeception format for unit testing. - It is pretty hard to develop completely isolated unit tests in Yii, so an application is bootstrapped before each test case. Tests are configured in `tests/unit.suite.yml` file with Yii2 module enabled: + It is pretty hard to develop completely isolated unit tests in Yii, so an application is bootstrapped before each test case. Tests are configured in `tests/Unit.suite.yml` file with Yii2 module enabled: ```yaml modules: @@ -79,11 +79,11 @@ $this->tester->haveFixtures([ $this->tester->grabFixture('user', 0); ``` -If `Yii2` module is enabled you can safely call `Yii::$app` inside a test, as application is initialized and cleaned up after a test. If you want to add your helper methods or custom assertions for your test case you should not extend `Codeception\Test\Unit` but write your own separate [Helper class](https://codeception.com/docs/06-ModulesAndHelpers#Helpers). +If `Yii2` module is enabled you can safely call `Yii::$app` inside a test, as application is initialized and cleaned up after a test. If you want to add your helper methods or custom assertions for your test case you should not extend `Codeception\Test\Unit` but write your own separate [Helper class](https://codeception.com/docs/ModulesAndHelpers#Helpers).
- Continue to Unit Testing Guide » + Continue to Unit Testing Guide »
@@ -106,44 +106,54 @@ $I->see('Body cannot be blank'); This way you not only test the ContactForm on a site but actual output of application that user sees. Codeception provides standard set of actions like `amOnPage`, `submitForm`, `see` for testing. Yii2 module provides special methods, like `amLoggedInAs` (for fast authentication), `haveRecord`, `seeRecord`, `seeEmailIsSent` and others. They all are listed in [module reference](https://codeception.com/docs/modules/Yii2). -Functional tests should be written inside [Cest files](https://codeception.com/docs/07-AdvancedUsage#Cest-Classes), which is a scenario-driven test format of Codeception. You can easily create a new test by running: +Functional tests should be written inside [Cest files](https://codeception.com/docs/AdvancedUsage#Cest-Classes), which is a scenario-driven test format of Codeception. You can easily create a new test by running: ``` -./vendor/bin/codecept g:cest functional MyNewScenarioCest +./vendor/bin/codecept g:cest Functional MyNewScenarioCest ```
Functional tests are really powerful and simple. They are highly recommended to use for any Yii application.
- Continue to Functional Testing Guide » + Continue to Functional Testing Guide »
### API Tests -API tests are not included in any Yii templates so you need to set up them manually if you developing a web service. API testing is done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To start writing api tests you should create a suite for them +API tests are not included in any Yii templates so you need to set them up manually if you are developing a web service. API testing is done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. API tests require the REST module, which is not installed by default: ``` -./vendor/bin/codecept g:suite api +composer require codeception/module-rest --dev ``` -You will need to enable `REST`, `Yii2` module in `tests/api.suite.yml`: +To start writing API tests you should create a suite for them: + +``` +./vendor/bin/codecept g:suite Api +``` + +You will need to enable the `REST` module in `tests/Api.suite.yml`: ```yaml -class_name: ApiTester +actor: ApiTester modules: enabled: - REST: url: /api/v1 depends: Yii2 - - \ApiBundle\Helper\Api - ``` -Yii2 module actions like `amOnPage` or `see` should not be available for testing API. This is why Yii2 module is not enabled but declared with `depends` for REST module. +Yii2 module actions like `amOnPage` or `see` should not be available for testing API. This is why Yii2 module is not enabled but declared with `depends` for REST module. The `configFile` for Yii2 is taken from the global `codeception.yml`, so it doesn't need to be repeated here. + +Run `./vendor/bin/codecept build` after changing the enabled modules, then create your first API test: + +``` +./vendor/bin/codecept g:cest Api CreateUserCest +```
- Continue to REST API Testing Guide ». + Continue to REST API Testing Guide ».
### Acceptance Tests @@ -164,10 +174,10 @@ Then you will need to launch application server in test mode: ./tests/bin/yii serve ``` -and start a [Selenium Server](https://codeception.com/docs/modules/WebDriver#Local-Testing). For acceptance WebDriver module is used. Please check its reference to learn how to work with it. Unlike Yii2 module it does know nothing about your application, so if you want to use features of Yii like fixtures for acceptance testing, you should check that enable Yii2 module is enabled as well: +and start a [Selenium Server](https://codeception.com/docs/modules/WebDriver#Selenium-Recommended). For acceptance WebDriver module is used. Please check its reference to learn how to work with it. Unlike Yii2 module it does know nothing about your application, so if you want to use features of Yii like fixtures for acceptance testing, you should check that enable Yii2 module is enabled as well: ```yml -# config at tests/Acceptance.yml +# config at tests/Acceptance.suite.yml modules: enabled: - WebDriver: @@ -189,7 +199,7 @@ Similar as for functional tests it is recommended to use Cest format for accepta
- Continue to Acceptance Testing Guide » + Continue to Acceptance Testing Guide »
## Yii Advanced @@ -202,7 +212,7 @@ Tests also include namespaces for testcase classes and testers to avoid conflict
- Learn more about testing multiple applications » + Learn more about testing multiple applications »
## Manual Setup && Configuration