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
51 changes: 26 additions & 25 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This library is here to help you with Integration and [Functional Tests](http://

- [Setup](#setup)
- [Usage](#usage)
- [DI module - Nette\DI integration](#nettedimodule)
- [Application module - Nette\Application integration](#netteapplicationmodule)
- [DI module - Nette\DI integration](#nettedimodule)
- [Application module - Nette\Application integration](#netteapplicationmodule)
- [Development](#development)

## Setup
Expand All @@ -22,7 +22,7 @@ composer require contributte/codeception

When you want to write an integration test to make sure that some services work well together you need to create the DI container first.

```yml
```yaml
# /tests/integration.suite.yml
error_level: "E_ALL"
class_name: IntegrationSuiteTester
Expand All @@ -42,35 +42,36 @@ modules:
# newContainerForEachTest: true
```

```yml
```neon
# /tests/integration/config/config.neon
services:
- MyService
- MyService
```

```php
# /tests/integration/src/MyServiceTest.php
use Codeception\Test\Unit;

class MyServiceTest extends Unit
{
public function testMyService(): void
{
// Here you can override the configFiles from integration.suite.yml if needed.
// The newContainerForEachTest option is required for this.
// $this->tester->useConfigFiles(['config/another-config.neon']);
$this->assertInstanceOf(MyService::class, $this->tester->grabService(MyService::class));
}
public function testMyService(): void
{
// Here you can override the configFiles from integration.suite.yml if needed.
// The newContainerForEachTest option is required for this.
// $this->tester->useConfigFiles(['config/another-config.neon']);
$this->assertInstanceOf(MyService::class, $this->tester->grabService(MyService::class));
}
}
```
`useConfigFiles` method takes array of file paths that are either absolute or relative to suite root.
`useConfigFiles` method takes array of file paths that are either absolute or relative to suite root.

### NetteApplicationModule

In functional tests you want to emulate the HTTP request and run `Nette\Application\Application` to handle it.

Unfortunately Nette framework has some downsides like the fact that Request and Response are registered as services in the DI Container. For this reason the NetteApplicationModule requires `Contributte\Codeception\DI\CodeceptionExtension` to override the default implementations. **Beware that this is meant for the functional tests only. Do NOT register the extension outside of tests.**

```yml
```yaml
# /tests/functional.suite.yml
error_level: "E_ALL"
class_name: FunctionalSuiteTester
Expand All @@ -86,25 +87,25 @@ modules:
- config/config.neon
```

```yml
```neon
# /tests/functional/config/config.neon
extensions:
codeception: Contributte\Codeception\DI\HttpExtension
codeception: Contributte\Codeception\DI\HttpExtension
```

```php
# /tests/functional/src/HomepageTest.php
use Codeception\Test\Unit;
class HomepageTest extends Unit
{
public function testHomepage(): void
{
// Create http request and run Nette\Application\Application. See Contributte\Codeception\Connector\NetteConnector for details.
$this->tester->amOnPage('/');
// Assert that the response is what you expect.
$this->tester->seeResponseCodeIs(200);
$this->tester->see('Hello World!', 'h1');
}
public function testHomepage(): void
{
// Create http request and run Nette\Application\Application. See Contributte\Codeception\Connector\NetteConnector for details.
$this->tester->amOnPage('/');
// Assert that the response is what you expect.
$this->tester->seeResponseCodeIs(200);
$this->tester->see('Hello World!', 'h1');
}
}
```

Expand All @@ -116,7 +117,7 @@ Simply run scripts in `Makefile` and make sure that qa, tester and phpstan passe

You can use these commands to do more specific tasks.

```
```bash
# generate necessary files to run the tests
./vendor/bin/codecept build

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

To install latest version of `contributte/codeception` use [Composer](https://getcomposer.com).

```
```bash
composer require contributte/codeception
```

Expand Down