Skip to content

Commit 133cd3a

Browse files
committed
test: revamp testsuite
1 parent 7a9887f commit 133cd3a

File tree

1 file changed

+67
-22
lines changed

1 file changed

+67
-22
lines changed

tests/AsyncTest.php

+67-22
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ public static function asyncifyProvider(): array
2525
function (...$args) {
2626
return \file_get_contents(...$args);
2727
} :
28-
<<<EOF
29-
(
30-
function (...\$args) {
31-
return file_get_contents(...\$args);
32-
}
33-
)
34-
EOF
28+
'(function (...$args) { return file_get_contents(...$args); })'
3529
),
3630
['foo.txt']
3731
],
@@ -43,20 +37,57 @@ function (...\$args) {
4337
],
4438
[
4539
[
46-
<<<EOF
47-
(
48-
function (\$cmd) {
49-
return exec(\$cmd);
50-
}
51-
)
52-
EOF,
40+
'(function ($cmd) { return exec($cmd); })',
5341
['echo "foo"'],
5442
],
5543
(
5644
PHP_THREADABLE ?
5745
'/(Call to undefined function)/i' :
5846
'/^(foo)$/'
5947
)
48+
],
49+
[
50+
[
51+
(
52+
PHP_THREADABLE ?
53+
function (string $value) {
54+
return ['foo' => $value];
55+
} :
56+
'(function (string $value) { return ["foo" => $value]; })'
57+
),
58+
['foo']
59+
],
60+
['foo' => 'foo'],
61+
],
62+
[
63+
[
64+
(
65+
PHP_THREADABLE ?
66+
function (int $value) {
67+
return (object) ['foo' => $value];
68+
} :
69+
'(function (int $value) { return (object) ["foo" => $value]; })'
70+
),
71+
[12]
72+
],
73+
(object) ['foo' => 12]
74+
],
75+
[
76+
[
77+
(
78+
PHP_THREADABLE ?
79+
function (int $next) {
80+
if ($next < 3) {
81+
throw new \Exception('Invalid argument');
82+
}
83+
84+
return $next + 2;
85+
} :
86+
'(function (int $next) { if ($next < 3) { throw new Exception("Invalid argument"); } return $next + 2; })'
87+
),
88+
[2]
89+
],
90+
'/(Invalid argument)/i'
6091
]
6192
];
6293
}
@@ -75,10 +106,17 @@ function (\Throwable $err) {
75106
}
76107
)(...$args);
77108

78-
$this->assertMatchesRegularExpression(
79-
$result,
80-
$exec
81-
);
109+
if (\is_string($result)) {
110+
$this->assertMatchesRegularExpression(
111+
$result,
112+
$exec
113+
);
114+
} else {
115+
$this->assertEquals(
116+
$result,
117+
$exec
118+
);
119+
}
82120
}
83121

84122
/**
@@ -96,9 +134,16 @@ function (\Throwable $err) {
96134
}
97135
)(...$args);
98136

99-
$this->assertMatchesRegularExpression(
100-
$result,
101-
$exec
102-
);
137+
if (\is_string($result)) {
138+
$this->assertMatchesRegularExpression(
139+
$result,
140+
$exec
141+
);
142+
} else {
143+
$this->assertEquals(
144+
$result,
145+
$exec
146+
);
147+
}
103148
}
104149
}

0 commit comments

Comments
 (0)