Completed
Push — master ( 96bb84...2f170a )
by Tobias
04:46 queued 01:16
created

ValidationAnnotationTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testExtractAnnotation() 0 22 2
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 Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest;
15
use Translation\Extractor\Tests\Resources;
16
use Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation;
17
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
18
use Doctrine\Common\Annotations\AnnotationReader;
19
20
/**
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
final class ValidationAnnotationTest extends BasePHPVisitorTest
24
{
25
    public function testExtractAnnotation()
26
    {
27
        //use correct factory class depending on whether using Symfony 2 or 3
28
        if (class_exists('Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory')) {
29
            $metadataFactoryClass = 'Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory';
30
        } else {
31
            $metadataFactoryClass = 'Symfony\Component\Validator\Mapping\ClassMetadataFactory';
32
        }
33
34
        $factory = new $metadataFactoryClass(new AnnotationLoader(new AnnotationReader()));
35
        $extractor = new ValidationAnnotation($factory);
36
        $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotation::class);
37
38
        $this->assertCount(2, $collection);
39
        $source = $collection->get(0);
40
        $this->assertEquals('start.null', $source->getMessage());
41
        $this->assertEquals('validators', $source->getContext()['domain']);
42
43
        $source = $collection->get(1);
44
        $this->assertEquals('end.blank', $source->getMessage());
45
        $this->assertEquals('validators', $source->getContext()['domain']);
46
    }
47
}
48