Skip to content

Commit f58bf61

Browse files
authored
Merge pull request #41 from php-translation/issue-39
Do not stop all visitors if FormVisitor fails
2 parents cfd04a6 + 19dde6e commit f58bf61

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

src/Visitor/Php/Symfony/FormTypeChoices.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PhpParser\Node;
1515
use PhpParser\Node\Stmt;
16-
use PhpParser\NodeTraverser;
1716
use PhpParser\NodeVisitor;
1817
use Translation\Extractor\Model\SourceLocation;
1918
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
@@ -41,7 +40,7 @@ public function enterNode(Node $node)
4140
// only Traverse *Type
4241
if ($node instanceof Stmt\Class_) {
4342
if (substr($node->name, -4) !== 'Type') {
44-
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
43+
return;
4544
}
4645
}
4746

src/Visitor/Php/Symfony/FormTypeLabelExplicit.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PhpParser\Node;
1515
use PhpParser\Node\Stmt;
16-
use PhpParser\NodeTraverser;
1716
use PhpParser\NodeVisitor;
1817
use Translation\Extractor\Model\SourceLocation;
1918
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
@@ -28,7 +27,7 @@ public function enterNode(Node $node)
2827
// only Traverse *Type
2928
if ($node instanceof Stmt\Class_) {
3029
if (substr($node->name, -4) !== 'Type') {
31-
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
30+
return;
3231
}
3332
}
3433

src/Visitor/Php/Symfony/FormTypeLabelImplicit.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PhpParser\Node;
1515
use PhpParser\Node\Stmt;
16-
use PhpParser\NodeTraverser;
1716
use PhpParser\NodeVisitor;
1817
use Translation\Extractor\Model\SourceLocation;
1918
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
@@ -28,7 +27,7 @@ public function enterNode(Node $node)
2827
// only Traverse *Type
2928
if ($node instanceof Stmt\Class_) {
3029
if (substr($node->name, -4) !== 'Type') {
31-
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
30+
return;
3231
}
3332
}
3433

src/Visitor/Php/Symfony/FormTypePlaceholder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PhpParser\Node;
1515
use PhpParser\Node\Stmt;
16-
use PhpParser\NodeTraverser;
1716
use PhpParser\NodeVisitor;
1817
use Translation\Extractor\Model\SourceLocation;
1918
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
@@ -28,7 +27,7 @@ public function enterNode(Node $node)
2827
// only Traverse *Type
2928
if ($node instanceof Stmt\Class_) {
3029
if (substr($node->name, -4) !== 'Type') {
31-
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
30+
return;
3231
}
3332
}
3433

tests/Functional/Visitor/Php/BasePHPVisitorTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ abstract class BasePHPVisitorTest extends \PHPUnit_Framework_TestCase
3131
protected function getSourceLocations($visitor, $namespaceForTestFile)
3232
{
3333
$extractor = new PHPFileExtractor();
34-
$extractor->addVisitor($visitor);
34+
35+
if (is_array($visitor)) {
36+
foreach ($visitor as $nodeVisitor) {
37+
$extractor->addVisitor($nodeVisitor);
38+
}
39+
} else {
40+
$extractor->addVisitor($visitor);
41+
}
3542

3643
$currentNamespace = explode('\\', __NAMESPACE__);
3744
$fileNamespace = explode('\\', $namespaceForTestFile);

tests/Functional/Visitor/Php/Symfony/FormTypePlaceholderTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest;
1515
use Translation\Extractor\Tests\Resources;
1616
use Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder;
17+
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans;
1718

1819
/**
1920
* @author Tobias Nyholm <[email protected]>
@@ -22,7 +23,8 @@ final class FormTypePlaceholderTest extends BasePHPVisitorTest
2223
{
2324
public function testExtract()
2425
{
25-
$collection = $this->getSourceLocations(new FormTypePlaceholder(), Resources\Php\Symfony\PlaceholderFormType::class);
26+
$collection = $this->getSourceLocations(new FormTypePlaceholder(),
27+
Resources\Php\Symfony\PlaceholderFormType::class);
2628

2729
$this->assertCount(3, $collection);
2830
$this->assertEquals('form.placeholder.text', $collection->get(0)->getMessage());
@@ -32,9 +34,28 @@ public function testExtract()
3234

3335
public function testExtractError()
3436
{
35-
$collection = $this->getSourceLocations(new FormTypePlaceholder(), Resources\Php\Symfony\PlaceholderFormErrorType::class);
37+
$collection = $this->getSourceLocations(new FormTypePlaceholder(),
38+
Resources\Php\Symfony\PlaceholderFormErrorType::class);
3639

3740
$errors = $collection->getErrors();
3841
$this->assertCount(3, $errors);
3942
}
43+
44+
public function testChildVisitationNotBlocked()
45+
{
46+
$collection = $this->getSourceLocations(
47+
[
48+
new FormTypePlaceholder(),
49+
new ContainerAwareTrans(),
50+
],
51+
Resources\Php\Symfony\ContainerAwareTrans::class
52+
);
53+
54+
$this->assertCount(4, $collection);
55+
56+
$this->assertEquals('trans0', $collection->get(0)->getMessage());
57+
$this->assertEquals('trans1', $collection->get(1)->getMessage());
58+
$this->assertEquals('trans_line', $collection->get(2)->getMessage());
59+
$this->assertEquals('variable', $collection->get(3)->getMessage());
60+
}
4061
}

0 commit comments

Comments
 (0)