Skip to content
Permalink
Browse files

Assert::noError() throws exception when is called with more than one …

…parameter

Prevents unwanted misuse instead of exception() or error()
  • Loading branch information...
dg committed Feb 19, 2019
1 parent 1e73518 commit 2e5da8421c5e3c0fc48d101e046953e95f89185c
Showing with 10 additions and 0 deletions.
  1. +3 −0 src/Framework/Assert.php
  2. +7 −0 tests/Framework/Assert.noError.phpt
@@ -361,6 +361,9 @@ public static function error(callable $function, $expectedType, string $expected
*/
public static function noError(callable $function): void
{
if (($count = func_num_args()) > 1) {
throw new \Exception(__METHOD__ . "() expects 1 parameter, $count given.");
}
self::error($function, []);
}
@@ -23,3 +23,10 @@ Assert::exception(function () {
throw new \Exception('Unexpected');
});
}, Exception::class, 'Unexpected');
Assert::exception(function () {
Assert::noError(function () {
throw new \Exception('Unexpected');
}, InvalidArgumentException::class);
}, Exception::class, 'Tester\Assert::noError() expects 1 parameter, 2 given.');

0 comments on commit 2e5da84

Please sign in to comment.
You can’t perform that action at this time.