8000 Fix the translation commands when a template contains a syntax error · symfony/symfony@c239ed3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c239ed3

Browse files
committed
Fix the translation commands when a template contains a syntax error
1 parent fa783f9 commit c239ed3

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,15 @@ public function getExtractData()
7878
/**
7979
* @dataProvider resourcesWithSyntaxErrorsProvider
8080
*/
81-
public function testExtractSyntaxError($resources)
81+
public function testExtractSyntaxError($resources, array $messages)
8282
{
83-
$this->expectException('Twig\Error\Error');
8483
$twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
8584
$twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock()));
8685

8786
$extractor = new TwigExtractor($twig);
88-
89-
try {
90-
$extractor->extract($resources, new MessageCatalogue('en'));
91-
} catch (Error $e) {
92-
$this->assertSame(\dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', \DIRECTORY_SEPARATOR), $e->getFile());
93-
$this->assertSame(1, $e->getLine());
94-
$this->assertSame('Unclosed "block".', $e->getMessage());
95-
96-
throw $e;
97-
}
87+
$catalogue = new MessageCatalogue('en');
88+
$extractor->extract($resources, $catalogue);
89+
$this->assertSame($messages, $catalogue->all());
9890
}
9991

10092
/**
@@ -103,9 +95,9 @@ public function testExtractSyntaxError($resources)
10395
public function resourcesWithSyntaxErrorsProvider()
10496
{
10597
return [
106-
[__DIR__.'/../Fixtures'],
107-
[__DIR__.'/../Fixtures/extractor/syntax_error.twig'],
108-
[new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig')],
98+
[__DIR__.'/../Fixtures', ['messages' => ['Hi!' => 'Hi!']]],
99+
[__DIR__.'/../Fixtures/extractor/syntax_error.twig', []],
100+
[new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig'), []],
109101
];
110102
}
111103

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bridge\Twig\Translation;
1313

1414
use Symfony\Component\Finder\Finder;
15-
use Symfony\Component\Finder\SplFileInfo;
1615
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
1716
use Symfony\Component\Translation\Extractor\ExtractorInterface;
1817
use Symfony\Component\Translation\MessageCatalogue;
@@ -58,13 +57,7 @@ public function extract($resource, MessageCatalogue $catalogue)
5857
try {
5958
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6059
} catch (Error $e) {
61-
if ($file instanceof \SplFileInfo) {
62-
$path = $file->getRealPath() ?: $file->getPathname();
63-
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
64-
$e->setSourceContext(new Source('', $name, $path));
65-
}
66-
67-
throw $e;
60+
// ignore errors, these should be fixed by using the linter
6861
}
6962
}
7063
}

0 commit comments

Comments
 (0)
0