Skip to content

Commit 9738e2e

Browse files
authored
Merge pull request #7 from Codeception/codecept5
Support Codeception 5
2 parents 82d43aa + c49d3bd commit 9738e2e

5 files changed

Lines changed: 39 additions & 42 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.4, 8.0, 8.1]
11+
php: [8.0, 8.1]
1212

1313
steps:
1414
- name: Checkout code

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
],
1313
"minimum-stability": "RC",
1414
"require": {
15-
"php": "^7.4 | ^8.0",
16-
"codeception/codeception": "^4.0"
15+
"php": "^8.0",
16+
"codeception/codeception": "^5.0"
1717
},
1818
"autoload":{
19-
"classmap": ["src/"]
19+
"classmap": ["src/"],
20+
"files": ["src/Codeception/Util/sq.php"]
2021
},
2122
"config": {
2223
"classmap-authoritative": true

src/Codeception/Module/Sequence.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,35 @@
100100
*/
101101
class Sequence extends Module
102102
{
103+
/**
104+
* @var array<int|string,string>
105+
*/
103106
public static array $hash = [];
104107

108+
/**
109+
* @var array<int|string,string>
110+
*/
105111
public static array $suiteHash = [];
106112

107113
public static string $prefix = '';
108114

109115
/**
110116
* @var array<string, string>
111117
*/
112-
protected $config = ['prefix' => '{id}_'];
118+
protected array $config = ['prefix' => '{id}_'];
113119

114-
public function _initialize()
120+
public function _initialize(): void
115121
{
116122
static::$prefix = $this->config['prefix'];
117123
}
118124

119-
public function _after(TestInterface $t)
125+
public function _after(TestInterface $test): void
120126
{
121127
self::$hash = [];
122128
}
123129

124-
public function _afterSuite()
130+
public function _afterSuite(): void
125131
{
126132
self::$suiteHash = [];
127133
}
128134
}
129-
130-
if (!function_exists('sq') && !function_exists('sqs')) {
131-
require_once __DIR__ . '/../Util/sq.php';
132-
} else {
133-
throw new ModuleException(Sequence::class, "function 'sq' and 'sqs' already defined");
134-
}

src/Codeception/Util/sq.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,32 @@
44

55
use Codeception\Module\Sequence;
66

7-
if (!function_exists('sq')) {
8-
function sq($id = null)
9-
{
10-
if ($id && isset(Sequence::$hash[$id])) {
11-
return Sequence::$hash[$id];
12-
}
13-
14-
$prefix = str_replace('{id}', $id, Sequence::$prefix);
15-
$sequence = $prefix . uniqid($id);
16-
if ($id) {
17-
Sequence::$hash[$id] = $sequence;
18-
}
19-
20-
return $sequence;
7+
function sq(int|string $id = null): string
8+
{
9+
if ($id && isset(Sequence::$hash[$id])) {
10+
return Sequence::$hash[$id];
11+
}
12+
13+
$prefix = str_replace('{id}', (string)$id, Sequence::$prefix);
14+
$sequence = $prefix . uniqid((string)$id);
15+
if ($id) {
16+
Sequence::$hash[$id] = $sequence;
2117
}
22-
}
2318

24-
if (!function_exists('sqs')) {
25-
function sqs($id = null)
26-
{
27-
if ($id && isset(Sequence::$suiteHash[$id])) {
28-
return Sequence::$suiteHash[$id];
29-
}
19+
return $sequence;
20+
}
3021

31-
$prefix = str_replace('{id}', $id, Sequence::$prefix);
32-
$sequence = $prefix . uniqid($id);
33-
if ($id) {
34-
Sequence::$suiteHash[$id] = $sequence;
35-
}
22+
function sqs(int|string $id = null): string
23+
{
24+
if ($id && isset(Sequence::$suiteHash[$id])) {
25+
return Sequence::$suiteHash[$id];
26+
}
3627

37-
return $sequence;
28+
$prefix = str_replace('{id}', (string)$id, Sequence::$prefix);
29+
$sequence = $prefix . uniqid((string)$id);
30+
if ($id) {
31+
Sequence::$suiteHash[$id] = $sequence;
3832
}
33+
34+
return $sequence;
3935
}

tests/unit/Codeception/Module/SequenceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Codeception\Lib\ModuleContainer;
66
use Codeception\Module\Sequence;
77
use Codeception\Test\Unit;
8-
use Codeception\Util\Stub;
8+
use Codeception\Stub;
99

1010
final class SequenceTest extends Unit
1111
{

0 commit comments

Comments
 (0)