Files
michaelschiemer/tests/Unit/Framework/LiveComponents/Security/TestComponents.php
2025-11-24 21:28:25 +01:00

128 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Framework\LiveComponents\Security;
use App\Application\LiveComponents\Counter\CounterState;
use App\Framework\LiveComponents\Attributes\Action;
use App\Framework\LiveComponents\Contracts\LiveComponentContract;
use App\Framework\LiveComponents\ValueObjects\ComponentId;
use App\Framework\LiveComponents\ValueObjects\ComponentRenderData;
/**
* Test Component with valid action
*/
final class ValidActionComponent implements LiveComponentContract
{
public function __construct(
public ComponentId $id,
public CounterState $state
) {
}
public function getRenderData(): ComponentRenderData
{
return new ComponentRenderData(templatePath: 'test', data: []);
}
#[Action]
public function validAction(): CounterState
{
return $this->state;
}
}
/**
* Test Component with private action (should fail validation)
*/
final class PrivateActionComponent implements LiveComponentContract
{
public function __construct(
public ComponentId $id,
public CounterState $state
) {
}
public function getRenderData(): ComponentRenderData
{
return new ComponentRenderData(templatePath: 'test', data: []);
}
#[Action]
private function privateAction(): CounterState
{
return $this->state;
}
}
/**
* Test Component with static action (should fail validation)
*/
final class StaticActionComponent implements LiveComponentContract
{
public function __construct(
public ComponentId $id,
public CounterState $state
) {
}
public function getRenderData(): ComponentRenderData
{
return new ComponentRenderData(templatePath: 'test', data: []);
}
#[Action]
public static function staticAction(): CounterState
{
return CounterState::empty();
}
}
/**
* Test Component with primitive return type (should fail validation)
*/
final class PrimitiveReturnTypeComponent implements LiveComponentContract
{
public function __construct(
public ComponentId $id,
public CounterState $state
) {
}
public function getRenderData(): ComponentRenderData
{
return new ComponentRenderData(templatePath: 'test', data: []);
}
#[Action]
public function intAction(): int
{
return 42;
}
}
/**
* Test Component with array return type (should fail validation)
*/
final class ArrayReturnTypeComponent implements LiveComponentContract
{
public function __construct(
public ComponentId $id,
public CounterState $state
) {
}
public function getRenderData(): ComponentRenderData
{
return new ComponentRenderData(templatePath: 'test', data: []);
}
#[Action]
public function arrayAction(): array
{
return [];
}
}