Skip to content

Commit ba78eb1

Browse files
committed
auto updated documentation
1 parent f9be47b commit ba78eb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+19325
-0
lines changed

_includes/guides.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li><a href="/docs/01-Introduction.md">Introduction.md</a></li><li><a href="/docs/02-GettingStarted.md">Getting Started.md</a></li><li><a href="/docs/03-ModulesAndHelpers.md">Modules And Helpers.md</a></li><li><a href="/docs/04-AcceptanceTests.md">Acceptance Tests.md</a></li><li><a href="/docs/05-FunctionalTests.md">Functional Tests.md</a></li><li><a href="/docs/06-UnitTests.md">Unit Tests.md</a></li><li><a href="/docs/07-AdvancedUsage.md">Advanced Usage.md</a></li><li><a href="/docs/08-Customization.md">Customization.md</a></li><li><a href="/docs/09-Data.md">Data.md</a></li><li><a href="/docs/10-WebServices.md">Web Services.md</a></li><li><a href="/docs/11-Codecoverage.md">Codecoverage.md</a></li><li><a href="/docs/12-ParallelExecution.md">Parallel Execution.md</a></li>

_includes/modules.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li><a href="/docs/modules/AMQP.md">AMQP.md</a></li><li><a href="/docs/modules/Asserts.md">Asserts.md</a></li><li><a href="/docs/modules/Cli.md">Cli.md</a></li><li><a href="/docs/modules/Db.md">Db.md</a></li><li><a href="/docs/modules/Dbh.md">Dbh.md</a></li><li><a href="/docs/modules/Doctrine1.md">Doctrine1.md</a></li><li><a href="/docs/modules/Doctrine2.md">Doctrine2.md</a></li><li><a href="/docs/modules/Facebook.md">Facebook.md</a></li><li><a href="/docs/modules/Filesystem.md">Filesystem.md</a></li><li><a href="/docs/modules/Kohana.md">Kohana.md</a></li><li><a href="/docs/modules/Laravel4.md">Laravel4.md</a></li><li><a href="/docs/modules/Memcache.md">Memcache.md</a></li><li><a href="/docs/modules/MongoDb.md">MongoDb.md</a></li><li><a href="/docs/modules/Phalcon1.md">Phalcon1.md</a></li><li><a href="/docs/modules/PhpBrowser.md">PhpBrowser.md</a></li><li><a href="/docs/modules/REST.md">REST.md</a></li><li><a href="/docs/modules/Redis.md">Redis.md</a></li><li><a href="/docs/modules/SOAP.md">SOAP.md</a></li><li><a href="/docs/modules/Sequence.md">Sequence.md</a></li><li><a href="/docs/modules/Silex.md">Silex.md</a></li><li><a href="/docs/modules/Symfony1.md">Symfony1.md</a></li><li><a href="/docs/modules/Symfony2.md">Symfony2.md</a></li><li><a href="/docs/modules/WebDriver.md">WebDriver.md</a></li><li><a href="/docs/modules/XMLRPC.md">XMLRPC.md</a></li><li><a href="/docs/modules/Yii1.md">Yii1.md</a></li><li><a href="/docs/modules/Yii2.md">Yii2.md</a></li><li><a href="/docs/modules/ZF1.md">ZF1.md</a></li><li><a href="/docs/modules/ZF2.md">ZF2.md</a></li>

_includes/reference.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li><a href="/docs/reference/Autoload.md">Autoload.md</a></li><li><a href="/docs/reference/Commands.md">Commands.md</a></li><li><a href="/docs/reference/Configuration.md">Configuration.md</a></li><li><a href="/docs/reference/Fixtures.md">Fixtures.md</a></li><li><a href="/docs/reference/Locator.md">Locator.md</a></li><li><a href="/docs/reference/Stub.md">Stub.md</a></li><li><a href="/docs/reference/XmlBuilder.md">XmlBuilder.md</a></li>

docs/01-Introduction.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
layout: doc
3+
title: Introduction - Codeception - Documentation
4+
---
5+
6+
# Introduction
7+
8+
The idea behind testing is not new. You can't sleep well if you are not confident that your last commit didn't take down the whole application.
9+
Having your application covered with tests gives you more trust in the stability of your application. That's all.
10+
11+
In most cases tests don't guarantee that the application works 100% as it is supposed to. You can't predict all possible scenarios and exceptional situations for complex apps.
12+
But you can cover with tests the most important parts of your app and at least be sure they work as predicted.
13+
14+
There are plenty of ways to test your application. The most popular paradigm is [Unit Testing](http://en.wikipedia.org/wiki/Unit_testing). As for web applications, testing the controller, or model in isolation doesn't prove your application is working. To test the behavior of your application as a whole, you should write functional or acceptance tests.
15+
16+
The Codeception testing framework distinguishes these levels of testing. Out of the box you have tools for writing unit, functional, and acceptance tests in a single manner.
17+
18+
Let's review the listed testing paradigms in reverse order.
19+
20+
### Acceptance Tests
21+
22+
How does your client, manager, or tester, or any other non-technical person, know your site is working? By opening browser, accessing a site, clicking on links, filling the forms, and actually seeing the contant on a web page. That person has no idea of the framework, database, web-server, or programming language you use or why application did not behave as it was expected.
23+
24+
Acceptance tests can cover standard but complex scenarios from a user's perspective. With acceptance tests you can be confident that users, following all defined scenarios, won't get errors.
25+
26+
Please, note that **any web site** can be covered with acceptance tests. Even if you use a very custom CMS or framework.
27+
28+
#### Sample acceptance test
29+
30+
{% highlight php %}
31+
32+
<?php
33+
$I = new AcceptanceTester($scenario);
34+
$I->amOnPage('/');
35+
$I->click('Sign Up');
36+
$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => 'miles@davis.com'));
37+
$I->see('Thank you for Signing Up!');
38+
?>
39+
40+
{% endhighlight %}
41+
42+
#### Pros
43+
44+
* can be run on any website
45+
* can test javascript and ajax requests
46+
* can be shown to your clients and managers
47+
* most stable in support: less affected by changes in source code or technologies.
48+
49+
#### Cons
50+
* the slowest: requires running browser and database repopulation.
51+
* fewer checks can lead to false-positive results
52+
* yep, they are really slow.
53+
* not stable in execution: rendering and javascript issues, can lead to unpredicted results.
54+
55+
56+
### Functional Tests
57+
58+
What if we could check our application without running it on a server? In this way we could see detailed exceptions on errors, have tests running faster, and check database for values we expect. That's a are what functional tests are for.
59+
60+
For functional tests you emulate a web request ($_GET, $_POST variables) and send it into your application which returns HTML response. Inside a test you can make assertions about the response, also you can check the data was succesfully stored into database.
61+
62+
For functional tests your application should be prepared to be run in test environment. Codeception provides connectors to several popular PHP frameworks, but you can write your own.
63+
64+
#### Sample functional test
65+
66+
{% highlight php %}
67+
68+
<?php
69+
$I = new FunctionalTester($scenario);
70+
$I->amOnPage('/');
71+
$I->click('Sign Up');
72+
$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => 'miles@davis.com'));
73+
$I->see('Thank you for Signing Up!');
74+
$I->seeEmailSent('miles@davis.com', 'Thank you for registration');
75+
$I->seeInDatabase('users', array('email' => 'miles@davis.com'));
76+
?>
77+
78+
{% endhighlight %}
79+
80+
#### Pros
81+
82+
* like acceptance tests, but much faster.
83+
* can provide more detailed reports.
84+
* you can still show this code to managers and clients.
85+
* stable enough: only major code changes, or moving to other framework, can break them.
86+
87+
#### Cons
88+
89+
* javascript and ajax can't be tested.
90+
* by emulating the browser you might get more false-positive results.
91+
* require a framework.
92+
93+
### Unit Tests
94+
95+
Testing pieces of code before coupling them together is highly important as well. This way you can be sure that some deeply hidden feature still works, even it was not touched by functional or acceptance tests. This also proves you produced stable and testable code.
96+
97+
Codeception is created on top of [PHPUnit](http://www.phpunit.de/). If you have experience writing unit tests with PHPUnit you can continue doing so. Codeception has no problem executing standard PHPUnit tests.
98+
99+
But Codeception provides some good tools to make your unit tests simpler and cleaner. Even inexperienced developers should understand what is tested and how. Requirements and code can change rapidly, and unit tests should be updated every time to fit requirements. The better you understand the testing scenario, the faster you can update it for new behavior.
100+
101+
#### Sample integration test
102+
103+
{% highlight php %}
104+
105+
<?php
106+
function testSavingUser()
107+
{
108+
$user = new User();
109+
$user->setName('Miles');
110+
$user->setSurname('Davis');
111+
$user->save();
112+
$this->assertEquals('Miles Davis', $user->getFullName());
113+
$this->unitTester->seeInDatabase('users',array('name' => 'Miles', 'surname' => 'Davis'));
114+
}
115+
?>
116+
117+
{% endhighlight %}
118+
119+
#### Pros
120+
121+
* fastest (well, in the current example, you still need database repopulation).
122+
* can cover rarely used features.
123+
* can test stability of application core.
124+
* you can only be considered a good developer if you write them :)
125+
126+
#### Cons
127+
128+
* doesn't test connections between units.
129+
* unstable in support: very sensitive to code changes.
130+
131+
## Conclusion
132+
133+
Despite the wide popularity of TDD, not all PHP developers ever write automatic tests for their applications. The Codeception framework was developed to make the testing actually fun. It allows writing unit, functional, integration, and acceptance tests in one style.
134+
135+
It could be called a BDD framework. All Codeception tests are written in a descriptive manner. Just by looking in the test body you can get a clear understanding of what is being tested and how it is performed. Even complex tests with many assertions are written in a simple PHP DSL.
136+
137+
138+
139+
140+
* **Next Chapter: [GettingStarted.md >](/docs/02-GettingStarted.md)**

docs/02-GettingStarted.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
---
2+
layout: doc
3+
title: Getting Started - Codeception - Documentation
4+
---
5+
6+
# Getting Started
7+
8+
Let's take a look into Codeception architecture. We assume that you already [installed](http://codeception.com/install) it, and bootstrapped your first test suites. Codeception has generated three of them: unit, functional, and acceptance. They are well described in the previous chapter. Inside your __/tests__ folder you will have three config files and three directories with names corresponding to these suites. Suites are independent groups of tests with a common purpose.
9+
10+
## Actors
11+
12+
One of the main concepts of Codeception is representation of tests as actions of a person. We have a UnitTester, who executes functions and tests the code. We also have a FunctionalTester, a qualified tester, who tests the application as a whole, with knowledge of its internals. And a AcceptanceTester, a user who works with our application through an interface that we provide.
13+
14+
Each of these Actors are PHP classes along with the actions that they are allowed to do. As you can see, each of these Actors have different abilities. They are not constant, you can extend them. One Actor belongs to one testing suite.
15+
16+
Actor classes are not written but generated from suite configuration. When you change configuration actor classes are **rebuilt automatically**.
17+
18+
If Actor classes are not created or updated as you expect, try to generate them manually with `build` command:
19+
20+
{% highlight yaml %}
21+
22+
$ php codecept.phar build
23+
24+
{% endhighlight %}
25+
26+
27+
## Writing a Sample Scenario
28+
29+
By default tests are written as narrative scenarios. To make a PHP file a valid scenario, its name should have a `Cept` suffix.
30+
31+
Let's say, we created a file `tests/acceptance/SigninCept.php`
32+
33+
We can do that by running command:
34+
35+
{% highlight yaml %}
36+
37+
$ php codecept.phar generate:cept acceptance Signin
38+
39+
{% endhighlight %}
40+
41+
{% highlight php %}
42+
43+
<?php
44+
$I = new AcceptanceTester($scenario);
45+
?>
46+
47+
{% endhighlight %}
48+
49+
A Scenario always starts with Actor class initialization. After that, writing a scenario is just like typing `$I->` and choosing a proper action from the auto-completion list.
50+
51+
Let's sign in to our site. We assume that we have a 'login' page where we are getting authenticated by login and password. Then we are moved to a user page, where we see the text `Hello, %username%`. Let's look at how this scenario is written in Codeception.
52+
53+
{% highlight php %}
54+
55+
<?php
56+
$I = new AcceptanceTester($scenario);
57+
$I->wantTo('log in as regular user');
58+
$I->amOnPage('/login');
59+
$I->fillField('Username','davert');
60+
$I->fillField('Password','qwerty');
61+
$I->click('Login');
62+
$I->see('Hello, davert');
63+
?>
64+
65+
{% endhighlight %}
66+
67+
Before we execute this test, we should make sure that the site is running on a local web server. Let's open the `tests/acceptance.suite.yml` file and replace the URL with the URL of your web application:
68+
69+
{% highlight yaml %}
70+
yaml
71+
config:
72+
PhpBrowser:
73+
url: 'http://myappurl.local'
74+
75+
{% endhighlight %}
76+
77+
After we configured utl we can run this test with `run` command:
78+
79+
{% highlight yaml %}
80+
bash
81+
$ php codecept.phar run
82+
83+
{% endhighlight %}
84+
85+
Here is the output we should see:
86+
87+
{% highlight yaml %}
88+
bash
89+
Acceptance Tests (1) -------------------------------
90+
Trying log in as regular user (SigninCept.php) Ok
91+
----------------------------------------------------
92+
93+
Functional Tests (0) -------------------------------
94+
----------------------------------------------------
95+
96+
Unit Tests (0) -------------------------------------
97+
----------------------------------------------------
98+
99+
Time: 1 second, Memory: 21.00Mb
100+
101+
OK (1 test, 1 assertions)
102+
103+
{% endhighlight %}
104+
105+
Let's get a detailed output:
106+
107+
{% highlight yaml %}
108+
bash
109+
$ php codecept.phar run acceptance --steps
110+
111+
{% endhighlight %}
112+
113+
We should see a step-by-step report on the performed actions.
114+
115+
{% highlight yaml %}
116+
bash
117+
Acceptance Tests (1) -------------------------------
118+
Trying to log in as regular user (SigninCept.php)
119+
Scenario:
120+
* I am on page "/login"
121+
* I fill field "Username" "davert"
122+
* I fill field "Password" "qwerty"
123+
* I click "Login"
124+
* I see "Hello, davert"
125+
OK
126+
----------------------------------------------------
127+
128+
Time: 0 seconds, Memory: 21.00Mb
129+
130+
OK (1 test, 1 assertions)
131+
132+
{% endhighlight %}
133+
134+
That was a very simple test that you can reproduce for your own site.
135+
By emulating the user's actions you can test all of your site the same way.
136+
137+
Give it a try!
138+
139+
## Modules and Helpers
140+
141+
The actions in Actor classes are taken from modules. Generated Actor classes emulate multiple inheritance. Modules are designed to have one action performed with one method. According to the [DRY principle](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself), if you use the same scenario components in different modules, you can combine them and move them to a custom module. By default each suite has an empty module, which can be used to extend Actor classes. They are stored in the ___support__ directory.
142+
143+
## Bootstrap
144+
145+
Each suite has its own bootstrap file. It's located in the suite directory and is named `_bootstrap.php`. It will be executed before test suite. There us also a global bootstrap file located in `tests` directory. It can be used to include additional files.
146+
147+
## Test Formats
148+
149+
Codeception supports three test formats. Besides the previously described scenario-based Cept format, Codeception can also execute [PHPUnit test files for unit testing](http://codeception.com/docs/06-UnitTests), and [class-based Cest](http://codeception.com/docs/07-AdvancedUsage#Cest-Classes) format. They are covered in later chapters. There is no difference in the way the tests of either format will be run in the suite.
150+
151+
## Configuration
152+
153+
Codeception has a global configuration in `codeception.yml` and a config for each suite. We also support `.dist` configuration files. If you have several developers in a project, put shared settings into `codeception.dist.yml` and personal settings into `codeception.yml`. Same goes for suite configs. For example, the `unit.suite.yml` will be merged with `unit.suite.dist.yml`.
154+
155+
156+
## Running Tests
157+
158+
Tests can be started with the `run` command.
159+
160+
{% highlight yaml %}
161+
bash
162+
$ php codecept.phar run
163+
164+
{% endhighlight %}
165+
166+
With the first argument you can run tests from one suite.
167+
168+
{% highlight yaml %}
169+
bash
170+
$ php codecept.phar run acceptance
171+
172+
{% endhighlight %}
173+
174+
To run exactly one test, add a second argument. Provide a local path to the test, from the suite directory.
175+
176+
{% highlight yaml %}
177+
bash
178+
$ php codecept.phar run acceptance SigninCept.php
179+
180+
{% endhighlight %}
181+
182+
Alternatively you can provide full path to test file:
183+
184+
{% highlight yaml %}
185+
bash
186+
$ php codecept.phar run tests/acceptance/SigninCept.php
187+
188+
{% endhighlight %}
189+
190+
You can provide a directory path as well:
191+
192+
{% highlight yaml %}
193+
bash
194+
$ php codecept.phar run tests/acceptance/backend
195+
196+
{% endhighlight %}
197+
198+
Which will execute all tests from backend dir.
199+
200+
To execute a group of tests that are not stored in the same dir you can organize them in [groups](http://codeception.com/docs/07-AdvancedUsage#Groups).
201+
202+
### Reports
203+
204+
To generate JUnit XML output you can provide `--xml` option, and `--html` for HTML report.
205+
206+
{% highlight yaml %}
207+
bash
208+
$ php codecept.phar run --steps --xml --html
209+
210+
{% endhighlight %}
211+
212+
This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. Reports will be store in `tests/_output/` directory.
213+
214+
And to learn all available options:
215+
216+
{% highlight yaml %}
217+
bash
218+
$ php codecept.phar help run
219+
220+
{% endhighlight %}
221+
222+
## Debugging
223+
224+
To receive detailed output tests can be executed with `--debug` option.
225+
You may print any information inside a test using `codecept_debug` function.
226+
227+
### Generators
228+
229+
There are plenty of useful Codeception commands.
230+
231+
* `generate:cept` *suite* *filename* - Generates a sample Cept scenario.
232+
* `generate:cest` *suite* *filename* - Generates a sample Cest test.
233+
* `generate:test` *suite* *filename* - Generates a sample PHPUnit Test with Codeception hooks.
234+
* `generate:phpunit` *suite* *filename* - Generates a classic PHPUnit Test.
235+
* `generate:suite` *suite* *guy* - Generates a new suite with the given Guy class name.
236+
* `generate:scenarios` *suite* - Generates text files containing scenarios from tests.
237+
238+
239+
## Conclusion
240+
241+
We took a look into the Codeception structure. Most of the things you need were already generated by the `bootstrap` command. After you have reviewed the basic concepts and configurations, you can start writing your first scenarios.
242+
243+
244+
245+
* **Next Chapter: [ModulesAndHelpers.md >](/docs/03-ModulesAndHelpers.md)**
246+
* **Previous Chapter: [< Introduction.md](/docs/01-Introduction.md)**

0 commit comments

Comments
 (0)