Skip to content

Commit 5e2c211

Browse files
committed
auto updated documentation
1 parent 11d6364 commit 5e2c211

10 files changed

+138
-148
lines changed

docs/01-Introduction.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ With acceptance tests, you can be confident that users, following all the define
5454
{% highlight php %}
5555

5656
<?php
57-
$I = new AcceptanceTester($scenario);
5857
$I->amOnPage('/');
5958
$I->click('Sign Up');
6059
$I->submitForm('#signup', ['username' => 'MilesDavis', 'email' => 'miles@davis.com']);
@@ -80,7 +79,6 @@ Codeception provides connectors to several popular PHP frameworks. You can also
8079
{% highlight php %}
8180

8281
<?php
83-
$I = new FunctionalTester($scenario);
8482
$I->amOnPage('/');
8583
$I->click('Sign Up');
8684
$I->submitForm('#signup', ['username' => 'MilesDavis', 'email' => 'miles@davis.com']);
@@ -116,7 +114,7 @@ function testSavingUser()
116114
$user->setSurname('Davis');
117115
$user->save();
118116
$this->assertEquals('Miles Davis', $user->getFullName());
119-
$this->unitTester->seeInDatabase('users', ['name' => 'Miles', 'surname' => 'Davis']);
117+
$this->tester->seeInDatabase('users', ['name' => 'Miles', 'surname' => 'Davis']);
120118
}
121119

122120
{% endhighlight %}

docs/02-GettingStarted.md

Lines changed: 59 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -73,75 +73,71 @@ try to generate them manually with the `build` command:
7373

7474
{% highlight bash %}
7575

76-
php codecept build
76+
php vendor/bin/codecept build
7777

7878
{% endhighlight %}
7979

80-
## Writing a Sample Scenario
80+
## Writing a Sample Test
8181

82-
By default tests are written as narrative scenarios. To make a PHP file a valid scenario, its name should have a `Cept` suffix.
83-
84-
Let's say we have created a file `tests/acceptance/SigninCept.php`
85-
86-
We can do that by running the following command:
82+
Codeception has its own testing format called Cest (Codecept + Test).
83+
To start writing a test we need to create a new Cest file. We can do that by running the following command:
8784

8885
{% highlight bash %}
8986

90-
php codecept generate:cept acceptance Signin
87+
php vendor/bin/codecept generate:cest acceptance Signin
9188

9289
{% endhighlight %}
9390

94-
A scenario always starts with actor class initialization. After that, writing a scenario is just like typing `$I->`
95-
and choosing a proper action from the auto-completion list. Let's log in to our website:
91+
This will generate `SigninCest.php` file inside `tests/acceptance` directory. Let's open it:
9692

9793
{% highlight php %}
9894

9995
<?php
100-
$I = new AcceptanceTester($scenario); // actor class initialization
101-
$I->wantTo('login to website');
102-
103-
104-
{% endhighlight %}
105-
106-
The `wantTo` section describes your scenario in brief. There are additional comment methods that are useful to describe the context of a scenario:
107-
108-
{% highlight php %}
96+
class SigninCest
97+
{
98+
function _before(AcceptanceTester $I)
99+
{
100+
}
101+
102+
public function _after(AcceptanceTester $I)
103+
{
104+
}
109105
110-
<?php
111-
$I = new AcceptanceTester($scenario);
112-
$I->am('user'); // actor's role
113-
$I->wantTo('login to website'); // feature to test
114-
$I->lookForwardTo('access website features for logged-in users'); // result to achieve
106+
public function tryToTest(AcceptanceTester $I)
107+
{
108+
// todo: write test
109+
}
110+
}
115111
116112
{% endhighlight %}
117113
118-
After we have described the story background, let's start writing a scenario.
114+
We have `_before` and `_after` methods to run some common actions before and after a test. And we have a placeholder action `tryToTest` which we need to implement.
115+
If we try to test a signin process it's a good start to test a successful signin. Let's rename this method to `signInSuccessfully`.
119116
120-
We'll assume that we have a 'login' page where we get authenticated by providing a username and password.
117+
We'll assume that we have a 'login' page where we get authenticated by providing a username and password.
121118
Then we are sent to a user page, where we see the text `Hello, %username%`. Let's look at how this scenario is written in Codeception:
122119
123120
{% highlight php %}
124121
125122
<?php
126-
$I = new AcceptanceTester($scenario);
127-
$I->am('user');
128-
$I->wantTo('login to website');
129-
$I->lookForwardTo('access website features for logged-in users');
130-
$I->amOnPage('/login');
131-
$I->fillField('Username','davert');
132-
$I->fillField('Password','qwerty');
133-
$I->click('Login');
134-
$I->see('Hello, davert');
123+
class SigninCest
124+
{
125+
public function loginSuccessfully(AcceptanceTester $I)
126+
{
127+
$I->amOnPage('/login');
128+
$I->fillField('Username','davert');
129+
$I->fillField('Password','qwerty');
130+
$I->click('Login');
131+
$I->see('Hello, davert');
132+
}
133+
}
135134

136135
{% endhighlight %}
137136

138137
This scenario can probably be read by non-technical people. If you just remove all special chars like braces, arrows and `$`,
139138
this test transforms into plain English text:
140139

141140
{% highlight yaml %}
142-
I am user
143-
I wantTo login to website
144-
I lookForwardTo access website features for logged-in users
145141
I amOnPage '/login'
146142
I fillField 'Username','davert'
147143
I fillField 'Password','qwerty'
@@ -154,7 +150,7 @@ Codeception generates this text representation from PHP code by executing:
154150

155151
{% highlight bash %}
156152

157-
php codecept generate:scenarios
153+
php vendor/bin/codecept generate:scenarios
158154

159155
{% endhighlight %}
160156

@@ -178,7 +174,7 @@ After configuring the URL we can run this test with the `run` command:
178174

179175
{% highlight bash %}
180176

181-
php codecept run
177+
php vendor/bin/codecept run
182178

183179
{% endhighlight %}
184180

@@ -187,7 +183,7 @@ This is the output we should see:
187183
{% highlight bash %}
188184

189185
Acceptance Tests (1) -------------------------------
190-
SigninCept: Login to website
186+
SigninCest: sign in successfully
191187
----------------------------------------------------
192188

193189
Time: 1 second, Memory: 21.00Mb
@@ -200,7 +196,7 @@ Let's get some detailed output:
200196

201197
{% highlight bash %}
202198

203-
php codecept run acceptance --steps
199+
php vendor/bin/codecept run acceptance --steps
204200

205201
{% endhighlight %}
206202

@@ -209,12 +205,10 @@ We should see a step-by-step report on the performed actions:
209205
{% highlight bash %}
210206

211207
Acceptance Tests (1) -------------------------------
212-
SigninCept: Login to website
213-
Signature: SigninCept.php
214-
Test: tests/acceptance/SigninCept.php
208+
SigninCest: Login to website
209+
Signature: SigninCest.php:signInSuccessfully
210+
Test: tests/acceptance/SigninCest.php:signInSuccessfully
215211
Scenario --
216-
I am user
217-
I look forward to access website features for logged-in users
218212
I am on page "/login"
219213
I fill field "Username" "davert"
220214
I fill field "Password" "qwerty"
@@ -232,58 +226,45 @@ OK (1 test, 1 assertions)
232226
This simple test can be extended to a complete scenario of site usage, therefore,
233227
by emulating the user's actions, you can test any of your websites.
234228

235-
Give it a try!
236-
237-
## Cept, Cest and Test Formats
229+
To run more tests create a public method for each of them. Include `AcceptanceTester` object as `$I` as a method parameter and use the same `$I->` API you've seen before.
230+
If your tests share common setup actions put them into `_before` method.
238231

239-
Codeception supports three test formats. Beside the previously described scenario-based Cept format,
240-
Codeception can also execute [PHPUnit test files for unit testing](http://codeception.com/docs/05-UnitTests), and Cest format.
241-
242-
**Cest** combines scenario-driven test approach with OOP design. In case you want to group a few testing scenarios into one, you should consider using Cest format.
243-
In the example below we are testing CRUD actions within a single file but with several tests (one per operation):
232+
For instance, to test CRUD we want 4 methods to be implemented and all next tests should start at `/task` page:
244233

245234
{% highlight php %}
246235

247236
<?php
248-
class PageCrudCest
237+
class TaskCrudCest
249238
{
250239
function _before(AcceptanceTester $I)
251240
{
252241
// will be executed at the beginning of each test
253-
$I->amOnPage('/');
242+
$I->amOnPage('/task');
254243
}
255244

256-
function createPage(AcceptanceTester $I)
245+
function createTask(AcceptanceTester $I)
257246
{
258247
// todo: write test
259248
}
260249

261-
function viewPage(AcceptanceTester $I)
250+
function viewTask(AcceptanceTester $I)
262251
{
263252
// todo: write test
264253
}
265254

266-
function updatePage(AcceptanceTester $I)
255+
function updateTask(AcceptanceTester $I)
267256
{
268257
// todo: write test
269258
}
270259

271-
function deletePage(AcceptanceTester $I)
260+
function deleteTask(AcceptanceTester $I)
272261
{
273262
// todo: write test
274263
}
275264
}
276265

277266
{% endhighlight %}
278267

279-
Cest files such as this can be created by running a generator:
280-
281-
{% highlight bash %}
282-
283-
php codecept generate:cest acceptance PageCrud
284-
285-
{% endhighlight %}
286-
287268
Learn more about the [Cest format](http://codeception.com/docs/07-AdvancedUsage#Cest-Classes) in the Advanced Testing section.
288269

289270
## BDD
@@ -303,47 +284,47 @@ Tests can be started with the `run` command:
303284

304285
{% highlight bash %}
305286

306-
php codecept run
287+
php vendor/bin/codecept run
307288

308289
{% endhighlight %}
309290

310291
With the first argument you can run all tests from one suite:
311292

312293
{% highlight bash %}
313294

314-
php codecept run acceptance
295+
php vendor/bin/codecept run acceptance
315296

316297
{% endhighlight %}
317298

318299
To limit tests run to a single class, add a second argument. Provide a local path to the test class, from the suite directory:
319300

320301
{% highlight bash %}
321302

322-
php codecept run acceptance SigninCept.php
303+
php vendor/bin/codecept run acceptance SigninCest.php
323304

324305
{% endhighlight %}
325306

326307
Alternatively you can provide the full path to test file:
327308

328309
{% highlight bash %}
329310

330-
php codecept run tests/acceptance/SigninCept.php
311+
php vendor/bin/codecept run tests/acceptance/SigninCest.php
331312

332313
{% endhighlight %}
333314

334315
You can further filter which tests are run by appending a method name to the class, separated by a colon (for Cest or Test formats):
335316

336317
{% highlight bash %}
337318

338-
php codecept run tests/acceptance/SignInCest.php:^anonymousLogin$
319+
php vendor/bin/codecept run tests/acceptance/SigninCest.php:^anonymousLogin$
339320

340321
{% endhighlight %}
341322

342323
You can provide a directory path as well. This will execute all acceptance tests from the `backend` dir:
343324

344325
{% highlight bash %}
345326

346-
php codecept run tests/acceptance/backend
327+
php vendor/bin/codecept run tests/acceptance/backend
347328

348329
{% endhighlight %}
349330

@@ -352,7 +333,7 @@ For example, this will execute all acceptance tests from the `backend` dir begin
352333

353334
{% highlight bash %}
354335

355-
php codecept run tests/acceptance/backend:^login
336+
php vendor/bin/codecept run tests/acceptance/backend:^login
356337

357338
{% endhighlight %}
358339

@@ -364,7 +345,7 @@ To generate JUnit XML output, you can provide the `--xml` option, and `--html` f
364345

365346
{% highlight bash %}
366347

367-
php codecept run --steps --xml --html
348+
php vendor/bin/codecept run --steps --xml --html
368349

369350
{% endhighlight %}
370351

@@ -374,7 +355,7 @@ To see all the available options, run the following command:
374355

375356
{% highlight bash %}
376357

377-
php codecept help run
358+
php vendor/bin/codecept help run
378359

379360
{% endhighlight %}
380361

@@ -387,7 +368,6 @@ You may print any information inside a test using the `codecept_debug` function.
387368

388369
There are plenty of useful Codeception commands:
389370

390-
* `generate:cept` *suite* *filename* - Generates a sample Cept scenario
391371
* `generate:cest` *suite* *filename* - Generates a sample Cest test
392372
* `generate:test` *suite* *filename* - Generates a sample PHPUnit Test with Codeception hooks
393373
* `generate:feature` *suite* *filename* - Generates Gherkin feature file

docs/03-AcceptanceTests.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,25 @@ modules:
6969

7070
{% endhighlight %}
7171

72-
We should start by creating a 'Cept' file:
72+
We should start by creating a test with the next command:
73+
74+
{% highlight php %}
75+
vendor/bin/codecept g:cest acceptance Signin
76+
77+
{% endhighlight %}
78+
79+
It will be placed into `tests/acceptance` directory.
7380

7481
{% highlight php %}
7582

7683
<?php
77-
// tests/acceptance/SigninCept.php
78-
$I = new AcceptanceTester($scenario);
79-
$I->wantTo('sign in');
84+
class SigninCest
85+
{
86+
public function tryToTest(AcceptanceTester $I)
87+
{
88+
$I->wantTo('test my page');
89+
}
90+
}
8091

8192
{% endhighlight %}
8293

@@ -230,7 +241,6 @@ you can pass instance `\Codeception\Step\Argument\PasswordArgument` with the dat
230241

231242
{% highlight php %}
232243

233-
<?php
234244
<?php
235245
use \Codeception\Step\Argument\PasswordArgument;
236246

0 commit comments

Comments
 (0)