You've already forked Php-Template
feat: implement command bus with attribute-based handler resolution and add example command and handler (#27)
All checks were successful
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m13s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m24s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m58s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m20s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m5s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m0s
All checks were successful
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m13s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m24s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m58s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m20s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m5s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m0s
Reviewed-on: #27 Co-authored-by: Ron Rise <ron@siteworxpro.com> Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #27.
This commit is contained in:
36
tests/CommandBus/AttributeLocatorTest.php
Normal file
36
tests/CommandBus/AttributeLocatorTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\CommandBus;
|
||||
|
||||
use League\Tactician\Exception\CanNotInvokeHandlerException;
|
||||
use Siteworxpro\App\CommandBus\AttributeLocator;
|
||||
use Siteworxpro\App\CommandBus\Commands\ExampleCommand;
|
||||
use Siteworxpro\App\CommandBus\Handlers\ExampleHandler;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
class AttributeLocatorTest extends Unit
|
||||
{
|
||||
private const array HANDLERS = [
|
||||
ExampleCommand::class => ExampleHandler::class,
|
||||
];
|
||||
|
||||
public function testResolvesFiles(): void
|
||||
{
|
||||
$attributeLocator = new AttributeLocator();
|
||||
|
||||
foreach (self::HANDLERS as $command => $handler) {
|
||||
$class = $attributeLocator->getHandlerForCommand($command);
|
||||
$this->assertInstanceOf($handler, $class);
|
||||
}
|
||||
}
|
||||
|
||||
public function testThrowsOnCannotResolve(): void
|
||||
{
|
||||
$attributeLocator = new AttributeLocator();
|
||||
|
||||
$this->expectException(CanNotInvokeHandlerException::class);
|
||||
$attributeLocator->getHandlerForCommand('NonExistentCommand');
|
||||
}
|
||||
}
|
||||
32
tests/CommandBus/Handlers/ExampleHandlerTest.php
Normal file
32
tests/CommandBus/Handlers/ExampleHandlerTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Siteworxpro\Tests\CommandBus\Handlers;
|
||||
|
||||
use Siteworxpro\App\CommandBus\Commands\Command;
|
||||
use Siteworxpro\App\CommandBus\Commands\ExampleCommand;
|
||||
use Siteworxpro\App\CommandBus\Handlers\ExampleHandler;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
class ExampleHandlerTest extends Unit
|
||||
{
|
||||
public function testExampleCommand(): void
|
||||
{
|
||||
$command = new ExampleCommand('test payload');
|
||||
$this->assertEquals('test payload', $command->getName());
|
||||
|
||||
$handler = new ExampleHandler();
|
||||
$result = $handler($command);
|
||||
$this->assertEquals('Hello, test payload!', $result);
|
||||
}
|
||||
|
||||
public function testThrowsException(): void
|
||||
{
|
||||
$class = new readonly class extends Command
|
||||
{
|
||||
};
|
||||
|
||||
$this->expectException(\TypeError::class);
|
||||
$handler = new ExampleHandler();
|
||||
$handler($class);
|
||||
}
|
||||
}
|
||||
23
tests/GrpcHandlers/GreeterHandlerTest.php
Normal file
23
tests/GrpcHandlers/GreeterHandlerTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\GrpcHandlers;
|
||||
|
||||
use Siteworxpro\Tests\Unit;
|
||||
use Spiral\RoadRunner\GRPC\ContextInterface;
|
||||
|
||||
class GreeterHandlerTest extends Unit
|
||||
{
|
||||
public function testSayHello(): void
|
||||
{
|
||||
$request = new \GRPC\Greeter\HelloRequest();
|
||||
$request->setName('World');
|
||||
|
||||
$context = \Mockery::mock(ContextInterface::class);
|
||||
|
||||
$handler = new \Siteworxpro\App\GrpcHandlers\GreeterHandler();
|
||||
$response = $handler->SayHello($context, $request);
|
||||
$this->assertEquals('Hello World', $response->getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user