It throws an Exception for invalid Filters array

pull/538/head
fadrian06 12 months ago
parent 72c50d4cb5
commit a15a82a209

@ -165,9 +165,13 @@ class Dispatcher
* *
* @throws Exception If an event throws an `Exception`. * @throws Exception If an event throws an `Exception`.
*/ */
public function filter(array $filters, array &$params, &$output): void public static function filter(array $filters, array &$params, &$output): void
{ {
foreach ($filters as $callback) { foreach ($filters as $key => $callback) {
if (!is_callable($callback)) {
throw new InvalidArgumentException("Invalid callable \$filters[$key].");
}
$continue = $callback($params, $output); $continue = $callback($params, $output);
if ($continue === false) { if ($continue === false) {

@ -194,6 +194,20 @@ class DispatcherTest extends TestCase
restore_error_handler(); restore_error_handler();
} }
public function testItThrowsAnExceptionForInvalidFilters(): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid callable $filters[1]');
$params = [];
$output = '';
$validCallable = function (): void {
};
$invalidCallable = 'invalidGlobalFunction';
Dispatcher::filter([$validCallable, $invalidCallable], $params, $output);
}
public function testCallFunction4Params(): void public function testCallFunction4Params(): void
{ {
$myFunction = function ($param1, $param2, $param3, $param4) { $myFunction = function ($param1, $param2, $param3, $param4) {

Loading…
Cancel
Save