Completed
Push — master ( b11a4b...fca11f )
by Tobias
02:04
created

ValidationAnnotationTest::testExtractAnnotation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Extractor\Tests\Functional\Visitor\Php\Symfony;
13
14
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
15
use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest;
16
use Translation\Extractor\Tests\Resources;
17
use Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation;
18
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
19
use Doctrine\Common\Annotations\AnnotationReader;
20
21
/**
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
final class ValidationAnnotationTest extends BasePHPVisitorTest
25
{
26
    public function testExtractAnnotation()
27
    {
28
        $factory = new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader()));
29
        $extractor = new ValidationAnnotation($factory);
30
        $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotation::class);
31
32
        $this->assertCount(2, $collection);
33
        $source = $collection->get(0);
34
        $this->assertEquals('start.null', $source->getMessage());
35
        $this->assertEquals('validators', $source->getContext()['domain']);
36
37
        $source = $collection->get(1);
38
        $this->assertEquals('end.blank', $source->getMessage());
39
        $this->assertEquals('validators', $source->getContext()['domain']);
40
    }
41
42
    public function testExtractAnnotationError()
43
    {
44
        $factory = new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader()));
45
        $extractor = new ValidationAnnotation($factory);
46
        $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotationError::class);
47
48
        $errors = $collection->getErrors();
49
        $this->assertCount(1, $errors);
50
    }
51
}
52