NoExistingRouteValidatorTest::testInvalid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Beelab\SimplePageBundle\Tests\Validator\Constraints;
4
5
use Beelab\SimplePageBundle\Validator\Constraints\NoExistingRoute;
6
use Beelab\SimplePageBundle\Validator\Constraints\NoExistingRouteValidator;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Routing\Route;
9
use Symfony\Component\Routing\RouterInterface;
10
use Symfony\Component\Validator\Context\ExecutionContextInterface;
11
12
final class NoExistingRouteValidatorTest extends TestCase
13
{
14
    protected $router;
15
    protected $context;
16
17
    protected function setUp(): void
18
    {
19
        $this->router = $this->createMock(RouterInterface::class);
20
        $this->context = $this->createMock(ExecutionContextInterface::class);
21
    }
22
23
    public function testInvalid(): void
24
    {
25
        $validator = new NoExistingRouteValidator($this->router);
0 ignored issues
show
Documentation introduced by
$this->router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

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...
26
        $validator->initialize($this->context);
0 ignored issues
show
Documentation introduced by
$this->context is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...cutionContextInterface>.

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...
27
        $routes = ['foo_bar' => new Route('/foobar')];
28
        $constraint = new NoExistingRoute();
29
30
        $this->router->expects($this->once())->method('getRouteCollection')->willReturn($routes);
31
        $this->context->expects($this->atLeastOnce())->method('addViolation');
32
33
        $validator->validate('foobar', $constraint);
34
    }
35
36
    public function testInvalidWithoutRoute(): void
37
    {
38
        $validator = new NoExistingRouteValidator($this->router, false);
0 ignored issues
show
Documentation introduced by
$this->router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

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...
39
        $validator->initialize($this->context);
0 ignored issues
show
Documentation introduced by
$this->context is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...cutionContextInterface>.

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...
40
        $routes = ['bar_foo' => new Route('/barfoo')];
41
        $constraint = new NoExistingRoute();
42
43
        $this->router->expects($this->once())->method('getRouteCollection')->willReturn($routes);
44
        $this->context->expects($this->atLeastOnce())->method('addViolation');
45
46
        $validator->validate('barfoo', $constraint);
47
    }
48
49
    public function testValid(): void
50
    {
51
        $validator = new NoExistingRouteValidator($this->router, false);
0 ignored issues
show
Documentation introduced by
$this->router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

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...
52
        $validator->initialize($this->context);
0 ignored issues
show
Documentation introduced by
$this->context is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...cutionContextInterface>.

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...
53
        $routes = ['foo_baz' => new Route('/foobaz')];
54
        $constraint = new NoExistingRoute();
55
56
        $this->router->expects($this->once())->method('getRouteCollection')->willReturn($routes);
57
        $this->context->expects($this->never())->method('addViolation');
58
59
        $validator->validate('bazbaz', $constraint);
60
    }
61
}
62