1717use Symfony \Component \Translation \MessageCatalogue ;
1818use Symfony \Contracts \Translation \TranslatorInterface ;
1919use Twig \Environment ;
20- use Twig \Error \Error ;
2120use Twig \Loader \ArrayLoader ;
2221
2322class TwigExtractorTest extends TestCase
@@ -101,23 +100,15 @@ public function getLegacyExtractData()
101100 /**
102101 * @dataProvider resourcesWithSyntaxErrorsProvider
103102 */
104- public function testExtractSyntaxError ($ resources )
103+ public function testExtractSyntaxError ($ resources, array $ messages )
105104 {
106- $ this ->expectException ('Twig\Error\Error ' );
107105 $ twig = new Environment ($ this ->getMockBuilder ('Twig\Loader\LoaderInterface ' )->getMock ());
108106 $ twig ->addExtension (new TranslationExtension ($ this ->getMockBuilder (TranslatorInterface::class)->getMock ()));
109107
110108 $ extractor = new TwigExtractor ($ twig );
111-
112- try {
113- $ extractor ->extract ($ resources , new MessageCatalogue ('en ' ));
114- } catch (Error $ e ) {
115- $ this ->assertSame (\dirname (__DIR__ ).strtr ('/Fixtures/extractor/syntax_error.twig ' , '/ ' , \DIRECTORY_SEPARATOR ), $ e ->getFile ());
116- $ this ->assertSame (1 , $ e ->getLine ());
117- $ this ->assertSame ('Unclosed "block". ' , $ e ->getMessage ());
118-
119- throw $ e ;
120- }
109+ $ catalogue = new MessageCatalogue ('en ' );
110+ $ extractor ->extract ($ resources , $ catalogue );
111+ $ this ->assertSame ($ messages , $ catalogue ->all ());
121112 }
122113
123114 /**
@@ -126,9 +117,9 @@ public function testExtractSyntaxError($resources)
126117 public function resourcesWithSyntaxErrorsProvider ()
127118 {
128119 return [
129- [__DIR__ .'/../Fixtures ' ],
130- [__DIR__ .'/../Fixtures/extractor/syntax_error.twig ' ],
131- [new \SplFileInfo (__DIR__ .'/../Fixtures/extractor/syntax_error.twig ' )],
120+ [__DIR__ .'/../Fixtures ' , [ ' messages ' => [ ' Hi! ' => ' Hi! ' ]] ],
121+ [__DIR__ .'/../Fixtures/extractor/syntax_error.twig ' , [] ],
122+ [new \SplFileInfo (__DIR__ .'/../Fixtures/extractor/syntax_error.twig ' ), [] ],
132123 ];
133124 }
134125
0 commit comments