Skip to content

Commit c71a471

Browse files
committed
added global testNoError() function
1 parent a3c5edf commit c71a471

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Framework/functions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ function testException(
5555
}
5656

5757

58+
/**
59+
* Tests that a provided closure does not generate any errors or exceptions.
60+
*/
61+
function testNoError(string $description, Closure $function): void
62+
{
63+
if (($count = func_num_args()) > 2) {
64+
throw new Exception(__FUNCTION__ . "() expects 2 parameters, $count given.");
65+
}
66+
67+
test($description, fn() => Assert::noError($function));
68+
}
69+
70+
5871
/**
5972
* Registers a function to be called before each test execution.
6073
*/

tests/Framework/functions.setUp.tearDown.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ testException('testException with setUp/tearDown', function () {
4747
}, Exception::class);
4848
Assert::same(3, $setUpCalled);
4949
Assert::same(3, $tearDownCalled);
50+
51+
52+
// Test that setUp and tearDown are called after testNoError()
53+
testNoError('testNoError with setUp/tearDown', function () {
54+
Assert::true(true);
55+
});
56+
Assert::same(4, $setUpCalled);
57+
Assert::same(4, $tearDownCalled);

0 commit comments

Comments
 (0)