Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed Nov 4, 2023
1 parent 075c74f commit f917f9d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Bus/NativeMessageBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Yceruto\Messenger\Middleware\Middleware;
use Yceruto\Messenger\Middleware\MiddlewareStack;
use Yceruto\Messenger\Model\Envelop;
use Yceruto\Messenger\Model\Envelope;
use Yceruto\Messenger\Model\Message;

final readonly class NativeMessageBus implements MessageBus
Expand All @@ -21,7 +21,7 @@ public function __construct(iterable $middlewares)

public function dispatch(Message $message): mixed
{
$envelop = Envelop::wrap($message);
$envelop = Envelope::wrap($message);

$this->stack->handle($envelop);

Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/HandlerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Psr\Container\ContainerInterface;
use Yceruto\Messenger\Error\HandlerNotFound;
use Yceruto\Messenger\Model\Envelop;
use Yceruto\Messenger\Model\Envelope;

/**
* Handles a message with a handler.
Expand All @@ -18,7 +18,7 @@ public function __construct(private ContainerInterface $handlers)
/**
* {@inheritdoc}
*/
public function handle(Envelop $envelop, callable $next): void
public function handle(Envelope $envelop, callable $next): void
{
$class = get_class($envelop->message);

Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Yceruto\Messenger\Middleware;

use Yceruto\Messenger\Model\Envelop;
use Yceruto\Messenger\Model\Envelope;

/**
* Handles an Envelope object and pass control to the next middleware in the stack.
*/
interface Middleware
{
/**
* @param callable(Envelop): void $next
* @param callable(Envelope): void $next
*/
public function handle(Envelop $envelop, callable $next): void;
public function handle(Envelope $envelop, callable $next): void;
}
6 changes: 3 additions & 3 deletions src/Middleware/MiddlewareStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Yceruto\Messenger\Middleware;

use Yceruto\Messenger\Model\Envelop;
use Yceruto\Messenger\Model\Envelope;

/**
* @internal
Expand All @@ -16,7 +16,7 @@ public function __construct(private iterable $middlewares)
{
}

public function handle(Envelop $envelop): void
public function handle(Envelope $envelop): void
{
$next = static fn (): null => null;

Expand All @@ -27,7 +27,7 @@ public function handle(Envelop $envelop): void
}

foreach (array_reverse($middlewares) as $middleware) {
$next = static fn (Envelop $envelop): null => $middleware->handle($envelop, $next);
$next = static fn (Envelope $envelop): null => $middleware->handle($envelop, $next);
}

$next($envelop);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Envelop.php → src/Model/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Yceruto\Messenger\Model;

final class Envelop
final class Envelope
{
public mixed $result = null;

Expand Down
6 changes: 3 additions & 3 deletions tests/Middleware/HandlerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Yceruto\Messenger\Error\HandlerNotFound;
use Yceruto\Messenger\Handler\HandlersLocator;
use Yceruto\Messenger\Middleware\HandlerMiddleware;
use Yceruto\Messenger\Model\Envelop;
use Yceruto\Messenger\Model\Envelope;
use Yceruto\Messenger\Tests\Fixtures\CreateProduct;
use Yceruto\Messenger\Tests\Fixtures\MessageWithoutHandler;

Expand All @@ -24,7 +24,7 @@ protected function setUp(): void
public function testHandle(): void
{
$message = new CreateProduct();
$envelop = Envelop::wrap($message);
$envelop = Envelope::wrap($message);
$this->handlerMiddleware->handle($envelop, static fn () => null);

$this->assertSame($message, $envelop->result);
Expand All @@ -35,7 +35,7 @@ public function testNotHandlerFound(): void
$this->expectException(HandlerNotFound::class);
$this->expectExceptionMessage('Handler not found for message "Yceruto\Messenger\Tests\Fixtures\MessageWithoutHandler"');

$envelop = Envelop::wrap(new MessageWithoutHandler());
$envelop = Envelope::wrap(new MessageWithoutHandler());
$this->handlerMiddleware->handle($envelop, static fn () => null);
}
}
10 changes: 5 additions & 5 deletions tests/Middleware/MiddlewareStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
use PHPUnit\Framework\TestCase;
use Yceruto\Messenger\Middleware\MiddlewareStack;
use Yceruto\Messenger\Middleware\Middleware;
use Yceruto\Messenger\Model\Envelop;
use Yceruto\Messenger\Model\Envelope;
use Yceruto\Messenger\Tests\Fixtures\CreateProduct;

class MiddlewareStackTest extends TestCase
{
public function testHandle(): void
{
$middleware1 = new class() implements Middleware {
public function handle(Envelop $envelop, callable $next): void
public function handle(Envelope $envelop, callable $next): void
{
$envelop->result = '1';
$next($envelop);
}
};
$middleware2 = new class() implements Middleware {
public function handle(Envelop $envelop, callable $next): void
public function handle(Envelope $envelop, callable $next): void
{
$envelop->result .= '2';
$next($envelop);
}
};
$middleware3 = new class() implements Middleware {
public function handle(Envelop $envelop, callable $next): void
public function handle(Envelope $envelop, callable $next): void
{
$envelop->result .= '3';
$next($envelop);
}
};
$stack = new MiddlewareStack([$middleware1, $middleware2, $middleware3]);
$envelop = Envelop::wrap(new CreateProduct());
$envelop = Envelope::wrap(new CreateProduct());
$stack->handle($envelop);

$this->assertSame('123', $envelop->result);
Expand Down

0 comments on commit f917f9d

Please sign in to comment.