Skip to content

Commit 8cf8a15

Browse files
author
Davert
committed
=auto-updated documentation
1 parent 7ee4354 commit 8cf8a15

File tree

3 files changed

+55
-58
lines changed

3 files changed

+55
-58
lines changed

_includes/modules.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<li><a href="/docs/modules/AMQP">AMQP</a></li><li><a href="/docs/modules/Cli">Cli</a></li><li><a href="/docs/modules/Db">Db</a></li><li><a href="/docs/modules/Dbh">Dbh</a></li><li><a href="/docs/modules/Doctrine1">Doctrine1</a></li><li><a href="/docs/modules/Doctrine2">Doctrine2</a></li><li><a href="/docs/modules/Filesystem">Filesystem</a></li><li><a href="/docs/modules/Kohana">Kohana</a></li><li><a href="/docs/modules/Memcache">Memcache</a></li><li><a href="/docs/modules/MongoDb">MongoDb</a></li><li><a href="/docs/modules/PhpBrowser">PhpBrowser</a></li><li><a href="/docs/modules/REST">REST</a></li><li><a href="/docs/modules/Redis">Redis</a></li><li><a href="/docs/modules/SOAP">SOAP</a></li><li><a href="/docs/modules/Selenium">Selenium</a></li><li><a href="/docs/modules/Selenium2">Selenium2</a></li><li><a href="/docs/modules/SocialEngine">SocialEngine</a></li><li><a href="/docs/modules/Symfony1">Symfony1</a></li><li><a href="/docs/modules/Symfony2">Symfony2</a></li><li><a href="/docs/modules/Unit">Unit</a></li><li><a href="/docs/modules/WebDebug">WebDebug</a></li><li><a href="/docs/modules/XMLRPC">XMLRPC</a></li><li><a href="/docs/modules/ZF1">ZF1</a></li><li><a href="/docs/modules/ZombieJS">ZombieJS</a></li>
1+
<li><a href="/docs/modules/AMQP">AMQP</a></li><li><a href="/docs/modules/Cli">Cli</a></li><li><a href="/docs/modules/Dbh">Dbh</a></li><li><a href="/docs/modules/Db">Db</a></li><li><a href="/docs/modules/Doctrine1">Doctrine1</a></li><li><a href="/docs/modules/Doctrine2">Doctrine2</a></li><li><a href="/docs/modules/Filesystem">Filesystem</a></li><li><a href="/docs/modules/Kohana">Kohana</a></li><li><a href="/docs/modules/Memcache">Memcache</a></li><li><a href="/docs/modules/MongoDb">MongoDb</a></li><li><a href="/docs/modules/PhpBrowser">PhpBrowser</a></li><li><a href="/docs/modules/Redis">Redis</a></li><li><a href="/docs/modules/REST">REST</a></li><li><a href="/docs/modules/Selenium2">Selenium2</a></li><li><a href="/docs/modules/Selenium">Selenium</a></li><li><a href="/docs/modules/SOAP">SOAP</a></li><li><a href="/docs/modules/SocialEngine">SocialEngine</a></li><li><a href="/docs/modules/Symfony1">Symfony1</a></li><li><a href="/docs/modules/Symfony2">Symfony2</a></li><li><a href="/docs/modules/Unit">Unit</a></li><li><a href="/docs/modules/WebDebug">WebDebug</a></li><li><a href="/docs/modules/XMLRPC">XMLRPC</a></li><li><a href="/docs/modules/ZF1">ZF1</a></li><li><a href="/docs/modules/ZombieJS">ZombieJS</a></li>

docs/06-UnitTests-TEST.markdown

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,25 @@ class SimpleTest extends \Codeception\TestCase\Test
3838
*/
3939
protected $codeGuy;
4040
41-
// keep this setupUp and tearDown to enable proper work of Codeception modules
42-
protected function setUp()
41+
// executed before each test
42+
protected function _before()
4343
{
44-
if ($this->bootstrap) require $this->bootstrap;
45-
$this->dispatcher->dispatch('test.before', new \Codeception\Event\Test($this));
46-
$this->codeGuy = new CodeGuy($scenario = new \Codeception\Scenario($this));
47-
$scenario->run();
4844
}
4945
50-
protected function tearDown()
46+
// executed after each test
47+
protected function _after()
5148
{
52-
$this->dispatcher->dispatch('test.after', new \Codeception\Event\Test($this));
5349
}
5450
}
5551
?>
5652

5753
{% endhighlight %}
58-
This class has predefined `setUp` and `tearDown` methods to start with. They are used to include a bootstrap file (`_bootstrap.php` by default) and set up the codeGuy class to have all the cool actions from Cept-files to be run as a part of unit tests. Just like in accordance tests, you can choose the proper modules for `CodeGuy` class in `unit.suite.yml` configuration file.
54+
This class has predefined `_before` and `_after` methods to start with. You can use them to create a tested object before each test, and destroy it afterwards.
55+
56+
As you see unlike in PHPUnit setUp/tearDown methods are replaced with their aliases: `_before`, `_after`.
57+
The actual setUp and tearDown was implemented by parent class `\Codeception\TestCase\Test` and is used to include a bootstrap file (`_bootstrap.php` by default) and set up the codeGuy class to have all the cool actions from Cept-files to be run as a part of unit tests. Just like in accordance tests, you can choose the proper modules for `CodeGuy` class in `unit.suite.yml` configuration file.
58+
So If you implement `setUp` and `tearDown` be sure, that you will call their parent method.
59+
5960

6061
{% highlight yaml %}
6162
yaml
@@ -107,52 +108,32 @@ function testSavingUser()
107108

108109
{% endhighlight %}
109110

110-
The setUp and tearDown methods of your test will perform all initialization and cleanup actions for modules included into CodeGuy class. For instance, while using the database module will make it clean up the database after each run. If you don't need this cleanup to performed you can either update the suite configuration file or just remove this lines for your test:
111-
112-
{% highlight php %}
113-
114-
<?php
115-
// in setUp
116-
$this->dispatcher->dispatch('test.before', new \Codeception\Event\Test($this));
117-
// in tearDown
118-
$this->dispatcher->dispatch('test.after', new \Codeception\Event\Test($this));
119-
?>
111+
Database will be cleaned and populated after each test, as it happens for acceptance and functional tests.
112+
If it's not your required behavior, please change the settings of `Db` module for current suite.
120113

121-
{% endhighlight %}
114+
### Modules
122115

123-
### Bootstrap
116+
*new in 1.5.2*
124117

125-
The bootstrap file is located in suite directory and is named `_bootstrap`. It's widely used in acceptance and functional tests to initialze the predefined variables. In unit tests it can be used for sharing share same data among the different tests. But the main purpose of is to set up an autoloader for your project inside this class. Otherwise Codeception will not find the testing classes and fail.
118+
Codeception allows you to access properties and methods of all modules defined for this suite. Unlike using the CodeGuy class for this purpose, using module directly grants you access to all public properties of that module.
126119

127-
Example bootstrap file may look like this:
120+
For example, if you use `Symfony2` module here is the way you can access Symfony container:
128121

129122
{% highlight php %}
130123

131124
<?php
132-
require_once 'app/autoload.php';
133-
Autoloader::initialize();
134-
135-
$demoUser = User::find(1);
136-
?>
125+
/**
126+
* @var Symfony\Component\DependencyInjection\Container
127+
*/
128+
$container = $this->getModule('Symfony2')->container;
137129

138130
{% endhighlight %}
139131

140-
The `$demoUser` varible now can be accessed in setUp method of a test class.
132+
All public variables are listed in references for corresponding modules.
141133

142-
{% highlight php %}
143-
144-
<?php
145-
protected function setUp()
146-
{
147-
if ($this->bootstrap) require $this->bootstrap;
148-
$this->user = $demoUser;
149-
// ...
150-
}
151-
?>
152-
153-
{% endhighlight %}
134+
### Bootstrap
154135

155-
And you can use it anywhere in your test. Use autoloader to set up the fixtures for your tests. For more information on working with data in tests - read the _Data_ chapter.
136+
The bootstrap file is located in suite directory and is named `_bootstrap` and is **included before each test** (with `setUp` method in parent class). It's widely used in acceptance and functional tests to initialize the predefined variables. In unit tests it can be used for sharing share same data among the different tests. But the main purpose of is to set up an autoloader for your project inside this class. Otherwise Codeception will not find the testing classes and fail.
156137

157138
### Stubs
158139

@@ -176,19 +157,9 @@ class SimpleTest extends \Codeception\TestCase\Test
176157
*/
177158
protected $codeGuy;
178159
179-
// keep this setupUp and tearDown to enable proper work of Codeception modules
180-
protected function setUp()
181-
{
182-
if ($this->bootstrap) require $this->bootstrap;
183-
$this->user = new DemoUser;
184-
$this->dispatcher->dispatch('test.before', new \Codeception\Event\Test($this));
185-
$this->codeGuy = new CodeGuy($scenario = new \Codeception\Scenario($this));
186-
$scenario->run();
187-
}
188-
189-
protected function tearDown()
160+
function _before()
190161
{
191-
$this->dispatcher->dispatch('test.after', new \Codeception\Event\Test($this));
162+
$this->user = new User();
192163
}
193164

194165
function testUserCanBeBanned()

docs/08-UnitTests-CEST.markdown

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,35 @@ class UserCest {
3030

3131
{% endhighlight %}
3232

33-
In most cases, we will probably test exactly one method. As we discovered, it's quite easy to define the class and method you are going to test. We take the `$class` parameter of the Cest class, and the method's name as a target method.
33+
Let's create first test with `generate:cest` command:
34+
35+
{% highlight yaml %}
36+
bash
37+
$ php codecept.phar generate:cest unit Post
38+
39+
{% endhighlight %}
40+
41+
At first we need to define with `$class` preoperty the class which is being actually tested.
42+
43+
{% highlight php %}
44+
45+
<?php
46+
class PostCest {
47+
$class = 'Post';
48+
49+
function shouldBe(CodeGuy $I)
50+
{
51+
52+
}
53+
}
54+
?>
55+
56+
{% endhighlight %}
57+
58+
59+
This will create an empty Cest file for us.
60+
61+
There are many cases whre we test only one method of a class. As we discovered, it's quite easy to define the class and method you are going to test. We take the `$class` parameter of the Cest class, and the method's name as a target method.
3462

3563
{% highlight php %}
3664

@@ -119,8 +147,6 @@ Example bootstrap file (`tests/unit/_bootstrap.php`)
119147
{% highlight php %}
120148

121149
<?php
122-
require_once 'PHPUnit/Framework/Assert/Functions.php';
123-
124150
require_once __DIR__.'/../../config.xml';
125151
126152
MyApplication::autoload();

0 commit comments

Comments
 (0)