Repository navigation
Expand file tree
/
Copy pathSequence.php
More file actions
66 lines (62 loc) · 1.59 KB
/
Copy pathSequence.php
File metadata and controls
66 lines (62 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Codeception\Module;
use Codeception\Exception\Module;
use Codeception\TestCase;
/**
* Sequence solves data cleanup issue in alternative way.
* Instead cleaning up the database between tests,
* you can use generated unique names, that should not conflict.
* When you create article on a site, for instance, you can assign it a unique name and then check it.
*
* This module has no actions, but introduces a function `sq` for generating unique sequences.
*
* ### Usage
*
* Function `sq` generates sequence, the only parameter it takes, is id.
* You can get back to previously generated sequence using that id:
*
* ``` php
* <?php
* 'post'.sq(1); // post_521fbc63021eb
* 'post'.sq(2); // post_521fbc6302266
* 'post'.sq(1); // post_521fbc63021eb
* ?>
* ```
*
* Example:
*
* ``` php
* <?php
* $I->wantTo('create article');
* $I->click('New Article');
* $I->fillField('Title', 'Article'.sq('name'));
* $I->fillField('Body', 'Demo article with Lorem Ipsum');
* $I->click('save');
* $I->see('Article'.sq('name') ,'#articles')
* ?>
* ```
*
* Populating Database:
*
* ``` php
* <?php
*
* for ($i = 0; $i<10; $i++) {
* $I->haveInDatabase('users', array('login' => 'user'.sq($i), 'email' => 'user'.sq($i).'@email.com');
* }
* ?>
* ```
*
*/
class Sequence extends \Codeception\Module {
public static $hash = array();
public function _after(TestCase $t)
{
self::$hash = array();
}
}
if (!function_exists('sq')) {
require_once __DIR__.'/../Util/sq.php';
} else {
throw new Module('Codeception\Module\Sequence', "function 'sq' already defiend");
}