|
1
|
|
|
<?php |
|
2
|
|
|
namespace League\Tactician\Bundle\Tests\Middleware; |
|
3
|
|
|
|
|
4
|
|
|
use League\Tactician\Bundle\Middleware\InvalidCommandException; |
|
5
|
|
|
use League\Tactician\Bundle\Middleware\ValidatorMiddleware; |
|
6
|
|
|
use League\Tactician\Bundle\Tests\Fake\FakeCommand; |
|
7
|
|
|
use Mockery\MockInterface; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Component\Validator\ConstraintViolationList; |
|
10
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
|
11
|
|
|
|
|
12
|
|
|
class ValidatorMiddlewareTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ValidatorInterface | MockInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $validator; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var ValidatorMiddleware |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $middleware; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
|
|
28
|
|
|
$this->validator = \Mockery::mock('Symfony\Component\Validator\Validator\ValidatorInterface'); |
|
29
|
|
|
|
|
30
|
|
|
$this->middleware = new ValidatorMiddleware($this->validator); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testExecute() |
|
34
|
|
|
{ |
|
35
|
|
|
$list = new ConstraintViolationList([\Mockery::mock('Symfony\Component\Validator\ConstraintViolation')]); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$this->validator->shouldReceive('validate')->once()->andReturn($list); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
try { |
|
40
|
|
|
|
|
41
|
|
|
$this->middleware->execute(new FakeCommand(), function () { |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
} catch (InvalidCommandException $e) { |
|
45
|
|
|
$this->assertEquals($list, $e->getViolations()); |
|
46
|
|
|
$this->assertEquals(new FakeCommand(), $e->getCommand()); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testExecuteWithoutViolations() |
|
51
|
|
|
{ |
|
52
|
|
|
$list = new ConstraintViolationList([]); |
|
53
|
|
|
|
|
54
|
|
|
$this->validator->shouldReceive('validate')->once()->andReturn($list); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$this->middleware->execute(new FakeCommand(), function () { |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: