Skip to content

Commit 7dc5b6b

Browse files
committed
Add documentation
1 parent ff5cd9c commit 7dc5b6b

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

docs/index.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Documentation
2+
====
3+
4+
Arachne/Codeception is here to help you with Integration and [Functional Tests](http://codeception.com/docs/04-FunctionalTests) for your Nette application.
5+
6+
NetteDIModule
7+
----
8+
9+
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.
10+
11+
```yml
12+
# /tests/integration.suite.yml
13+
error_level: "E_ALL"
14+
class_name: IntegrationSuiteTester
15+
modules:
16+
enabled:
17+
- Arachne\Codeception\Module\NetteDIModule:
18+
tempDir: ../_temp/integration
19+
configFiles:
20+
- config/config.neon
21+
# Log directory for Tracy.
22+
# logDir: ../_log
23+
# Debug mode.
24+
# debugMode: true
25+
# Sometimes you might want to override the default Nette\Configurator with your own to get rid of the default extensions.
26+
# configurator: Arachne\Bootstrap\Configurator
27+
```
28+
29+
```
30+
# /tests/integration/config/config.neon
31+
services:
32+
- MyService
33+
```
34+
35+
```php
36+
# /tests/integration/src/MyServiceTest.php
37+
use Codeception\Test\Unit;
38+
class MyServiceTest extends Unit
39+
{
40+
public function testMyService()
41+
{
42+
// Here you can override the configFiles from integration.suite.yml if needed.
43+
// $this->tester->useConfigFiles(['config/another-config.neon']);
44+
$this->assertInstanceOf(MyService::class, $this->tester->grabService(MyService::class));
45+
}
46+
}
47+
```
48+
49+
NetteApplicationModule
50+
----
51+
52+
In functional tests you want to emulate the HTTP request and run `Nette\Application\Application` to handle it.
53+
54+
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 `Arachne\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.**
55+
56+
```
57+
# /tests/functional.suite.yml
58+
error_level: "E_ALL"
59+
class_name: FunctionalSuiteTester
60+
modules:
61+
enabled:
62+
- Arachne\Codeception\Module\NetteApplicationModule
63+
- Arachne\Codeception\Module\NetteDIModule:
64+
tempDir: ../_temp/functional
65+
configFiles:
66+
# Your application config file.
67+
- ../../app/config/config.neon
68+
# Additional config file only to add Arachne\Codeception\DI\HttpExtension.
69+
- config/config.neon
70+
```
71+
72+
```
73+
# /tests/functional/config/config.neon
74+
extensions:
75+
codeception: Arachne\Codeception\DI\HttpExtension
76+
```
77+
78+
```php
79+
# /tests/functional/src/HomepageTest.php
80+
use Codeception\Test\Unit;
81+
class HomepageTest extends Unit
82+
{
83+
public function testHomepage()
84+
{
85+
// Create http request and run Nette\Application\Application. See Arachne\Codeception\Connector\NetteConnector for details.
86+
$this->tester->amOnPage('/');
87+
// Assert that the response is what you expect.
88+
$this->tester->seeResponseCodeIs(200);
89+
$this->tester->see('Hello World!', 'h1');
90+
}
91+
}
92+
```

0 commit comments

Comments
 (0)