Skip to content

Commit 38c23f4

Browse files
committed
Assert::error() accepts array of E_XXXX without error message
1 parent 333e397 commit 38c23f4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Framework/Assert.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ public static function error(callable $function, $expectedType, $expectedMessage
336336
self::$counter++;
337337
$expected = is_array($expectedType) ? $expectedType : [[$expectedType, $expectedMessage]];
338338
foreach ($expected as &$item) {
339-
list($expectedType, $expectedMessage) = $item;
339+
$item = ((array) $item) + [null, null];
340+
$expectedType = $item[0];
340341
if (is_int($expectedType)) {
341342
$item[2] = Helpers::errorTypeToString($expectedType);
342343
} elseif (is_string($expectedType)) {

tests/Framework/Assert.error.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ Assert::error(function () {
2626
[E_NOTICE, 'Undefined variable: b'],
2727
]);
2828

29+
Assert::error(function () {
30+
$a++;
31+
$b++;
32+
}, [
33+
[E_NOTICE],
34+
[E_NOTICE],
35+
]);
36+
37+
Assert::error(function () {
38+
$a++;
39+
$b++;
40+
}, [E_NOTICE, E_NOTICE]
41+
);
42+
2943
Assert::exception(function () {
3044
Assert::error(function () {
3145
}, E_NOTICE);

0 commit comments

Comments
 (0)