Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,46 @@ public function buildDocs()
$this->changelog();
}

public function buildDocsGuides() {
$guides = Finder::create()
->ignoreVCS(true)
->depth('== 0')
->name('*.md')
->sortByName()
->in('guides');

$guidesLinks = [];

foreach ($guides as $file) {
$name = substr($file->getBasename(), 0, -3);
$titleName = preg_replace("(\d+-)", '', $name);

$link = "/docs/$titleName";
$editLink = 'https://github.com/Codeception/codeception.github.com/edit/master/guides/' . $file->getBasename();
$title = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $titleName);
$title = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $title);

$contents = file_get_contents($file->getPathname());

foreach ([$file->getBasename(), $titleName . '.md'] as $filename) {
$this->taskWriteToFile('docs/' . $filename)
->line('---')
->line('layout: doc')
->line("title: $title - Codeception Docs")
->line('---')
->line('')
->line('')
->text($contents)
->line('')
->line('<div class="alert alert-warning"><a href="'.$editLink.'"><strong>Improve</strong> this guide</a></div>')
->run();
}

$guidesLinks[] = "<li><a href=\"$link\">$title</a></li>";
}
file_put_contents('_includes/guides.html', implode("\n", $guidesLinks));
}

public function buildDocsModules()
{
$this->taskCleanDir('docs/modules')->run();
Expand Down Expand Up @@ -701,8 +741,8 @@ public function processChangelog()
date_format(date_create($release['published_at']),"Y/m/d H:i:s")
);

$changelog .= " / [🦑 Repository](https://github.com/Codeception/$repo) ";
$changelog .= " / [📦 Releases](https://github.com/Codeception/$repo/releases)\n\n";
$changelog .= " / [Repository](https://github.com/Codeception/$repo) ";
$changelog .= " / [Releases](https://github.com/Codeception/$repo/releases)\n\n";

$body = $release['body'];
//user
Expand Down
18 changes: 17 additions & 1 deletion _includes/guides.html
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
<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>
<li><a href="/docs/Introduction">Introduction</a></li>
<li><a href="/docs/GettingStarted">Getting Started</a></li>
<li><a href="/docs/AcceptanceTests">Acceptance Tests</a></li>
<li><a href="/docs/FunctionalTests">Functional Tests</a></li>
<li><a href="/docs/UnitTests">Unit Tests</a></li>
<li><a href="/docs/Debugging">Debugging</a></li>
<li><a href="/docs/ModulesAndHelpers">Modules And Helpers</a></li>
<li><a href="/docs/ReusingTestCode">Reusing Test Code</a></li>
<li><a href="/docs/AdvancedUsage">Advanced Usage</a></li>
<li><a href="/docs/BDD">BDD</a></li>
<li><a href="/docs/Customization">Customization</a></li>
<li><a href="/docs/Data">Data</a></li>
<li><a href="/docs/APITesting">API Testing</a></li>
<li><a href="/docs/Codecoverage">Codecoverage</a></li>
<li><a href="/docs/Reporting">Reporting</a></li>
<li><a href="/docs/ContinuousIntegration">Continuous Integration</a></li>
<li><a href="/docs/ParallelExecution">Parallel Execution</a></li>
3 changes: 0 additions & 3 deletions _includes/hero.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ <h1>PHP Testing for <br>everyone<span class="blue">_</span></h1>
</div> <!-- /.row -->
<div>
</div>
<div style="margin-top: 40px; width: 100%;">
{% include cloudways.html %}
</div>
</div>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions _layouts/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ <h3>Guides</h3>
<div>


{% include cloudways.html %}


<div id="page">


Expand Down
172 changes: 172 additions & 0 deletions _posts/2022-07-02-codeception-5.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---
layout: post
title: "Codeception 5"
date: 2022-07-02 01:03:50
---

Codeception 5.0 is out!

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.

So let's take a look at new features:

## New Directory Structure

Codeception 5 will match PSR-12 standard. So all tests and classes will have their own namespace `Tests`. The directory structure was updated accordingly:

```
tests/
_output
Acceptance
Functional
Support/
Data/
_generated/
Helper/
Unit/
```

All suite name will have their own namespace, as well as actor and helper classes:

```php
<?php

namespace Tests\Acceptance;

use \Tests\Support\AcceptanceTester;

class LoginCest
{
public function tryToTest(AcceptanceTester $I)
{
$I->amOnPage('/');
}
}
```

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.

## Attributes

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.

So we were glad that native Attributes have landed PHP world. In this release we encourage our users to start using them:

```php
#[Group('important')]
#[Group('api')]
#[Examples('GET', '/users')]
#[Examples('GET', '/posts')]
#[Env('staging-alpha')]
#[Env('staging-beta')]
#[Env('production')]
#[Prepare('startServices')]
public function testApiRequests(ApiTester $I, Example $e)
{
$I->send($e[0], $e[1]);
$I->seeResponseCodeIsSuccessful();
$I->seeResponseIsJson();
}
```

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.

List of available attributes (all under `Codeception\Attribute`) namespace:

* `Before` - specifies the method that should be executed before each test
* `After` - specifies the method that should be executed after each test
* `Group` - set the group for the test
* `Skip` - skips the current test
* `Incomplete` - marks test as incomplete
* `Depends` - sets the test that must be executed before the current one
* `Prepare` - sets a method to execute to initialize the environment (launch server, browser, etc)
* `DataProvider` - specifies a method that provides data for data-driven tests
* `Examples` - sets data for data-driven tests inside the annotation
* `Env` - sets environment value for the current test
* `Given`, `When`, `Then` - marks a method as BDD step

## Debugging

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.

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:

```php
$I->amOnPage('/');
$I->pause();
```

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.

Also new functions were added:

* `codecept_pause()` - starts interactive pause anywhere in debug mode
* `codecept_debug()` - prints a variable into console using Symfony VarDumper

## Sharding

[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.

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.

```
# first job
./venodor/bin/codecept run --shard 1/3

# second job
./venodor/bin/codecept run --shard 2/3

# third job
./venodor/bin/codecept run --shard 3/3
```

This feature reduces the need for complex configuration and usage of `robo` task runner to split tests.

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!

## Grep and Filter

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.

```
php venodor/bin/codecept run --grep "user"
```

## Other Changes

Please go through the list of changes introduced to see if they don't affect your codebase:

* Requires PHP 8.0 or higher
* Compatible with PHPUnit 9 and ready for PHPUnit 10
* Compatible with Symfony 4.4 - 6.0
* Stricter check for phpdotenv v5 (older versions are not supported)
* Throw exception if actor setting is missing in suite configuration
* Removed `generate:cept` command (Cept format is deprecated)
* Removed settings `disallow_test_output` and `log_incomplete_skipped`.
* Removed setting `paths.log` (it was replaced by `paths.output` in Codeception 2.3)
* Removed suite setting `class_name` (replaced by `actor` in Codeception 2.3)
* Removed global setting `actor` (replaced by `actor_prefix` in Codeception 2.3)
* Removed `Configuration::logDir` method (replaced by `Configuration::outputDir` in 2.0)
* Moved XmlBuilder class to module-soap
* Decoupled test execution and reporting from PHPUnit
* Custom reporters implementing TestListener are no longer supported and must be converted to Extensions
* Added optional value to `fail-fast` option (#6275) by #Verest
* Removed `JSON` and `TAP` loggers
* Removed code coverage blacklist functionality
* Removed deprecated class aliases
- Codeception\TestCase\Test
- Codeception\Platform\Group
- Codeception\Platform\Group
- Codeception\TestCase
* Introduced strict types in the code base.

[Complete Changelog](https://raw.githubusercontent.com/Codeception/Codeception/5.0/CHANGELOG-5.x.md)

---

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!

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
](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)!


31 changes: 9 additions & 22 deletions docs/01-Introduction.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
layout: doc
title: 01-Introduction - Codeception - Documentation
title: Introduction - Codeception Docs
---


# Introduction

The idea behind testing is not new. You can't sleep well if you are not confident
Expand Down Expand Up @@ -49,18 +50,15 @@ With acceptance tests, you can be confident that users, following all the define

#### Sample acceptance test

{% highlight php %}

<?php
```php
$I->amOnPage('/');
$I->click('Sign Up');
$I->submitForm('#signup', [
'username' => 'MilesDavis',
'email' => 'miles@davis.com'
]);
$I->see('Thank you for Signing Up!');

{% endhighlight %}
```

### Functional Tests

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

#### Sample functional test

{% highlight php %}

<?php
```php
$I->amOnPage('/');
$I->click('Sign Up');
$I->submitForm('#signup', ['username' => 'MilesDavis', 'email' => 'miles@davis.com']);
$I->see('Thank you for Signing Up!');
$I->seeEmailSent('miles@davis.com', 'Thank you for registration');
$I->seeInDatabase('users', ['email' => 'miles@davis.com']);

{% endhighlight %}
```

> This looks very similar to acceptance tests. The behavior is the same, however, the test is executed inside PHP without launching a browser.

Expand All @@ -103,9 +98,7 @@ The better you understand the testing scenario, the faster you can update it for

#### Sample integration test

{% highlight php %}

<?php
```php
public function testSavingUser()
{
$user = new User();
Expand All @@ -118,8 +111,7 @@ public function testSavingUser()
'surname' => 'Davis'
]);
}

{% endhighlight %}
```

## Conclusion

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




* **Next Chapter: [GettingStarted >](/docs/02-GettingStarted)**

<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>
<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>
Loading