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
|
|
|
|