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