Skip to content

Commit 74ae886

Browse files
authored
Merge pull request #12 from dmt-software/1.2
update validator to enable attribute support
2 parents 361623b + d1441d0 commit 74ae886

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": ">=8.0",
1515
"league/tactician": "^1.0",
16-
"symfony/validator": "^5.1"
16+
"symfony/validator": "^5.1|^6.0"
1717
},
1818
"autoload": {
1919
"psr-4": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace DMT\Test\CommandBus\Fixtures;
4+
5+
use Symfony\Component\Validator\Constraints as Assert;
6+
7+
class AttributeReaderCommand
8+
{
9+
#[Assert\NotNull()]
10+
protected ?string $prop = null;
11+
12+
public function getProp(): ?string
13+
{
14+
return $this->prop;
15+
}
16+
17+
public function setProp($prop): void
18+
{
19+
$this->prop = $prop;
20+
}
21+
}

tests/Validator/ValidationMiddlewareTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DMT\CommandBus\Validator\ValidationException;
66
use DMT\CommandBus\Validator\ValidationMiddleware;
77
use DMT\Test\CommandBus\Fixtures\AnnotationReaderCommand;
8+
use DMT\Test\CommandBus\Fixtures\AttributeReaderCommand;
89
use DMT\Test\CommandBus\Fixtures\ClassMetadataCommand;
910
use PHPUnit\Framework\Attributes\DataProvider;
1011
use PHPUnit\Framework\TestCase;
@@ -59,6 +60,15 @@ public function testAnnotationReaderValidator(): void
5960
$middleware->execute(new AnnotationReaderCommand(), 'gettype');
6061
}
6162

63+
public function testAttributeReaderValidator(): void
64+
{
65+
$this->expectException(ValidationException::class);
66+
$this->expectExceptionMessageMatches("~Invalid command .* given~");
67+
68+
$middleware = new ValidationMiddleware();
69+
$middleware->execute(new AttributeReaderCommand(), 'gettype');
70+
}
71+
6272
#[DataProvider(methodName: "provideConstraintViolations")]
6373
public function testInvalidCommand(ConstraintViolationList $violations): void
6474
{

0 commit comments

Comments
 (0)