1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Tactician\Bundle\Tests\Middleware; |
4
|
|
|
|
5
|
|
|
use League\Tactician\Bundle\Middleware\InvalidCommandException; |
6
|
|
|
use League\Tactician\Bundle\Middleware\ValidatorMiddleware; |
7
|
|
|
use League\Tactician\Bundle\Tests\Fake\FakeCommand; |
8
|
|
|
use Mockery\MockInterface; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Symfony\Component\Validator\ConstraintViolationList; |
11
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
12
|
|
|
|
13
|
|
|
class ValidatorMiddlewareTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var ValidatorInterface | MockInterface |
17
|
|
|
*/ |
18
|
|
|
protected $validator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ValidatorMiddleware |
22
|
|
|
*/ |
23
|
|
|
protected $middleware; |
24
|
|
|
|
25
|
|
|
protected function setUp(): void |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$this->validator = \Mockery::mock('Symfony\Component\Validator\Validator\ValidatorInterface'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->middleware = new ValidatorMiddleware($this->validator); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testExecute() |
35
|
|
|
{ |
36
|
|
|
$list = new ConstraintViolationList([\Mockery::mock('Symfony\Component\Validator\ConstraintViolation')]); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$this->validator->shouldReceive('validate')->once()->andReturn($list); |
|
|
|
|
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
|
42
|
|
|
$this->middleware->execute(new FakeCommand(), function () { |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
} catch (InvalidCommandException $e) { |
46
|
|
|
$this->assertEquals($list, $e->getViolations()); |
47
|
|
|
$this->assertEquals(new FakeCommand(), $e->getCommand()); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testExecuteWithoutViolations() |
52
|
|
|
{ |
53
|
|
|
$list = new ConstraintViolationList([]); |
54
|
|
|
|
55
|
|
|
$this->validator->shouldReceive('validate')->once()->andReturn($list); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$this->middleware->execute(new FakeCommand(), function () { |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..