ValidationTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 5
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validation() 0 19 1
1
<?php
2
3
namespace Zenstruck\RedirectBundle\Tests\Functional;
4
5
use Symfony\Component\Validator\Validator\RecursiveValidator;
6
use Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyRedirect;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class ValidationTest extends FunctionalTest
12
{
13
    /**
14
     * @test
15
     */
16
    public function validation()
17
    {
18
        /** @var RecursiveValidator $validator */
19
        $validator = self::$kernel->getContainer()->get('validator');
20
21
        $this->assertCount(0, $validator->validate(new DummyRedirect('/foo', '/bar')));
22
23
        $errors = $validator->validate(new DummyRedirect(null, null));
24
        $this->assertCount(2, $errors);
25
        $this->assertSame('Please enter a source.', $errors[0]->getMessage());
26
        $this->assertSame('source', $errors[0]->getPropertyPath());
27
        $this->assertSame('Please enter a destination.', $errors[1]->getMessage());
28
        $this->assertSame('destination', $errors[1]->getPropertyPath());
29
30
        $errors = $validator->validate(new DummyRedirect('/301-redirect', '/foo'));
31
        $this->assertCount(1, $errors);
32
        $this->assertSame('The source is already used.', $errors[0]->getMessage());
33
        $this->assertSame('source', $errors[0]->getPropertyPath());
34
    }
35
}
36