Completed
Push — master ( 1c5373...ea381d )
by Ross
9s
created

ValidatorMiddlewareTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testExecute() 0 16 2
A testExecuteWithoutViolations() 0 9 1
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')]);
0 ignored issues
show
Documentation introduced by
array(\Mockery::mock('Sy...\ConstraintViolation')) is of type array<integer,object<Moc...kery\\MockInterface>"}>, but the function expects a array<integer,object<Sym...intViolationInterface>>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
37
        $this->validator->shouldReceive('validate')->once()->andReturn($list);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Symfony\Component...tor\ValidatorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Symfony\Component...tor\ValidatorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
56
        $this->middleware->execute(new FakeCommand(), function () {
57
        });
58
    }
59
}
60