Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Visitor/Php/Symfony/FormTypeChoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Translation\Extractor\Model\SourceLocation;
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
Expand Down Expand Up @@ -41,7 +40,7 @@ public function enterNode(Node $node)
// only Traverse *Type
if ($node instanceof Stmt\Class_) {
if (substr($node->name, -4) !== 'Type') {
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return;
}
}

Expand All @@ -63,6 +62,7 @@ public function enterNode(Node $node)

if ($item->key->value === 'choices_as_values') {
$useKey = true;

continue;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Visitor/Php/Symfony/FormTypeLabelExplicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Translation\Extractor\Model\SourceLocation;
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
Expand All @@ -28,7 +27,7 @@ public function enterNode(Node $node)
// only Traverse *Type
if ($node instanceof Stmt\Class_) {
if (substr($node->name, -4) !== 'Type') {
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Visitor/Php/Symfony/FormTypeLabelImplicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Translation\Extractor\Model\SourceLocation;
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
Expand All @@ -28,7 +27,7 @@ public function enterNode(Node $node)
// only Traverse *Type
if ($node instanceof Stmt\Class_) {
if (substr($node->name, -4) !== 'Type') {
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Visitor/Php/Symfony/FormTypePlaceholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use Translation\Extractor\Model\SourceLocation;
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
Expand All @@ -28,7 +27,7 @@ public function enterNode(Node $node)
// only Traverse *Type
if ($node instanceof Stmt\Class_) {
if (substr($node->name, -4) !== 'Type') {
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return;
}
}

Expand Down
10 changes: 9 additions & 1 deletion tests/Functional/Visitor/Php/BasePHPVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ abstract class BasePHPVisitorTest extends \PHPUnit_Framework_TestCase
protected function getSourceLocations($visitor, $namespaceForTestFile)
{
$extractor = new PHPFileExtractor();
$extractor->addVisitor($visitor);

if (is_array($visitor)) {
foreach ($visitor as $nodeVisitor) {
$extractor->addVisitor($nodeVisitor);
}
} else {
$extractor->addVisitor($visitor);
}

$currentNamespace = explode('\\', __NAMESPACE__);
$fileNamespace = explode('\\', $namespaceForTestFile);
Expand All @@ -44,6 +51,7 @@ protected function getSourceLocations($visitor, $namespaceForTestFile)
for ($j = $i; $j < count($fileNamespace); ++$j) {
$path .= '/'.$fileNamespace[$j];
}

break;
}
}
Expand Down
25 changes: 23 additions & 2 deletions tests/Functional/Visitor/Php/Symfony/FormTypePlaceholderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest;
use Translation\Extractor\Tests\Resources;
use Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder;
use Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
Expand All @@ -22,7 +23,8 @@ final class FormTypePlaceholderTest extends BasePHPVisitorTest
{
public function testExtract()
{
$collection = $this->getSourceLocations(new FormTypePlaceholder(), Resources\Php\Symfony\PlaceholderFormType::class);
$collection = $this->getSourceLocations(new FormTypePlaceholder(),
Resources\Php\Symfony\PlaceholderFormType::class);

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

public function testExtractError()
{
$collection = $this->getSourceLocations(new FormTypePlaceholder(), Resources\Php\Symfony\PlaceholderFormErrorType::class);
$collection = $this->getSourceLocations(new FormTypePlaceholder(),
Resources\Php\Symfony\PlaceholderFormErrorType::class);

$errors = $collection->getErrors();
$this->assertCount(3, $errors);
}

public function testChildVisitationNotBlocked()
{
$collection = $this->getSourceLocations(
[
new FormTypePlaceholder(),
new ContainerAwareTrans(),
],
Resources\Php\Symfony\ContainerAwareTrans::class
);

$this->assertCount(4, $collection);

$this->assertEquals('trans0', $collection->get(0)->getMessage());
$this->assertEquals('trans1', $collection->get(1)->getMessage());
$this->assertEquals('trans_line', $collection->get(2)->getMessage());
$this->assertEquals('variable', $collection->get(3)->getMessage());
}
}