-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if handler method exists in MethodToCall
By doing this in our value object instead of our middleware, we make this more reusable for custom scenarios AND we simplify the middleware, which should help encourage folks to write their own custom ones instead.
- Loading branch information
Showing
11 changed files
with
105 additions
and
147 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\Tactician\Handler\Mapping; | ||
|
||
use BadMethodCallException; | ||
use League\Tactician\Exception; | ||
|
||
/** | ||
* Thrown when a specific handler object can not be used on a command object. | ||
* | ||
* The most common reason is the receiving method is missing or incorrectly | ||
* named. | ||
*/ | ||
final class MethodDoesNotExist extends BadMethodCallException implements Exception | ||
{ | ||
/** @var object */ | ||
private $command; | ||
|
||
public static function on(string $className, string $methodName): self | ||
{ | ||
return new self( | ||
"The handler method {$className}::{$methodName} does not exist. Please check your Tactician mapping " . | ||
"configuration or check verify that {$methodName} is actually declared in {$className}" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\Tactician\Tests\Handler\Mapping; | ||
|
||
use League\Tactician\Exception; | ||
use League\Tactician\Handler\Mapping\MethodDoesNotExist; | ||
use League\Tactician\Tests\Fixtures\Handler\ConcreteMethodsHandler; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \League\Tactician\Handler\Mapping\MethodDoesNotExist | ||
*/ | ||
class MethodDoesNotExistTest extends TestCase | ||
{ | ||
public function testExceptionContainsDebuggingInfo() : void | ||
{ | ||
$exception = MethodDoesNotExist::on(ConcreteMethodsHandler::class, 'handleTaskCompletedCommand'); | ||
|
||
self::assertInstanceOf(Exception::class, $exception); | ||
self::assertStringContainsString(ConcreteMethodsHandler::class, $exception->getMessage()); | ||
self::assertStringContainsString('handleTaskCompletedCommand', $exception->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace League\Tactician\Tests\Handler\Mapping; | ||
|
||
use League\Tactician\Handler\Mapping\MethodDoesNotExist; | ||
use League\Tactician\Handler\Mapping\MethodToCall; | ||
use League\Tactician\Tests\Fixtures\Command\CompleteTaskCommand; | ||
use League\Tactician\Tests\Fixtures\Handler\ConcreteMethodsHandler; | ||
use League\Tactician\Tests\Fixtures\Handler\DynamicMethodsHandler; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class MethodToCallTest extends TestCase | ||
{ | ||
public function testBoringGettersAndSetters(): void | ||
{ | ||
$methodToCall = new MethodToCall(ConcreteMethodsHandler::class, 'handleTaskCompletedCommand'); | ||
|
||
self::assertEquals(ConcreteMethodsHandler::class, $methodToCall->getClassName()); | ||
self::assertEquals('handleTaskCompletedCommand', $methodToCall->getMethodName()); | ||
} | ||
|
||
public function testMissingMethodOnHandlerObjectIsDetected(): void | ||
{ | ||
$this->expectException(MethodDoesNotExist::class); | ||
new MethodToCall(CompleteTaskCommand::class, 'someMethodThatDoesNotExist'); | ||
} | ||
|
||
public function testDynamicMethodNamesAreSupported(): void | ||
{ | ||
$methodToCall = new MethodToCall(DynamicMethodsHandler::class, 'someMethodThatDoesNotExist'); | ||
|
||
self::assertEquals(DynamicMethodsHandler::class, $methodToCall->getClassName()); | ||
self::assertEquals('someMethodThatDoesNotExist', $methodToCall->getMethodName()); | ||
} | ||
} |