Skip to content

Commit 841525b

Browse files
committed
merged with master
2 parents 40d89fa + 50c18b7 commit 841525b

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

src/Codeception/Module/Sequence.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* you can use generated unique names, that should not conflict.
1212
* When you create article on a site, for instance, you can assign it a unique name and then check it.
1313
*
14-
* This module has no actions, but introduces a function `sq` for generating unique sequences.
14+
* This module has no actions, but introduces a function `sq` for generating unique sequences within test and
15+
* `sqs` for generating unique sequences across suite.
1516
*
1617
* ### Usage
1718
*
@@ -50,19 +51,49 @@
5051
* ?>
5152
* ```
5253
*
54+
* Cest Suite tests:
55+
*
56+
* ``` php
57+
* <?php
58+
* class UserTest
59+
* {
60+
* public function createUser(AcceptanceTester $I)
61+
* {
62+
* $I->createUser('email' . sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd'));
63+
* }
64+
*
65+
* public function checkEmail(AcceptanceTester $I)
66+
* {
67+
* $I->seeInEmailTo('email' . sqs('user') . '@mailserver.com', sqs('login'));
68+
* }
69+
*
70+
* public function removeUser(AcceptanceTester $I)
71+
* {
72+
* $I->removeUser('email' . sqs('user') . '@mailserver.com');
73+
* }
74+
* }
75+
* ?>
76+
* ```
5377
*/
5478
class Sequence extends CodeceptionModule
5579
{
56-
public static $hash = array();
80+
public static $hash = [];
81+
public static $suiteHash = [];
5782

5883
public function _after(TestInterface $t)
5984
{
6085
self::$hash = [];
6186
}
87+
88+
public function _afterSuite()
89+
{
90+
self::$suiteHash = [];
91+
}
6292
}
6393

64-
if (!function_exists('sq')) {
94+
if (!function_exists('sq') && !function_exists('sqs')) {
6595
require_once __DIR__ . '/../Util/sq.php';
96+
require_once __DIR__ . '/../Util/sqs.php';
6697
} else {
67-
throw new ModuleException('Codeception\Module\Sequence', "function 'sq' already defined");
98+
throw new ModuleException('Codeception\Module\Sequence', "function 'sq' and 'sqs' already defined");
6899
}

tests/unit/Codeception/Module/SequenceTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ public function testSequences()
1414
$this->assertNotEquals($old, sq(1));
1515
}
1616

17+
public function testSuiteSequences()
18+
{
19+
$module = new \Codeception\Module\Sequence(make_container());
20+
$this->assertNotEquals(sqs(), sqs());
21+
$this->assertNotEquals(sqs(1), sqs(2));
22+
$this->assertEquals(sqs(1), sqs(1));
23+
$old = sqs(1);
24+
$module->_after($this);
25+
$this->assertEquals($old, sqs(1));
26+
$module->_afterSuite();
27+
$this->assertNotEquals($old, sqs(1));
28+
}
1729
}

0 commit comments

Comments
 (0)