Skip to content

Commit

Permalink
test: add coverage for CommandNameNotResolvable (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Longshaw <[email protected]>
  • Loading branch information
ben-challis and alexlongshaw authored May 28, 2024
1 parent b4174ed commit c70c451
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/unit/Command/Naming/CommandNameNotResolvableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\Lendable\Message\Command\Naming;

use Lendable\Message\Command\Command;
use Lendable\Message\Command\Naming\CommandNameNotResolvable;
use Lendable\Message\CorrelationId;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DisableReturnValueGenerationForTestDoubles;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Lendable\Message\Command\ExampleFooCommand;

#[CoversClass(CommandNameNotResolvable::class)]
#[DisableReturnValueGenerationForTestDoubles]
final class CommandNameNotResolvableTest extends TestCase
{
#[Test]
public function it_can_be_constructed_from_a_command(): void
{
$command = ExampleFooCommand::fresh(CorrelationId::generate());
$exception = CommandNameNotResolvable::for($command);

self::assertSame($this->expectedExceptionMessage($command), $exception->getMessage());
self::assertNull($exception->getPrevious());
}

#[Test]
public function it_can_be_constructed_from_a_command_and_triggering_throwable(): void
{
$command = ExampleFooCommand::fresh(CorrelationId::generate());
$previous = new \RuntimeException();
$exception = CommandNameNotResolvable::for($command, $previous);

self::assertSame($this->expectedExceptionMessage($command), $exception->getMessage());
self::assertSame($previous, $exception->getPrevious());
}

private function expectedExceptionMessage(Command $command): string
{
return \sprintf('Command message name for %s<%s> could not be resolved.', $command::class, $command->id()->toString());
}
}

0 comments on commit c70c451

Please sign in to comment.