diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 921aa97..826c190 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -7,9 +7,11 @@ namespace tests; use Closure; use Exception; use flight\core\Dispatcher; +use InvalidArgumentException; use PharIo\Manifest\InvalidEmailException; use tests\classes\Hello; use PHPUnit\Framework\TestCase; +use tests\classes\TesterClass; use TypeError; class DispatcherTest extends TestCase @@ -126,6 +128,28 @@ class DispatcherTest extends TestCase Dispatcher::execute(['NonExistentClass', 'nonExistentMethod']); } + public function testInvalidCallableString(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid callback specified.'); + + Dispatcher::execute('inexistentGlobalFunction'); + } + + public function testInvalidCallbackBecauseConstructorParameters(): void + { + $class = TesterClass::class; + $method = 'instanceMethod'; + $exceptionMessage = "Method '$class::$method' cannot be called statically. "; + $exceptionMessage .= "$class::__construct require 6 parameters"; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage($exceptionMessage); + + static $params = []; + Dispatcher::invokeMethod([$class, $method], $params); + } + // It will be useful for executing instance Controller methods statically public function testCanExecuteAnNonStaticMethodStatically(): void { diff --git a/tests/classes/TesterClass.php b/tests/classes/TesterClass.php index 0a9ecbc..289ee04 100644 --- a/tests/classes/TesterClass.php +++ b/tests/classes/TesterClass.php @@ -22,4 +22,9 @@ class TesterClass $this->param5 = $param5; $this->param6 = $param6; } + + public function instanceMethod(): void + { + $this->param2 = $this->param1; + } }