Skip to content

Commit 1e00447

Browse files
committed
auto updated documentation
1 parent 7825a25 commit 1e00447

Some content is hidden

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

42 files changed

+948
-406
lines changed

_includes/guides.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<li><a href="/docs/01-Introduction">Introduction</a></li><li><a href="/docs/02-GettingStarted">Getting Started</a></li><li><a href="/docs/03-AcceptanceTests">Acceptance Tests</a></li><li><a href="/docs/04-FunctionalTests">Functional Tests</a></li><li><a href="/docs/05-UnitTests">Unit Tests</a></li><li><a href="/docs/06-ModulesAndHelpers">Modules And Helpers</a></li><li><a href="/docs/06-ReusingTestCode">Reusing Test Code</a></li><li><a href="/docs/07-AdvancedUsage">Advanced Usage</a></li><li><a href="/docs/07-BDD">BDD</a></li><li><a href="/docs/08-Customization">Customization</a></li><li><a href="/docs/09-Data">Data</a></li><li><a href="/docs/10-WebServices">Web Services</a></li><li><a href="/docs/11-Codecoverage">Codecoverage</a></li><li><a href="/docs/12-ContinuousIntegration">Continuous Integration</a></li><li><a href="/docs/12-ParallelExecution">Parallel Execution</a></li>
1+
<li><a href="/docs/01-Introduction">Introduction</a></li><li><a href="/docs/02-GettingStarted">Getting Started</a></li><li><a href="/docs/03-AcceptanceTests">Acceptance Tests</a></li><li><a href="/docs/04-FunctionalTests">Functional Tests</a></li><li><a href="/docs/05-UnitTests">Unit Tests</a></li><li><a href="/docs/06-ModulesAndHelpers">Modules And Helpers</a></li><li><a href="/docs/06-ReusingTestCode">Reusing Test Code</a></li><li><a href="/docs/07-AdvancedUsage">Advanced Usage</a></li><li><a href="/docs/07-BDD">BDD</a></li><li><a href="/docs/08-Customization">Customization</a></li><li><a href="/docs/09-Data">Data</a></li><li><a href="/docs/10-APITesting">API Testing</a></li><li><a href="/docs/11-Codecoverage">Codecoverage</a></li><li><a href="/docs/12-ContinuousIntegration">Continuous Integration</a></li><li><a href="/docs/12-ParallelExecution">Parallel Execution</a></li>

changelog.markdown

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ title: Codeception Changelog
77

88
# Changelog
99

10+
#### 3.1.0
11+
12+
* Unified bootstrap file loading
13+
* Deprecated configuring bootstrap for all suites implicitly
14+
* Added `--bootstrap` option to `run`
15+
* **[Asserts]** Added specialized assertEquals methods
16+
* **[Doctrine2]** Added support for Expression and Criteria objects in queries by **[alexkunin](https://github.com/alexkunin)**
17+
* **[Doctrine2]** Added fixture support by **[alexkunin](https://github.com/alexkunin)**
18+
* **[Doctrine2]** added refreshEntities and clearEntityManager methods by **[alexkunin](https://github.com/alexkunin)**
19+
* **[Doctrine2]** implement recursive entity creation by **[alexkunin](https://github.com/alexkunin)**
20+
* **[Doctrine2]** properly handle non-typical primary keys in haveInRepository by **[alexkunin](https://github.com/alexkunin)**
21+
* **[Doctrine2]** merge functionality of persistEntity into haveInRepository by **[alexkunin](https://github.com/alexkunin)**
22+
* **[Doctrine2]** deprecated persistEntity method by **[alexkunin](https://github.com/alexkunin)**
23+
* **[Doctrine2]** Make haveInRepository support constructor parameters by **[burned42](https://github.com/burned42)**
24+
* **[Symfony]** Fixed symfony 4.3 deprecation message removal by **[juntereiner](https://github.com/juntereiner)**
25+
* **[Yii2]** Allow to preserve session with recreateApplication enabled by **[Slamdunk](https://github.com/Slamdunk)**
26+
* **[Docs]** Documentation updates by **[Nebulosar](https://github.com/Nebulosar)** and **[mikehaertl](https://github.com/mikehaertl)**
27+
* **[Docker]** Changed base image to 7.3-cli by **[OneEyedSpaceFish](https://github.com/OneEyedSpaceFish)**
28+
* Robo build:phar command can be used for building custom phar files again
29+
* Improved file path detection for groups [#5609](https://github.com/Codeception/Codeception/issues/5609) by **[adaniloff](https://github.com/adaniloff)**
30+
* Shortened error output of unexpected exit to one line by **[Slamdunk](https://github.com/Slamdunk)**
31+
* Fixed composer.json of codeception/base package
1032
#### 3.0.3
1133
- **[Laravel5]** Add `make` and `makeMultiple` methods for generating model instance by **[ibpavlov](https://github.com/ibpavlov)**
1234
- **[Lumen]** Add `make` and `makeMultiple` methods for generating model instance by **[ibpavlov](https://github.com/ibpavlov)**

docs/01-Introduction.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,31 @@ To test the behavior of your application as a whole, you should write functional
2121
Codeception supports all three testing types.
2222
Out of the box you have tools for writing unit, functional, and acceptance tests in a unified framework.
2323

24-
| | Codeception Unit Tests | Codeception Functional Tests | Codeception Acceptance Tests
24+
| | Unit Tests | Functional Tests | Acceptance Tests
2525
| --- | --- | --- | --- |
2626
| Scope of the test | Single PHP class | PHP Framework (Routing, Controllers, etc.) | Page in browser (Chrome, Firefox, or PhpBrowser) |
2727
| Testing computer needs access to project's PHP files | Yes | Yes | No |
2828
| Webserver required | No | No | Yes |
2929
| JavaScript | No | No | Yes |
30-
| Additional software required | None | None | <ul><li>For WebDriver: Selenium Server or PhantomJS (deprecated)</li><li>For PhpBrowser: None</li></ul> |
31-
| Test execution speed | High | High | Low |
30+
| Additional software required | None | None | Selenium for browser testing</ul> |
31+
| Speed | Fast | Fast | Slow |
3232
| Configuration file | `unit.suite.yml` | `functional.suite.yml` | `acceptance.suite.yml` |
3333

34-
One of the main advantages of Codeception is that you don't have to decide on just *one* type of testing. You can have all three!
34+
One of the main advantages of Codeception is that you don't have to decide on just *one* type of testing. You should have all three!
3535
And chances are, that you will (sooner or later) need all three. That's why Codeception consists of three so-called "suites":
3636
A "unit suite" for all unit tests, a "functional suite" for all functional tests, and an "acceptance suite" for all acceptance tests.
3737

3838
Let's review those three testing types in reverse order.
3939

4040
### Acceptance Tests
4141

42-
How does your client, manager, tester, or any other non-technical person know your website is working?
43-
By opening the browser, accessing the site, clicking on links, filling in the forms,
44-
and actually seeing the content on a web page. They have no idea of the programming language, framework, database, web-server,
42+
How does your client, manager, tester, or any other non-technical person know your website is working? By opening the browser, accessing the site, clicking on links, filling in the forms, and actually seeing the content on a web page. They have no idea of the programming language, framework, database, web-server,
4543
or why the application did (or did not) behave as expected.
4644

4745
This is what acceptance tests are doing. They cover scenarios from a user's perspective.
4846
With acceptance tests, you can be confident that users, following all the defined scenarios, won't get errors.
4947

50-
**Any website** can be covered with acceptance tests, even if you use a very exotic CMS or framework.
48+
> **Any website** can be covered with acceptance tests, even if you use a very exotic CMS or framework.
5149
5250
#### Sample acceptance test
5351

@@ -56,23 +54,22 @@ With acceptance tests, you can be confident that users, following all the define
5654
<?php
5755
$I->amOnPage('/');
5856
$I->click('Sign Up');
59-
$I->submitForm('#signup', ['username' => 'MilesDavis', 'email' => 'miles@davis.com']);
57+
$I->submitForm('#signup', [
58+
'username' => 'MilesDavis',
59+
'email' => 'miles@davis.com'
60+
]);
6061
$I->see('Thank you for Signing Up!');
6162

6263
{% endhighlight %}
6364

6465
### Functional Tests
6566

66-
What if we could check our application without running it on a server?
67-
That way we could see detailed exceptions on errors, have our tests run faster,
68-
and check the database against predictable and expected results. That's what functional tests are for.
67+
What if you could check our application without running it on a server?
68+
That way you could see detailed exceptions on errors, have our tests run faster, and check the database against predictable and expected results. That's what functional tests are for.
6969

70-
For functional tests, you emulate a web request (`$_GET` and `$_POST` variables)
71-
which returns the HTML response. Inside a test, you can make assertions about the response,
72-
and you can check if the data was successfully stored in the database.
70+
For functional tests, you emulate a web request (`$_GET` and `$_POST` variables) which returns the HTML response. Inside a test, you can make assertions about the response, and you can check if the data was successfully stored in the database.
7371

74-
For functional tests, your application needs to be structured in order to run in a test environment.
75-
Codeception provides connectors to several popular PHP frameworks. You can also write your own.
72+
For functional tests, your application needs to be structured in order to run in a test environment. Codeception provides connectors to all popular PHP frameworks.
7673

7774
#### Sample functional test
7875

@@ -88,6 +85,8 @@ $I->seeInDatabase('users', ['email' => 'miles@davis.com']);
8885

8986
{% endhighlight %}
9087

88+
> This looks very similar to acceptance tests. The behavior is the same, however, the test is executed inside PHP without launching a browser.
89+
9190
### Unit Tests
9291

9392
Testing pieces of code before coupling them together is highly important as well. This way,
@@ -107,28 +106,28 @@ The better you understand the testing scenario, the faster you can update it for
107106
{% highlight php %}
108107

109108
<?php
110-
function testSavingUser()
109+
public function testSavingUser()
111110
{
112111
$user = new User();
113112
$user->setName('Miles');
114113
$user->setSurname('Davis');
115114
$user->save();
116115
$this->assertEquals('Miles Davis', $user->getFullName());
117-
$this->tester->seeInDatabase('users', ['name' => 'Miles', 'surname' => 'Davis']);
116+
$this->tester->seeInDatabase('users', [
117+
'name' => 'Miles',
118+
'surname' => 'Davis'
119+
]);
118120
}
119121

120122
{% endhighlight %}
121123

122124
## Conclusion
123125

124-
Despite the wide popularity of *TDD* (Test Driven Development), some PHP developers never write automated tests for their applications mostly because they think it's hard, slow or boring.
125126
The Codeception framework was developed to actually make testing fun.
126127
It allows writing unit, functional, integration, and acceptance tests in a single, coherent style.
127128

128-
It can be called a *BDD* (Behavior Driven Development) framework. All Codeception tests are written in a descriptive manner.
129+
All Codeception tests are written in a descriptive manner.
129130
Just by looking at the test body, you can clearly understand what is being tested and how it is performed.
130-
Even complex tests with many assertions are written in a simple PHP Domain-Specific Language (*DSL*).
131-
132131

133132

134133

docs/02-GettingStarted.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Codeception follows simple naming rules to make it easy to remember (as well as
3434
$I->dontSeeInPageSource('<section class="foo">');
3535

3636
{% endhighlight %}
37-
* **Grabbers** just *read* something from the page, but don't process it. The return value of those are meant to be saved as variables and used later. Example:
37+
* **Grabbers** take information. The return value of those are meant to be saved as variables and used later. Example:
3838
{% highlight php %}
3939

4040
<?php
@@ -45,13 +45,11 @@ Codeception follows simple naming rules to make it easy to remember (as well as
4545

4646
## Actors
4747

48-
One of the main concepts of Codeception is representation of tests as actions of a person.
49-
We have a UnitTester, who executes functions and tests the code. We also have a FunctionalTester, a qualified tester,
48+
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,
5049
who tests the application as a whole, with knowledge of its internals. Lastly we have an AcceptanceTester, a user who works with our application
5150
through an interface that we provide.
5251

53-
**Methods of actor classes are generally taken from [Codeception Modules](http://codeception.com/docs/06-ModulesAndHelpers)**.
54-
Each module provides predefined actions for different testing purposes, and they can be combined to fit the testing environment.
52+
Methods of actor classes are generally taken from [Codeception Modules](http://codeception.com/docs/06-ModulesAndHelpers). Each module provides predefined actions for different testing purposes, and they can be combined to fit the testing environment.
5553
Codeception tries to solve 90% of possible testing issues in its modules, so you don't have to reinvent the wheel.
5654
We think that you can spend more time on writing tests and less on writing support code to make those tests run.
5755
By default, AcceptanceTester relies on PhpBrowser module, which is set in the `tests/acceptance.suite.yml` configuration file:

docs/03-AcceptanceTests.md

Lines changed: 96 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ use \Codeception\Step\Argument\PasswordArgument;
246246
$I->amOnPage('/form/password_argument');
247247
$I->fillField('password', new PasswordArgument('thisissecret'));
248248

249-
{% endhighlight %}
249+
{% endhighlight %}
250250

251251
`thisissecret` will be filled into a form but it won't be shown in output and logs.
252252

@@ -322,7 +322,7 @@ Conditional assertions are disabled in bootstrap setup. To enable them you shoul
322322
step_decorators:
323323
- \Codeception\Step\ConditionalAssertion
324324

325-
{% endhighlight %}
325+
{% endhighlight %}
326326

327327
Then rebuild actors with `codecept build` command.
328328

@@ -436,19 +436,6 @@ This makes Selenium quite heavy to install, as it requires Java, browsers, Chrom
436436
* Follow [Installation Instructions](http://codeception.com/docs/modules/WebDriver#Selenium)
437437
* Enable [RunProcess](http://codeception.com/extensions#RunProcess) extension to start/stop Selenium automatically *(optional)*.
438438

439-
#### PhantomJS
440-
441-
PhantomJS is a customized WebKit-based [headless browser](https://en.wikipedia.org/wiki/Headless_browser)
442-
built for programmatic usage only. It doesn't display a browser window and doesn't require GUI (display server) to be installed.
443-
This makes PhantomJS highly popular for Continuous Integration systems.
444-
PhantomJS needs only one binary with no extra dependencies which make it the simplest WebDriver tool to install.
445-
446-
However, it should be noted that PhantomJS is not a real browser, so the behavior and output in real browsers may differ from PhantomJS.
447-
And the most important: **PhantomJS is not maintained** anymore. So use it at your own risk.
448-
449-
* Follow [Installation Instructions](http://codeception.com/docs/modules/WebDriver#PhantomJS)
450-
* Enable [RunProcess](http://codeception.com/extensions#RunProcess) extension to start/stop PhantomJS automatically *(optional)*.
451-
452439
#### ChromeDriver
453440

454441
ChromeDriver was created by Google to control Chrome and Chromium browsers programmatically.
@@ -610,7 +597,7 @@ Retries are disabled by default. To enable them you should add retry step decora
610597
step_decorators:
611598
- \Codeception\Step\Retry
612599

613-
{% endhighlight %}
600+
{% endhighlight %}
614601

615602
Then add `\Codeception\Lib\Actor\Shared\Retry` trait into `AcceptanceTester` class:
616603

@@ -702,7 +689,7 @@ A/B testing is disabled by default. To enable it you should add corresponding st
702689
step_decorators:
703690
- \Codeception\Step\TryTo
704691

705-
{% endhighlight %}
692+
{% endhighlight %}
706693

707694
Then rebuild actors with `codecept build` command.
708695

@@ -803,6 +790,98 @@ Additional debugging features by Codeception:
803790
* [Interactive Pause](http://codeception.com/docs/02-GettingStarted#Interactive-Pause) is a REPL that allows to type and check commands for instant feedback.
804791
* [Recorder Extension](http://codeception.com/addons#CodeceptionExtensionRecorder) allows to record tests step-by-steps and show them in slideshow
805792

793+
### Common Cases
794+
795+
<<<<<<< HEAD
796+
Let's see how common problems of acceptance testing can be solved with Codeception.
797+
798+
#### Authorization
799+
=======
800+
Let's see how common problems of acceptance testing can be solved with Codeception. We will need to update actor class (whcih is AcceptanceTester) in our case to add a new action.
801+
802+
#### Login
803+
>>>>>>> 82997221b762bc09876379f9f30906c9d364a4f5
804+
805+
It is recommended to put widely used actions inside an Actor class. A good example is the `login` action
806+
which would probably be actively involved in acceptance or functional testing:
807+
808+
{% highlight php %}
809+
810+
<?php
811+
class AcceptanceTester extends \Codeception\Actor
812+
{
813+
// do not ever remove this line!
814+
use _generated\AcceptanceTesterActions;
815+
816+
public function login($name, $password)
817+
{
818+
$I = $this;
819+
$I->amOnPage('/login');
820+
$I->submitForm('#loginForm', [
821+
'login' => $name,
822+
'password' => $password
823+
]);
824+
$I->see($name, '.navbar');
825+
}
826+
}
827+
828+
{% endhighlight %}
829+
830+
Now you can use the `login` method inside your tests:
831+
832+
{% highlight php %}
833+
834+
<?php
835+
// $I is AcceptanceTester
836+
$I->login('miles', '123456');
837+
838+
{% endhighlight %}
839+
840+
However, implementing all actions for reuse in a single actor class may lead to
841+
breaking the [Single Responsibility Principle](http://en.wikipedia.org/wiki/Single_responsibility_principle).
842+
843+
<<<<<<< HEAD
844+
#### Session Snapshot
845+
=======
846+
#### Single Login
847+
>>>>>>> 82997221b762bc09876379f9f30906c9d364a4f5
848+
849+
If you need to authorize a user for each test, you can do so by submitting the login form at the beginning of every test.
850+
Running those steps takes time, and in the case of Selenium tests (which are slow by themselves)
851+
that time loss can become significant.
852+
853+
Codeception allows you to share cookies between tests, so a test user can stay logged in for other tests.
854+
855+
Let's improve the code of our `login` method, executing the form submission only once
856+
and restoring the session from cookies for each subsequent login function call:
857+
858+
{% highlight php %}
859+
860+
<?php
861+
public function login($name, $password)
862+
{
863+
$I = $this;
864+
// if snapshot exists - skipping login
865+
if ($I->loadSessionSnapshot('login')) {
866+
return;
867+
}
868+
// logging in
869+
$I->amOnPage('/login');
870+
$I->submitForm('#loginForm', [
871+
'login' => $name,
872+
'password' => $password
873+
]);
874+
$I->see($name, '.navbar');
875+
// saving snapshot
876+
$I->saveSessionSnapshot('login');
877+
}
878+
879+
{% endhighlight %}
880+
881+
Note that session restoration only works for `WebDriver` modules
882+
(modules implementing `Codeception\Lib\Interfaces\SessionSnapshot`).
883+
884+
806885
### Custom Browser Sessions
807886

808887
By default, WebDriver module is configured to automatically start browser before the test and stop afterward.

docs/05-UnitTests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function testSingleton()
508508
$this->assertInstanceOf('DOMDocument', $class);
509509
}
510510

511-
{% endhighlight %}
511+
{% endhighlight %}
512512

513513
* [AspectMock on GitHub](https://github.com/Codeception/AspectMock)
514514
* [AspectMock in Action](http://codeception.com/07-31-2013/nothing-is-untestable-aspect-mock.html)

0 commit comments

Comments
 (0)