Skip to content

Commit 51aa385

Browse files
committed
changed unit tests to use tester property instead of CodeGuy
1 parent 431abc3 commit 51aa385

13 files changed

Lines changed: 296 additions & 303 deletions

File tree

docs/01-Introduction.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ Let's review the listed testing paradigms in reverse order.
1414

1515
### Acceptance Tests
1616

17-
How does your client, manager, or tester, or any other non-technical person, know your site is working? She opens the browser, enters the site, clicks on links, fills the forms, and sees the proper pages as a result. She has no idea of the framework, database, web-server, or programming language you are using. If she sees improper behavior, she will create a bug report. Still this person has no idea why the application didn't work as expected.
17+
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.
1818

19-
Acceptance tests can cover standard but complex scenarios from a user perspective. With acceptance tests you can be confident that users, following all defined scenarios, won't get errors.
19+
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.
2020

21-
Please, note that **any site** can be covered with acceptance tests. Even if you use a very custom CMS or framework.
21+
Please, note that **any web site** can be covered with acceptance tests. Even if you use a very custom CMS or framework.
2222

2323
#### Sample acceptance test
2424

25-
``` php
25+
```php
2626
<?php
27-
$I = new WebGuy($scenario);
27+
$I = new AcceptanceTester($scenario);
2828
$I->amOnPage('/');
2929
$I->click('Sign Up');
3030
$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => 'miles@davis.com'));
@@ -37,29 +37,28 @@ $I->see('Thank you for Signing Up!');
3737
* can be run on any website
3838
* can test javascript and ajax requests
3939
* can be shown to your clients and managers
40-
* the most stable: less affected by changes in source code or technologies.
40+
* most stable in support: less affected by changes in source code or technologies.
4141

4242
#### Cons
43-
* fewer checks can lead to false-positive results
4443
* the slowest: requires running browser and database repopulation.
44+
* fewer checks can lead to false-positive results
4545
* yep, they are really slow.
46+
* not stable in execution: rendering and javascript issues, can lead to unpredicted results.
4647

4748

4849
### Functional Tests
4950

50-
Let's say your application is tested by a technically advanced guy. He also opens the browser, enters the site, clicks links and submits forms, but when an error occurs he can report to you the exception that was thrown, or check the database for expected values. This guy already knows some aspects of your application, and by knowing that his tests can cover more technical details.
51+
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.
5152

52-
Functional tests are run without browser emulation. For functional tests you emulate a web request and submit it to your application. It should return to you a response. You can make assertions about the response, and also access the application's internal values.
53+
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.
5354

54-
For functional tests your application should be prepared to be run in test mode. For frameworks like Symfony2, Symfony1, or Zend, it's easy to start an application in test mode.
55-
56-
Codeception provides connectors to several popular PHP frameworks, but you can write your own.
55+
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.
5756

5857
#### Sample functional test
5958

6059
```php
6160
<?php
62-
$I = new TestGuy($scenario);
61+
$I = new FunctionalTester($scenario);
6362
$I->amOnPage('/');
6463
$I->click('Sign Up');
6564
$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => 'miles@davis.com'));
@@ -84,9 +83,7 @@ $I->seeInDatabase('users', array('email' => 'miles@davis.com'));
8483

8584
### Unit Tests
8685

87-
Only the developer understands how and what is tested here. It can be either unit or integration tests, but they are limited to check one method per test.
88-
89-
The only difference between unit tests and integration tests is that a unit test should be run in total isolation. All other classes or methods should be replaced with stubs.
86+
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.
9087

9188
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.
9289

@@ -103,25 +100,25 @@ function testSavingUser()
103100
$user->setSurname('Davis');
104101
$user->save();
105102
$this->assertEquals('Miles Davis', $user->getFullName());
106-
$this->codeGuy->seeInDatabase('users',array('name' => 'Miles', 'surname' => 'Davis'));
103+
$this->unitTester->seeInDatabase('users',array('name' => 'Miles', 'surname' => 'Davis'));
107104
}
108105
?>
109106
```
110107

111108
#### Pros
112109

113-
* fast as hell (well, in the current example, you still need database repopulation).
110+
* fastest (well, in the current example, you still need database repopulation).
114111
* can cover rarely used features.
115112
* can test stability of application core.
116113
* you can only be considered a good developer if you write them :)
117114

118115
#### Cons
119116

120117
* doesn't test connections between units.
121-
* most unstable: very sensitive to code changes.
118+
* unstable in support: very sensitive to code changes.
122119

123120
## Conclusion
124121

125-
Despite the wide popularity of TDD, few 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.
122+
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.
126123

127124
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.

docs/02-GettingStarted.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
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.
44

5-
## Actors (Guys)
5+
## Actors
66

7-
One of the main concepts of Codeception is representation of tests as actions of a person. By default we call this person a Guy (but you may choose different naming on bootstrap). We have a CodeGuy, who executes functions and tests the code. We also have a TestGuy, a qualified tester, who tests the application as a whole, with knowledge of its internals. And a WebGuy, a user who works with our application through an interface that we provide.
7+
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.
88

9-
Each of these Guys are PHP classes along with the actions that they are allowed to do. As you can see, each of these Guys have different abilities. They are not constant, you can extend them. You can create new Guys If you like, but one Guy belongs to one suite. You can see the Guy classes inside the suite directories.
9+
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.
1010

11-
Guy classes are not written, they are generated by the build command:
11+
Actor classes are not written but generated from suite configuration. When you change configuration actor classes are **rebuilt automatically**.
12+
13+
If Actor classes are not created or updated as you expect, try to generate them manually with `build` command:
1214

1315
```
1416
$ php codecept.phar build
1517
```
1618

17-
Guy classes are generated from suite configuration. When you change configuration guy classes will be rebuilt automatically.
1819

1920
## Writing a Sample Scenario
2021

@@ -30,17 +31,17 @@ $ php codecept.phar generate:cept acceptance Signin
3031

3132
```php
3233
<?php
33-
$I = new WebGuy($scenario);
34+
$I = new AcceptanceTester($scenario);
3435
?>
3536
```
3637

37-
A Scenario always starts with Guy class initialization. After that, writing a scenario is just like typing `$I->` and choosing a proper action from the auto-completion list.
38+
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.
3839

3940
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.
4041

41-
``` php
42+
```php
4243
<?php
43-
$I = new WebGuy($scenario);
44+
$I = new AcceptanceTester($scenario);
4445
$I->wantTo('log in as regular user');
4546
$I->amOnPage('/login');
4647
$I->fillField('Username','davert');
@@ -50,32 +51,32 @@ $I->see('Hello, davert');
5051
?>
5152
```
5253

53-
Before we execute this test, we should make sure that the site is running on a local web server. Open the `tests/acceptance.suite.yml` file and replace the URL with the URL of your web application:
54+
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:
5455

5556
``` yaml
5657
config:
5758
PhpBrowser:
5859
url: 'http://myappurl.local'
5960
```
6061
61-
If you don't have a web server running, you can use the [PHP Built-in Web Server](http://php.net/manual/en/features.commandline.webserver.php) which is available in PHP 5.4.
62-
63-
After you set the proper URL, you can run this test with the command:
62+
After we configured utl we can run this test with `run` command:
6463

6564
``` bash
6665
$ php codecept.phar run
6766
```
6867

69-
In the output you should see:
68+
Here is the output we should see:
7069

7170
``` bash
72-
Suite acceptance started
73-
Trying log in as regular user (SigninCept.php) - Ok
71+
Acceptance Tests (1) -------------------------------
72+
Trying log in as regular user (SigninCept.php) Ok
73+
----------------------------------------------------
7474
75-
Suite functional started
76-
77-
Suite unit started
75+
Functional Tests (0) -------------------------------
76+
----------------------------------------------------
7877
78+
Unit Tests (0) -------------------------------------
79+
----------------------------------------------------
7980
8081
Time: 1 second, Memory: 21.00Mb
8182
@@ -91,7 +92,7 @@ $ php codecept.phar run acceptance --steps
9192
We should see a step-by-step report on the performed actions.
9293

9394
```bash
94-
Suite acceptance started
95+
Acceptance Tests (1) -------------------------------
9596
Trying to log in as regular user (SigninCept.php)
9697
Scenario:
9798
* I am on page "/login"
@@ -100,7 +101,7 @@ Scenario:
100101
* I click "Login"
101102
* I see "Hello, davert"
102103
OK
103-
104+
----------------------------------------------------
104105
105106
Time: 0 seconds, Memory: 21.00Mb
106107
@@ -114,13 +115,11 @@ Give it a try!
114115

115116
## Modules and Helpers
116117

117-
The actions in Guy classes are taken from modules. With the `build` command described above, Codeception emulates 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 extend Guy classes. They are stored in the ___helpers__ directory.
118+
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.
118119

119120
## Bootstrap
120121

121-
Each suite has its own bootstrap file. It's located in the suite directory and is named `_bootstrap.php`. It will be executed before each test.
122-
123-
Write any setup preparations for the suite there.
122+
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.
124123

125124
## Test Formats
126125

@@ -175,7 +174,7 @@ To generate JUnit XML output you can provide `--xml` option, and `--html` for HT
175174
$ php codecept.phar run --steps --xml --html
176175
```
177176

178-
This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. Reports will be store in `tests/_log/` directory.
177+
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.
179178

180179
And to learn all available options:
181180

@@ -202,4 +201,4 @@ There are plenty of useful Codeception commands.
202201

203202
## Conclusion
204203

205-
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.
204+
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.

0 commit comments

Comments
 (0)