@@ -6,8 +6,8 @@ This library is here to help you with Integration and [Functional Tests](http://
6
6
7
7
- [ Setup] ( #setup )
8
8
- [ Usage] ( #usage )
9
- - [ DI module - Nette\DI integration] ( #nettedimodule )
10
- - [ Application module - Nette\Application integration] ( #netteapplicationmodule )
9
+ - [DI module - Nette\DI integration](#nettedimodule)
10
+ - [Application module - Nette\Application integration](#netteapplicationmodule)
11
11
- [ Development] ( #development )
12
12
13
13
## Setup
@@ -22,7 +22,7 @@ composer require contributte/codeception
22
22
23
23
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.
24
24
25
- ``` yml
25
+ ``` yaml
26
26
# /tests/integration.suite.yml
27
27
error_level : " E_ALL"
28
28
class_name : IntegrationSuiteTester
@@ -42,35 +42,36 @@ modules:
42
42
# newContainerForEachTest: true
43
43
```
44
44
45
- ``` yml
45
+ ``` neon
46
46
# /tests/integration/config/config.neon
47
47
services:
48
- - MyService
48
+ - MyService
49
49
```
50
50
51
51
``` php
52
52
# /tests/integration/src/MyServiceTest.php
53
53
use Codeception\Test\Unit;
54
+
54
55
class MyServiceTest extends Unit
55
56
{
56
- public function testMyService() : void
57
- {
58
- // Here you can override the configFiles from integration.suite.yml if needed.
59
- // The newContainerForEachTest option is required for this.
60
- // $this->tester->useConfigFiles(['config/another-config.neon']);
61
- $this->assertInstanceOf(MyService::class, $this->tester->grabService(MyService::class));
62
- }
57
+ public function testMyService(): void
58
+ {
59
+ // Here you can override the configFiles from integration.suite.yml if needed.
60
+ // The newContainerForEachTest option is required for this.
61
+ // $this->tester->useConfigFiles(['config/another-config.neon']);
62
+ $this->assertInstanceOf(MyService::class, $this->tester->grabService(MyService::class));
63
+ }
63
64
}
64
65
```
65
- ` useConfigFiles ` method takes array of file paths that are either absolute or relative to suite root.
66
+ ` useConfigFiles ` method takes array of file paths that are either absolute or relative to suite root.
66
67
67
68
### NetteApplicationModule
68
69
69
70
In functional tests you want to emulate the HTTP request and run ` Nette\Application\Application ` to handle it.
70
71
71
72
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.**
72
73
73
- ``` yml
74
+ ``` yaml
74
75
# /tests/functional.suite.yml
75
76
error_level : " E_ALL"
76
77
class_name : FunctionalSuiteTester
@@ -86,25 +87,25 @@ modules:
86
87
- config/config.neon
87
88
` ` `
88
89
89
- ` ` ` yml
90
+ ` ` ` neon
90
91
# /tests/functional/config/config.neon
91
92
extensions :
92
- codeception : Contributte\Codeception\DI\HttpExtension
93
+ codeception: Contributte\Codeception\DI\HttpExtension
93
94
```
94
95
95
96
``` php
96
97
# /tests/functional/src/HomepageTest.php
97
98
use Codeception\Test\Unit;
98
99
class HomepageTest extends Unit
99
100
{
100
- public function testHomepage() : void
101
- {
102
- // Create http request and run Nette\Application\Application. See Contributte\Codeception\Connector\NetteConnector for details.
103
- $this->tester->amOnPage('/');
104
- // Assert that the response is what you expect.
105
- $this->tester->seeResponseCodeIs(200);
106
- $this->tester->see('Hello World!', 'h1');
107
- }
101
+ public function testHomepage(): void
102
+ {
103
+ // Create http request and run Nette\Application\Application. See Contributte\Codeception\Connector\NetteConnector for details.
104
+ $this->tester->amOnPage('/');
105
+ // Assert that the response is what you expect.
106
+ $this->tester->seeResponseCodeIs(200);
107
+ $this->tester->see('Hello World!', 'h1');
108
+ }
108
109
}
109
110
```
110
111
@@ -116,7 +117,7 @@ Simply run scripts in `Makefile` and make sure that qa, tester and phpstan passe
116
117
117
118
You can use these commands to do more specific tasks.
118
119
119
- ```
120
+ ``` bash
120
121
# generate necessary files to run the tests
121
122
./vendor/bin/codecept build
122
123
0 commit comments