Skip to content

Commit 90d46a2

Browse files
committed
Added tests
1 parent e66d105 commit 90d46a2

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

src/Visitor/Php/Symfony/Constraint.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
<?php
22

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+
312
namespace Translation\Extractor\Visitor\Php\Symfony;
413

514
use PhpParser\Node;
615
use PhpParser\NodeVisitor;
716
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
817

18+
/**
19+
* @author Luca Passini <[email protected]>
20+
*/
921
final class Constraint extends BasePHPVisitor implements NodeVisitor
1022
{
1123
const VALIDATORS_DOMAIN = 'validators';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Constraint;
17+
18+
/**
19+
* @author Tobias Nyholm <[email protected]>
20+
*/
21+
final class ConstraintTest extends BasePHPVisitorTest
22+
{
23+
public function testExtract()
24+
{
25+
$collection = $this->getSourceLocations(new Constraint(), Resources\Php\Symfony\Constraint::class);
26+
27+
$this->assertCount(2, $collection);
28+
29+
$first = $collection->get(0);
30+
$this->assertEquals('error.custom_not_blank', $first->getMessage());
31+
32+
$second = $collection->get(1);
33+
$this->assertEquals('error.custom_length', $second->getMessage());
34+
}
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Translation\Extractor\Tests\Resources\Php\Symfony;
4+
5+
use Symfony\Component\Validator\Constraints as Assert;
6+
use Symfony\Component\Validator\Constraints\NotBlank;
7+
8+
class Constraint
9+
{
10+
/**
11+
* @return array
12+
*/
13+
public function newAction()
14+
{
15+
$notBlankConstraint = new NotBlank([
16+
'message' => 'error.custom_not_blank',
17+
]);
18+
19+
$lengthConstraint = new Assert\Length([
20+
'min' => 6,
21+
'minMessage' => 'error.custom_length',
22+
]);
23+
24+
return [];
25+
}
26+
}

0 commit comments

Comments
 (0)