Skip to content

Commit 51d2387

Browse files
authored
[WIP] Docs for 5.0 (Codeception#611)
* added debugging section * added script to generate guides, parallel guide updated * refreshed docs, added parallel reporting * improved parallel excution chapter * added reporters * added image for allure extension * reviewed and updated old guides * updated guides for v5 * updated guides * updated links to 5.0 version * updated all guides * cleaned up reporters section * added GitHub Actions as CI provider * added guide for skipped tests * updated env params to include objects or array * rerunning * dataproviders for unit tests disabled * removed Cept from mentioning * mention combined attributes * filter running on multiple apps * updated guiides * added blogpost for v5 * grammar fixes
1 parent c5d6a0f commit 51d2387

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+13816
-787
lines changed

RoboFile.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,46 @@ public function buildDocs()
129129
$this->changelog();
130130
}
131131

132+
public function buildDocsGuides() {
133+
$guides = Finder::create()
134+
->ignoreVCS(true)
135+
->depth('== 0')
136+
->name('*.md')
137+
->sortByName()
138+
->in('guides');
139+
140+
$guidesLinks = [];
141+
142+
foreach ($guides as $file) {
143+
$name = substr($file->getBasename(), 0, -3);
144+
$titleName = preg_replace("(\d+-)", '', $name);
145+
146+
$link = "/docs/$titleName";
147+
$editLink = 'https://github.com/Codeception/codeception.github.com/edit/master/guides/' . $file->getBasename();
148+
$title = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $titleName);
149+
$title = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $title);
150+
151+
$contents = file_get_contents($file->getPathname());
152+
153+
foreach ([$file->getBasename(), $titleName . '.md'] as $filename) {
154+
$this->taskWriteToFile('docs/' . $filename)
155+
->line('---')
156+
->line('layout: doc')
157+
->line("title: $title - Codeception Docs")
158+
->line('---')
159+
->line('')
160+
->line('')
161+
->text($contents)
162+
->line('')
163+
->line('<div class="alert alert-warning"><a href="'.$editLink.'"><strong>Improve</strong> this guide</a></div>')
164+
->run();
165+
}
166+
167+
$guidesLinks[] = "<li><a href=\"$link\">$title</a></li>";
168+
}
169+
file_put_contents('_includes/guides.html', implode("\n", $guidesLinks));
170+
}
171+
132172
public function buildDocsModules()
133173
{
134174
$this->taskCleanDir('docs/modules')->run();
@@ -701,8 +741,8 @@ public function processChangelog()
701741
date_format(date_create($release['published_at']),"Y/m/d H:i:s")
702742
);
703743

704-
$changelog .= " / [🦑 Repository](https://github.com/Codeception/$repo) ";
705-
$changelog .= " / [📦 Releases](https://github.com/Codeception/$repo/releases)\n\n";
744+
$changelog .= " / [Repository](https://github.com/Codeception/$repo) ";
745+
$changelog .= " / [Releases](https://github.com/Codeception/$repo/releases)\n\n";
706746

707747
$body = $release['body'];
708748
//user

_includes/guides.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
<li><a href="/docs/01-Introduction">Introduction</a></li><li><a href="/docs/02-GettingStarted">Getting Started</a></li><li><a href="/docs/03-AcceptanceTests">Acceptance Tests</a></li><li><a href="/docs/04-FunctionalTests">Functional Tests</a></li><li><a href="/docs/05-UnitTests">Unit Tests</a></li><li><a href="/docs/06-ModulesAndHelpers">Modules And Helpers</a></li><li><a href="/docs/06-ReusingTestCode">Reusing Test Code</a></li><li><a href="/docs/07-AdvancedUsage">Advanced Usage</a></li><li><a href="/docs/07-BDD">BDD</a></li><li><a href="/docs/08-Customization">Customization</a></li><li><a href="/docs/09-Data">Data</a></li><li><a href="/docs/10-APITesting">API Testing</a></li><li><a href="/docs/11-Codecoverage">Codecoverage</a></li><li><a href="/docs/12-ContinuousIntegration">Continuous Integration</a></li><li><a href="/docs/12-ParallelExecution">Parallel Execution</a></li>
1+
<li><a href="/docs/Introduction">Introduction</a></li>
2+
<li><a href="/docs/GettingStarted">Getting Started</a></li>
3+
<li><a href="/docs/AcceptanceTests">Acceptance Tests</a></li>
4+
<li><a href="/docs/FunctionalTests">Functional Tests</a></li>
5+
<li><a href="/docs/UnitTests">Unit Tests</a></li>
6+
<li><a href="/docs/Debugging">Debugging</a></li>
7+
<li><a href="/docs/ModulesAndHelpers">Modules And Helpers</a></li>
8+
<li><a href="/docs/ReusingTestCode">Reusing Test Code</a></li>
9+
<li><a href="/docs/AdvancedUsage">Advanced Usage</a></li>
10+
<li><a href="/docs/BDD">BDD</a></li>
11+
<li><a href="/docs/Customization">Customization</a></li>
12+
<li><a href="/docs/Data">Data</a></li>
13+
<li><a href="/docs/APITesting">API Testing</a></li>
14+
<li><a href="/docs/Codecoverage">Codecoverage</a></li>
15+
<li><a href="/docs/Reporting">Reporting</a></li>
16+
<li><a href="/docs/ContinuousIntegration">Continuous Integration</a></li>
17+
<li><a href="/docs/ParallelExecution">Parallel Execution</a></li>

_includes/hero.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ <h1>PHP Testing for <br>everyone<span class="blue">_</span></h1>
2020
</div> <!-- /.row -->
2121
<div>
2222
</div>
23-
<div style="margin-top: 40px; width: 100%;">
24-
{% include cloudways.html %}
25-
</div>
2623
</div>
2724
</div>
2825
</div>

_layouts/doc.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ <h3>Guides</h3>
3636
<div>
3737

3838

39-
{% include cloudways.html %}
40-
41-
4239
<div id="page">
4340

4441

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
layout: post
3+
title: "Codeception 5"
4+
date: 2022-07-02 01:03:50
5+
---
6+
7+
Codeception 5.0 is out!
8+
9+
This release is **PHP 8+** only, so we are back on track with modern PHP. We are **dropping support for PHPUnit < 9**, and are technically ready for PHPUnit 10. And we also support **Symfony 6** without dropping support of previous Symfony versions. As always, we did our best to keep backward compatibility so if you can update your dependencies, all tests should be working for you.
10+
11+
So let's take a look at new features:
12+
13+
## New Directory Structure
14+
15+
Codeception 5 will match PSR-12 standard. So all tests and classes will have their own namespace `Tests`. The directory structure was updated accordingly:
16+
17+
```
18+
tests/
19+
_output
20+
Acceptance
21+
Functional
22+
Support/
23+
Data/
24+
_generated/
25+
Helper/
26+
Unit/
27+
```
28+
29+
All suite name will have their own namespace, as well as actor and helper classes:
30+
31+
```php
32+
<?php
33+
34+
namespace Tests\Acceptance;
35+
36+
use \Tests\Support\AcceptanceTester;
37+
38+
class LoginCest
39+
{
40+
public function tryToTest(AcceptanceTester $I)
41+
{
42+
$I->amOnPage('/');
43+
}
44+
}
45+
```
46+
47+
New directory structure will be generated by running `codecept bootstrap`. The directory structure is set with a new default config, so the previous directory structure is still valid.
48+
49+
## Attributes
50+
51+
Annotations were an essential part of Codeception testing framework. Even though they were not native language constructs, they proved to be quite good to separate a test from its metadata. We believe that test should not include code that doesn't belong to the test scenario.
52+
53+
So we were glad that native Attributes have landed PHP world. In this release we encourage our users to start using them:
54+
55+
```php
56+
#[Group('important')]
57+
#[Group('api')]
58+
#[Examples('GET', '/users')]
59+
#[Examples('GET', '/posts')]
60+
#[Env('staging-alpha')]
61+
#[Env('staging-beta')]
62+
#[Env('production')]
63+
#[Prepare('startServices')]
64+
public function testApiRequests(ApiTester $I, Example $e)
65+
{
66+
$I->send($e[0], $e[1]);
67+
$I->seeResponseCodeIsSuccessful();
68+
$I->seeResponseIsJson();
69+
}
70+
```
71+
72+
As you see, attributes decouple all preparation steps, keeping the test scenario minimal. We also keep supporting annotations, so an urgent upgrade is not needed. Attributes can't do something that traditional annotations can't, they are just a modern alternative.
73+
74+
List of available attributes (all under `Codeception\Attribute`) namespace:
75+
76+
* `Before` - specifies the method that should be executed before each test
77+
* `After` - specifies the method that should be executed after each test
78+
* `Group` - set the group for the test
79+
* `Skip` - skips the current test
80+
* `Incomplete` - marks test as incomplete
81+
* `Depends` - sets the test that must be executed before the current one
82+
* `Prepare` - sets a method to execute to initialize the environment (launch server, browser, etc)
83+
* `DataProvider` - specifies a method that provides data for data-driven tests
84+
* `Examples` - sets data for data-driven tests inside the annotation
85+
* `Env` - sets environment value for the current test
86+
* `Given`, `When`, `Then` - marks a method as BDD step
87+
88+
## Debugging
89+
90+
Do you remember, `Hoa\Console`? Unfortunately, this library was deprecated and we were looking for a modern alternative that could power `codecept console` and `$I->pause();` commands. We switched to [PsySH](https://psysh.org) a PHP REPL.
91+
92+
An interactive console is used to pause a test in the given state. While in pause you can try different Codeception commands, and check variable values. Instead of fixing tests blindly, you can start an interactive session. This is quite a similar effect you can get with a real debugger like XDebug but focused on Codeception commands. Especially this is helpful to write acceptance tests as the test scenario can be planned while executing a test. So basic scenario can be written as:
93+
94+
```php
95+
$I->amOnPage('/');
96+
$I->pause();
97+
```
98+
99+
After opening a page you will be able to try commands in a browser. If a command succeeds you can use it in your tests.
100+
101+
Also new functions were added:
102+
103+
* `codecept_pause()` - starts interactive pause anywhere in debug mode
104+
* `codecept_debug()` - prints a variable into console using Symfony VarDumper
105+
106+
## Sharding
107+
108+
[Parallel Execution](/docs/ParallelExecution) guide has been rewritten and focused on a new feature: sharding. It is the simplest way to run slow tests (think of acceptance tests first) in parallel on multiple agents.
109+
110+
In this case, you specify the batch of tests that should be executed independently and each job picks up its own not intersecting group of tests to run them.
111+
112+
```
113+
# first job
114+
./venodor/bin/codecept run --shard 1/3
115+
116+
# second job
117+
./venodor/bin/codecept run --shard 2/3
118+
119+
# third job
120+
./venodor/bin/codecept run --shard 3/3
121+
```
122+
123+
This feature reduces the need for complex configuration and usage of `robo` task runner to split tests.
124+
125+
It is recommended to use sharding to parallelize tests between multiple jobs as the simplest approach. Unfortunately, PHP doesn't have native multi-threading for test parallelization, and even if it had, it doesn't solve the problem of running slow browser tests that interacts with a whole application. So only horizontal scaling by jobs can be suggested as a long-running approach. The more build agents you add to your Continuous Integration server, the fastest tests will run. That's it!
126+
127+
## Grep and Filter
128+
129+
New options `--grep` and `--filter` were introduced to select tests by part of their name. Actually, it is the same option and an alias. `--grep` is a common way to select tests to execute in NodeJS test runners, so we ported it to Codeception. But as usual, specific tests can also be executed by group or specifying a test signature.
130+
131+
```
132+
php venodor/bin/codecept run --grep "user"
133+
```
134+
135+
## Other Changes
136+
137+
Please go through the list of changes introduced to see if they don't affect your codebase:
138+
139+
* Requires PHP 8.0 or higher
140+
* Compatible with PHPUnit 9 and ready for PHPUnit 10
141+
* Compatible with Symfony 4.4 - 6.0
142+
* Stricter check for phpdotenv v5 (older versions are not supported)
143+
* Throw exception if actor setting is missing in suite configuration
144+
* Removed `generate:cept` command (Cept format is deprecated)
145+
* Removed settings `disallow_test_output` and `log_incomplete_skipped`.
146+
* Removed setting `paths.log` (it was replaced by `paths.output` in Codeception 2.3)
147+
* Removed suite setting `class_name` (replaced by `actor` in Codeception 2.3)
148+
* Removed global setting `actor` (replaced by `actor_prefix` in Codeception 2.3)
149+
* Removed `Configuration::logDir` method (replaced by `Configuration::outputDir` in 2.0)
150+
* Moved XmlBuilder class to module-soap
151+
* Decoupled test execution and reporting from PHPUnit
152+
* Custom reporters implementing TestListener are no longer supported and must be converted to Extensions
153+
* Added optional value to `fail-fast` option (#6275) by #Verest
154+
* Removed `JSON` and `TAP` loggers
155+
* Removed code coverage blacklist functionality
156+
* Removed deprecated class aliases
157+
- Codeception\TestCase\Test
158+
- Codeception\Platform\Group
159+
- Codeception\Platform\Group
160+
- Codeception\TestCase
161+
* Introduced strict types in the code base.
162+
163+
[Complete Changelog](https://raw.githubusercontent.com/Codeception/Codeception/5.0/CHANGELOG-5.x.md)
164+
165+
---
166+
167+
We really happy that we are finally here with Codeception 5. This release was crafted during wartime, which happens in Ukraine. It is mentally and morally hard to work on tech products knowing that at any point this peaceful virtual life can end at any moment by a random missile. Codeception was created in 2011 by Michael Bodnarchuk in Kyiv, and today in 2022 he also stays there writing this post. If you want to support Codeception, all the Ukrainian PHP community, and all our brave nation who stands for democracy against barbaric Russian invasion, consider **[donating to Ukrainian charities](https://stand-with-ukraine.pp.ua)**. Not a single time. Every month until the war ends. Every time you travel or enjoy tasty food in a restaurant think of people who are forced to defend their land, or who fled their homes. Glory to Ukraine!
168+
169+
This release wouldn't be possible without the hard work of [Gintautas Misselis](https://github.com/Naktibalda) who keeps constant work on modernizing internals and keeping Codeception up to date. Also we are really thankful to [Gustavo Nieves
170+
](https://github.com/TavoNiievez) who did a lot of work transitioning Codeception to new Symfony and more! Thanks to our maintainers! If you want to support our work we have [OpenCollective](https://opencollective.com/codeception)!
171+
172+

docs/01-Introduction.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
layout: doc
3-
title: 01-Introduction - Codeception - Documentation
3+
title: Introduction - Codeception Docs
44
---
55

6+
67
# Introduction
78

89
The idea behind testing is not new. You can't sleep well if you are not confident
@@ -49,18 +50,15 @@ With acceptance tests, you can be confident that users, following all the define
4950
5051
#### Sample acceptance test
5152

52-
{% highlight php %}
53-
54-
<?php
53+
```php
5554
$I->amOnPage('/');
5655
$I->click('Sign Up');
5756
$I->submitForm('#signup', [
5857
'username' => 'MilesDavis',
5958
'email' => 'miles@davis.com'
6059
]);
6160
$I->see('Thank you for Signing Up!');
62-
63-
{% endhighlight %}
61+
```
6462

6563
### Functional Tests
6664

@@ -73,17 +71,14 @@ For functional tests, your application needs to be structured in order to run in
7371

7472
#### Sample functional test
7573

76-
{% highlight php %}
77-
78-
<?php
74+
```php
7975
$I->amOnPage('/');
8076
$I->click('Sign Up');
8177
$I->submitForm('#signup', ['username' => 'MilesDavis', 'email' => 'miles@davis.com']);
8278
$I->see('Thank you for Signing Up!');
8379
$I->seeEmailSent('miles@davis.com', 'Thank you for registration');
8480
$I->seeInDatabase('users', ['email' => 'miles@davis.com']);
85-
86-
{% endhighlight %}
81+
```
8782

8883
> This looks very similar to acceptance tests. The behavior is the same, however, the test is executed inside PHP without launching a browser.
8984
@@ -103,9 +98,7 @@ The better you understand the testing scenario, the faster you can update it for
10398

10499
#### Sample integration test
105100

106-
{% highlight php %}
107-
108-
<?php
101+
```php
109102
public function testSavingUser()
110103
{
111104
$user = new User();
@@ -118,8 +111,7 @@ public function testSavingUser()
118111
'surname' => 'Davis'
119112
]);
120113
}
121-
122-
{% endhighlight %}
114+
```
123115

124116
## Conclusion
125117

@@ -129,9 +121,4 @@ It allows writing unit, functional, integration, and acceptance tests in a singl
129121
All Codeception tests are written in a descriptive manner.
130122
Just by looking at the test body, you can clearly understand what is being tested and how it is performed.
131123

132-
133-
134-
135-
* **Next Chapter: [GettingStarted >](/docs/02-GettingStarted)**
136-
137-
<div class="alert alert-warning"><a href="https://github.com/Codeception/codeception.github.com/edit/master/docs/01-Introduction.md"><strong>Edit</strong> this page on GitHub</a></div>
124+
<div class="alert alert-warning"><a href="https://github.com/Codeception/codeception.github.com/edit/master/guides/01-Introduction.md"><strong>Improve</strong> this guide</a></div>

0 commit comments

Comments
 (0)