Some checks failed
Deploy Application / deploy (push) Has been cancelled
98 lines
2.6 KiB
PHP
98 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Framework\LiveComponents\Middleware;
|
|
|
|
use App\Framework\LiveComponents\Contracts\LiveComponentContract;
|
|
use App\Framework\LiveComponents\Middleware\ComponentMiddlewareInterface;
|
|
use App\Framework\LiveComponents\ValueObjects\ActionParameters;
|
|
use App\Framework\LiveComponents\ValueObjects\ComponentUpdate;
|
|
|
|
/**
|
|
* Test Middleware for unit tests
|
|
*/
|
|
final class TestMiddleware1 implements ComponentMiddlewareInterface
|
|
{
|
|
private array $executionOrder;
|
|
|
|
public function __construct(
|
|
array &$executionOrder
|
|
) {
|
|
$this->executionOrder = &$executionOrder;
|
|
}
|
|
|
|
public function handle(
|
|
LiveComponentContract $component,
|
|
string $action,
|
|
ActionParameters $params,
|
|
callable $next
|
|
): ComponentUpdate {
|
|
$this->executionOrder[] = 'middleware1';
|
|
return $next($component, $action, $params);
|
|
}
|
|
}
|
|
|
|
final class TestMiddleware2 implements ComponentMiddlewareInterface
|
|
{
|
|
private array $executionOrder;
|
|
|
|
public function __construct(
|
|
array &$executionOrder
|
|
) {
|
|
$this->executionOrder = &$executionOrder;
|
|
}
|
|
|
|
public function handle(
|
|
LiveComponentContract $component,
|
|
string $action,
|
|
ActionParameters $params,
|
|
callable $next
|
|
): ComponentUpdate {
|
|
$this->executionOrder[] = 'middleware2';
|
|
return $next($component, $action, $params);
|
|
}
|
|
}
|
|
|
|
final class TestPassThroughMiddleware implements ComponentMiddlewareInterface
|
|
{
|
|
public function handle(
|
|
LiveComponentContract $component,
|
|
string $action,
|
|
ActionParameters $params,
|
|
callable $next
|
|
): ComponentUpdate {
|
|
return $next($component, $action, $params);
|
|
}
|
|
}
|
|
|
|
final class TestCaptureMiddleware implements ComponentMiddlewareInterface
|
|
{
|
|
private ?LiveComponentContract $capturedComponent;
|
|
private ?string $capturedAction;
|
|
private ?ActionParameters $capturedParams;
|
|
|
|
public function __construct(
|
|
?LiveComponentContract &$capturedComponent,
|
|
?string &$capturedAction,
|
|
?ActionParameters &$capturedParams
|
|
) {
|
|
$this->capturedComponent = &$capturedComponent;
|
|
$this->capturedAction = &$capturedAction;
|
|
$this->capturedParams = &$capturedParams;
|
|
}
|
|
|
|
public function handle(
|
|
LiveComponentContract $component,
|
|
string $action,
|
|
ActionParameters $params,
|
|
callable $next
|
|
): ComponentUpdate {
|
|
$this->capturedComponent = $component;
|
|
$this->capturedAction = $action;
|
|
$this->capturedParams = $params;
|
|
return $next($component, $action, $params);
|
|
}
|
|
}
|
|
|