Skip to content

Commit 361623b

Browse files
authored
Merge pull request #11 from dmt-software/1.1
upgrade to php 8
2 parents 748704e + f1eae5b commit 361623b

File tree

4 files changed

+40
-73
lines changed

4 files changed

+40
-73
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=7.2",
14+
"php": ">=8.0",
1515
"league/tactician": "^1.0",
1616
"symfony/validator": "^5.1"
1717
},
@@ -25,7 +25,7 @@
2525
"doctrine/cache": "Enables adding constraints using annotations"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": ">=7.2",
28+
"phpunit/phpunit": "^12.0",
2929
"doctrine/annotations": "^1.6"
3030
},
3131
"autoload-dev": {

phpunit.xml.dist

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
54
bootstrap="vendor/autoload.php"
6-
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
12-
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
beStrictAboutCoverageMetadata="true"
8+
beStrictAboutOutputDuringTests="true"
9+
displayDetailsOnPhpunitDeprecations="true"
10+
failOnPhpunitDeprecation="true"
11+
failOnRisky="true"
12+
failOnWarning="true">
1313
<testsuites>
14-
<testsuite name="Test Suite">
15-
<directory>./tests/</directory>
14+
<testsuite name="default">
15+
<directory>tests</directory>
1616
</testsuite>
1717
</testsuites>
18-
<filter>
19-
<whitelist>
20-
<directory>./src/</directory>
21-
</whitelist>
22-
</filter>
18+
19+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
20+
<include>
21+
<directory>src</directory>
22+
</include>
23+
</source>
2324
</phpunit>

src/Validator/ValidationMiddleware.php

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace DMT\CommandBus\Validator;
44

5-
use Doctrine\Common\Annotations\AnnotationException;
65
use Doctrine\Common\Annotations\AnnotationReader;
7-
use Doctrine\Common\Annotations\CachedReader;
8-
use Doctrine\Common\Cache\ArrayCache;
96
use League\Tactician\Middleware;
107
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
118
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
@@ -22,16 +19,12 @@
2219
*/
2320
class ValidationMiddleware implements Middleware
2421
{
25-
/**
26-
* @var ValidatorInterface
27-
*/
28-
protected $validator;
22+
protected ValidatorInterface|RecursiveValidator $validator;
2923

3024
/**
3125
* ValidationMiddleware constructor.
3226
*
3327
* @param ValidatorInterface|null $validator
34-
* @throws AnnotationException
3528
*/
3629
public function __construct(ValidatorInterface $validator = null)
3730
{
@@ -44,7 +37,7 @@ public function __construct(ValidatorInterface $validator = null)
4437
*
4538
* @return mixed
4639
*/
47-
public function execute($command, callable $next)
40+
public function execute($command, callable $next): mixed
4841
{
4942
$violations = $this->validator->validate($command);
5043

@@ -60,25 +53,12 @@ public function execute($command, callable $next)
6053
return $next($command);
6154
}
6255

63-
/**
64-
* Get a default validator.
65-
*
66-
* By default the usage of annotations to validate object is off. To enable annotation configuration install
67-
* `doctrine/annotations`.
68-
*
69-
* @return RecursiveValidator|ValidatorInterface
70-
* @throws AnnotationException
71-
*/
7256
protected function getDefaultValidator(): ValidatorInterface
7357
{
7458
$loaders = [new StaticMethodLoader()];
7559

7660
if (class_exists(AnnotationReader::class)) {
77-
if (class_exists(ArrayCache::class)) {
78-
$loaders[] = new AnnotationLoader(new CachedReader(new AnnotationReader(), new ArrayCache()));
79-
} else {
80-
$loaders[] = new AnnotationLoader(new AnnotationReader());
81-
}
61+
$loaders[] = new AnnotationLoader(new AnnotationReader());
8262
}
8363

8464
return (new ValidatorBuilder())

tests/Validator/ValidationMiddlewareTest.php

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use DMT\CommandBus\Validator\ValidationMiddleware;
77
use DMT\Test\CommandBus\Fixtures\AnnotationReaderCommand;
88
use DMT\Test\CommandBus\Fixtures\ClassMetadataCommand;
9-
use Doctrine\Common\Annotations\AnnotationException;
9+
use PHPUnit\Framework\Attributes\DataProvider;
1010
use PHPUnit\Framework\TestCase;
11+
use stdClass;
1112
use Symfony\Component\Validator\ConstraintViolation;
1213
use Symfony\Component\Validator\ConstraintViolationList;
1314
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -19,13 +20,10 @@
1920
*/
2021
class ValidationMiddlewareTest extends TestCase
2122
{
22-
/**
23-
* @throws \ReflectionException
24-
* @throws AnnotationException
25-
*/
26-
public function testValidCommand()
23+
public function testValidCommand(): void
2724
{
28-
$validator = static::getMockForAbstractClass(ValidatorInterface::class);
25+
/** @var ValidatorInterface $validator */
26+
$validator = static::getMockBuilder(ValidatorInterface::class)->getMock();
2927
$validator->expects(static::once())
3028
->method('validate')
3129
->willReturn(new ConstraintViolationList());
@@ -43,10 +41,7 @@ function ($command) {
4341
static::assertSame($expected, $result);
4442
}
4543

46-
/**
47-
* @throws AnnotationException
48-
*/
49-
public function testLoadClassMetadataValidator()
44+
public function testLoadClassMetadataValidator(): void
5045
{
5146
$this->expectException(ValidationException::class);
5247
$this->expectExceptionMessageMatches("~Invalid command .* given~");
@@ -55,10 +50,7 @@ public function testLoadClassMetadataValidator()
5550
$middleware->execute(new ClassMetadataCommand(), 'gettype');
5651
}
5752

58-
/**
59-
* @throws AnnotationException
60-
*/
61-
public function testAnnotationReaderValidator()
53+
public function testAnnotationReaderValidator(): void
6254
{
6355
$this->expectException(ValidationException::class);
6456
$this->expectExceptionMessageMatches("~Invalid command .* given~");
@@ -67,25 +59,19 @@ public function testAnnotationReaderValidator()
6759
$middleware->execute(new AnnotationReaderCommand(), 'gettype');
6860
}
6961

70-
/**
71-
* @dataProvider provideConstraintViolations
72-
*
73-
* @param ConstraintViolationList $violations
74-
*
75-
* @throws \ReflectionException
76-
* @throws AnnotationException
77-
*/
78-
public function testInvalidCommand(ConstraintViolationList $violations)
62+
#[DataProvider(methodName: "provideConstraintViolations")]
63+
public function testInvalidCommand(ConstraintViolationList $violations): void
7964
{
80-
$validator = static::getMockForAbstractClass(ValidatorInterface::class);
65+
/** @var ValidatorInterface $validator */
66+
$validator = static::getMockBuilder(ValidatorInterface::class)->getMock();
8167
$validator->expects(static::once())
8268
->method('validate')
8369
->willReturn($violations);
8470

8571
try {
8672
$middleware = new ValidationMiddleware($validator);
8773
$middleware->execute(
88-
new \stdClass(),
74+
new stdClass(),
8975
function ($command) {
9076
return $command;
9177
}
@@ -95,20 +81,20 @@ function ($command) {
9581
}
9682
}
9783

98-
public function provideConstraintViolations(): array
84+
public static function provideConstraintViolations(): array
9985
{
10086
return [
10187
[
10288
new ConstraintViolationList(
103-
[new ConstraintViolation('missing property $foo', null, ['foo'], new \StdClass(), 'foo', null)]
89+
[new ConstraintViolation('missing property $foo', null, ['foo'], new stdClass(), 'foo', null)]
10490
)
10591
],
10692
[
10793
new ConstraintViolationList(
10894
[
109-
new ConstraintViolation('missing property $foo', null, ['foo'], new \StdClass(), 'foo', null),
110-
new ConstraintViolation('missing property $bar', null, ['bar'], new \StdClass(), 'bar', null),
111-
new ConstraintViolation('missing property $baz', null, ['baz'], new \StdClass(), 'baz', null),
95+
new ConstraintViolation('missing property $foo', null, ['foo'], new stdClass(), 'foo', null),
96+
new ConstraintViolation('missing property $bar', null, ['bar'], new stdClass(), 'bar', null),
97+
new ConstraintViolation('missing property $baz', null, ['baz'], new stdClass(), 'baz', null),
11298
]
11399
)
114100
],

0 commit comments

Comments
 (0)