Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"require": {
"php": ">=8.0",
"league/tactician": "^1.0",
"symfony/validator": "^5.1"
"symfony/validator": "^5.1|^6.0"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 21 additions & 0 deletions tests/Fixtures/AttributeReaderCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace DMT\Test\CommandBus\Fixtures;

use Symfony\Component\Validator\Constraints as Assert;

class AttributeReaderCommand
{
#[Assert\NotNull()]
protected ?string $prop = null;

public function getProp(): ?string
{
return $this->prop;
}

public function setProp($prop): void
{
$this->prop = $prop;
}
}
10 changes: 10 additions & 0 deletions tests/Validator/ValidationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DMT\CommandBus\Validator\ValidationException;
use DMT\CommandBus\Validator\ValidationMiddleware;
use DMT\Test\CommandBus\Fixtures\AnnotationReaderCommand;
use DMT\Test\CommandBus\Fixtures\AttributeReaderCommand;
use DMT\Test\CommandBus\Fixtures\ClassMetadataCommand;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -59,6 +60,15 @@ public function testAnnotationReaderValidator(): void
$middleware->execute(new AnnotationReaderCommand(), 'gettype');
}

public function testAttributeReaderValidator(): void
{
$this->expectException(ValidationException::class);
$this->expectExceptionMessageMatches("~Invalid command .* given~");

$middleware = new ValidationMiddleware();
$middleware->execute(new AttributeReaderCommand(), 'gettype');
}

#[DataProvider(methodName: "provideConstraintViolations")]
public function testInvalidCommand(ConstraintViolationList $violations): void
{
Expand Down