|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Codeception 2.3" |
| 4 | +date: 2017-05-22 01:03:50 |
| 5 | +--- |
| 6 | + |
| 7 | +Today the Codeception 2.3 sees the world. This is a stable release with almost no breaking changes but with new features you will probably like. |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +At first, we need to say "thank you" to [Luis Montealegre](https://github.com/MontealegreLuis) for bringing **PHPUnit 6.0 support** to Codeception. This is done by using class aliases so this doesn't break old PHPUnit versions, so as usual, Codeception can be used with PHPUnit 4.8 and higher. However, If you run PHP7+ and you experience PHPUnit issues in this release we recommend you to set `phpunit/phpunit` package to `^5.7.0` in your composer.json. |
| 14 | + |
| 15 | +Supporting 3 major versions of PHPUnit may have its issues, so in next release, which is going to be 3.0 we will probably drop support for old PHPUnits and PHP < 7. |
| 16 | + |
| 17 | +Ok, let's talk about other changes in this release! |
| 18 | + |
| 19 | + |
| 20 | +## Installation Templates |
| 21 | + |
| 22 | +Codeception is a wide-range testing framework and sometimes it is hard to get it configured for a specific case. Nevertheless, you need only acceptance testing Codeception will still install all 3 test suites for you. In 2.3 we prepared installation templates: customized setup wizards that can configure tests for your needs. |
| 23 | + |
| 24 | +To setup Codeception for acceptance testing with browser only you can run this command |
| 25 | + |
| 26 | +``` |
| 27 | +codecept init acceptance |
| 28 | +``` |
| 29 | + |
| 30 | +After answering a few questions, you will be able to execute first browser test |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +The setup wizard will prepare only `acceptance` test suite with tests located in `tests` directory. Suite configuration will be stored in `codeception.yml`. |
| 35 | + |
| 36 | +**For QA engineers `codecept init acceptance` is a new convenient way to start end-to-end testing in PHP**. |
| 37 | + |
| 38 | +We also included API and Unit templates for faster setup of REST API or unit tests: |
| 39 | + |
| 40 | +``` |
| 41 | +codecept init api |
| 42 | +codecept init unit |
| 43 | +``` |
| 44 | + |
| 45 | +But the best thing about installation templates that they can be created by anyone! They can be placed inside a separate package and loaded by `init` command. A template class should be placed into `Codeception\Template` namespace and then it can be autoloaded. Installation templates are pretty simple, learn how to build your own by taking a look at [Acceptance template as an example](https://github.com/Codeception/Codeception/blob/master/src/Codeception/Template/Acceptance.php#L67). |
| 46 | + |
| 47 | +## Configuration Improvements |
| 48 | + |
| 49 | +#### Suites Inside Main Config |
| 50 | + |
| 51 | +Suites can be defined inside main config: |
| 52 | + |
| 53 | +```yaml |
| 54 | +actor_suffix: Tester |
| 55 | +paths: |
| 56 | + tests: . |
| 57 | + log: _output |
| 58 | + data: _data |
| 59 | + support: _support |
| 60 | +suites: |
| 61 | + unit: |
| 62 | + path: . |
| 63 | + actor: UnitTester |
| 64 | + modules: |
| 65 | + enabled: |
| 66 | + - Asserts |
| 67 | +``` |
| 68 | +
|
| 69 | +A good option if you have a single suite. |
| 70 | +
|
| 71 | +#### Suite Paths |
| 72 | +
|
| 73 | +The suite can have its custom path (specified by `path`). From config above expects unit tests to be placed into the root directory, where codeception.yml is located (`path: tests: .` and `path: ``) |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +#### Suites With No Actor |
| 78 | + |
| 79 | +Suite can be defined without an actor, which is useful for unit testing |
| 80 | + |
| 81 | +```yaml |
| 82 | +paths: |
| 83 | + tests: tests |
| 84 | + log: tests/_output |
| 85 | + data: tests/_data |
| 86 | + support: tests/_support |
| 87 | + envs: tests/_envs |
| 88 | +suites: |
| 89 | + unit: |
| 90 | + path: . |
| 91 | + modules: |
| 92 | + enabled: |
| 93 | + - Asserts |
| 94 | +``` |
| 95 | + |
| 96 | +In this case, UnitTester won't be created, as well as `_generated/UnitActions`. However, such suites won't be able to have Cest and Cept files generated. |
| 97 | + |
| 98 | +#### Naming Changes |
| 99 | + |
| 100 | +`class_name` suite in suite config replaced with `actor`: |
| 101 | + |
| 102 | +``` |
| 103 | +class_name: UnitTester => actor: UnitTester |
| 104 | +``` |
| 105 | + |
| 106 | +`actor` from global config is replaced with `actor_suffix` config option (which makes more sense). |
| 107 | + |
| 108 | +All these changes are backward compatible, so old values in config will work. |
| 109 | + |
| 110 | +## Extensions |
| 111 | + |
| 112 | +Dynamical loading of extensions was already with `--override` option but was not very usable. Now extensions can be loaded with `--ext` option: |
| 113 | + |
| 114 | +```bash |
| 115 | +codecept run --ext Recorder |
| 116 | +``` |
| 117 | + |
| 118 | +or by providing a full class name |
| 119 | + |
| 120 | +``` |
| 121 | +codecept run --ext "Codeception\Extension\Recorder" |
| 122 | +``` |
| 123 | +
|
| 124 | +This can be used to enable a custom reporter. For this reason, the new [DotReporter](http://codeception.com/extensions#DotReporter) has been added: |
| 125 | +
|
| 126 | +``` |
| 127 | +codecept run --ext DotReporter |
| 128 | +``` |
| 129 | +
|
| 130 | + |
| 131 | +
|
| 132 | +## Db Populator |
| 133 | +
|
| 134 | +From the early days of Codeception we had the Db module which was trying to do its best to populate database and clean up it between tests. However, parsing all possible SQL dialects and running them through PHP was not very effective. What if you could use native Database tools to import data instead of doing it from PHP? Why not! |
| 135 | +
|
| 136 | +In Codeception 2.3 we recommend to specify a command to load a database in `populator` option of Db module: |
| 137 | +
|
| 138 | +
|
| 139 | +```yaml |
| 140 | + modules: |
| 141 | + enabled: |
| 142 | + - Db: |
| 143 | + dsn: 'mysql:host=localhost;dbname=testdb' |
| 144 | + user: 'root' |
| 145 | + password: '' |
| 146 | + cleanup: true # run populator before each test |
| 147 | + populate: true # run populator before all test |
| 148 | + populator: 'mysql -u $user $dbname < tests/_data/dump.sql' |
| 149 | +``` |
| 150 | + |
| 151 | +This approach is system-dependent, you can't use the same config on Windows and Nix systems, but is much faster. Thanks [Mauro Asprea @brutuscat](https://github.com/brutuscat) for this feature. |
| 152 | + |
| 153 | +### Db module defaults |
| 154 | + |
| 155 | +Important notice: we changed defaults for Db module, so **`cleanup` and `populate` options are disabled** by default. They were quite dangerous in use, so we decided that you need to set them explicitly in Db module config. |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +Codeception 2.2.12 has been released as well. |
| 160 | +See complete [changelog](http://codeception.com/changelog) for all notable changes. |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +P.S. Codeception is seeking for Symfony module maintainer. If you use Codeception with Symfony and you'd like to improve it, please contact us at `team@codeception.com`. |
| 165 | +Maintainer responsibilities are: review issues, pull requests, update symfony demo app and so on. Take a part in project development and make open source brighter! |
0 commit comments