DispatcherTest 100% test coverage

pull/540/head
fadrian06 12 months ago
parent 50d258a997
commit 2b6fb46f48

@ -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
{

@ -22,4 +22,9 @@ class TesterClass
$this->param5 = $param5;
$this->param6 = $param6;
}
public function instanceMethod(): void
{
$this->param2 = $this->param1;
}
}

Loading…
Cancel
Save