react-command-bus/tests/CommandTest.php

40 lines
959 B
PHP
Raw Normal View History

<?php
namespace NoccyLabs\React\CommandBus;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(Command::class)]
class CommandTest extends \PHPUnit\Framework\TestCase
{
public function testCommandName()
{
$command = new Command("foobar", function () {});
$this->assertEquals('foobar', $command->getName());
}
public function testCommandExecution()
{
$hit = false;
$command = new Command("foobar", function () use (&$hit) { $hit=true; });
$context = new Context("foobar", []);
$command->call($context);
$this->assertEquals(true, $hit);
}
public function testCommandReflection()
{
$command = new Command("test", function (string $a, ?int $b, bool $c = false) { });
$expect = [
'a' => 'string',
'b' => 'int',
'c' => '?bool'
];
$this->assertEquals($expect, $command->parameters());
}
}