Commit 107eb811 by Mark

added titles, fixed formatting

parent 67aff101
...@@ -41,6 +41,9 @@ and application destroy after each test. You can configure a mock application us ...@@ -41,6 +41,9 @@ and application destroy after each test. You can configure a mock application us
`TestCase` is extended from `Codeception\TestCase\Case` so all methods and assertions are available. `TestCase` is extended from `Codeception\TestCase\Case` so all methods and assertions are available.
You may use codeception modules and fire events in your test, just use methods: You may use codeception modules and fire events in your test, just use methods:
Getting Codeception modules
---------------------------
```php ```php
<?php <?php
#in your unit-test #in your unit-test
...@@ -53,6 +56,8 @@ You also can use all guy methods by accessing guy instance like: ...@@ -53,6 +56,8 @@ You also can use all guy methods by accessing guy instance like:
<?php <?php
$this->codeGuy->someMethodFromModule(); $this->codeGuy->someMethodFromModule();
``` ```
Codeception events
------------------
to fire event do this: to fire event do this:
...@@ -68,6 +73,10 @@ public function testSomething() ...@@ -68,6 +73,10 @@ public function testSomething()
this event can be catched in modules and helpers. If your test is in the group, then event name will be followed by the groupname, this event can be catched in modules and helpers. If your test is in the group, then event name will be followed by the groupname,
for example ```myevent.somegroup```. for example ```myevent.somegroup```.
Special test methods chain call
-------------------------------
Execution of special tests methods is (for example on ```UserTest``` class): Execution of special tests methods is (for example on ```UserTest``` class):
``` ```
...@@ -88,19 +97,20 @@ tests\unit\models\UserTest::tearDownAfterClass(); ...@@ -88,19 +97,20 @@ tests\unit\models\UserTest::tearDownAfterClass();
If you use special methods dont forget to call its parent. If you use special methods dont forget to call its parent.
Customizing application config
------------------------------
```php ```php
<?php <?php
SomeConsoleTest extends \yii\codeception\TestCase SomeConsoleTest extends \yii\codeception\TestCase
{ {
// this is the config file to load as application config // this is the config file to load as application config
public $appConfig = '@app/path/to/my/custom/config/for/test.php'; public $appConfig = '@app/path/to/my/custom/config/for/test.php';
} }
``` ```
The `$appConfig` property could be an array or valid alias, pointing to file that returns config array. You can sepcify The `$appConfig` property could be an array or valid alias, pointing to file that returns config array. You can specify
application class in the config, for example for testing console commands/features you can create `_console.php` config under application class in the config, for example for testing console commands/features you can create `_console.php` config under
`tests/unit` folder like this: `tests/unit` folder like this:
...@@ -109,6 +119,7 @@ return yii\helpers\ArrayHelper::merge( ...@@ -109,6 +119,7 @@ return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/console.php'), require(__DIR__ . '/../../config/console.php'),
require(__DIR__ . '/../_config.php'), require(__DIR__ . '/../_config.php'),
[ [
'class' => 'yii\console\Application',
'components' => [ 'components' => [
//override console components if needed //override console components if needed
], ],
...@@ -124,14 +135,15 @@ use \yii\codeception\TestCase; ...@@ -124,14 +135,15 @@ use \yii\codeception\TestCase;
class ConsoleTestCase extends TestCase class ConsoleTestCase extends TestCase
{ {
public $appConfig = '@tests/unit/_console.php'; public $appConfig = '@tests/unit/_console.php';
} }
``` ```
You can extend other console tests cases from this basic `ConsoleTestCase`. You can extend other console tests cases from this basic `ConsoleTestCase`.
Reconfiguring components for test
---------------------------------
You also can reconfigure some components for tests, for this purpose in your `setUp` method of your test case You also can reconfigure some components for tests, for this purpose in your `setUp` method of your test case
you can do this for example: you can do this for example:
...@@ -193,7 +205,10 @@ class SomeMyTest extends TestCase ...@@ -193,7 +205,10 @@ class SomeMyTest extends TestCase
} }
} }
```
Additional debug output
-----------------------
Because of Codeception buffers all output you can't make simple `var_dump()` in the TestCase, instead you need to use Because of Codeception buffers all output you can't make simple `var_dump()` in the TestCase, instead you need to use
`Codeception\Util\Debug::debug()` function and then run test with `--debug` key, for example: `Codeception\Util\Debug::debug()` function and then run test with `--debug` key, for example:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment