ValidationTest::validation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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