13
13
14
14
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
15
15
use Twig \Environment ;
16
+ use Twig \Error \SyntaxError ;
16
17
use Twig \Loader \ArrayLoader ;
17
18
use Twig \TemplateWrapper ;
18
19
@@ -28,38 +29,50 @@ final class ComponentParserTest extends KernelTestCase
28
29
*/
29
30
public function testAcceptTwigComponentTagWithValidComponentName (string $ name ): void
30
31
{
31
- $ environment = self :: createEnvironment ();
32
+ $ environment = $ this -> createEnvironment ();
32
33
$ source = str_replace ('XXX ' , $ name , "{% component 'XXX' %}{% endcomponent %} " );
33
34
34
35
$ template = $ environment ->createTemplate ($ source );
35
36
36
- self :: assertInstanceOf (TemplateWrapper::class, $ template );
37
+ $ this -> assertInstanceOf (TemplateWrapper::class, $ template );
37
38
}
38
39
39
40
/**
40
41
* @dataProvider provideValidComponentNames
41
42
*/
42
43
public function testAcceptHtmlComponentTagWithValidComponentName (string $ name ): void
43
44
{
44
- $ environment = self :: createEnvironment ();
45
+ $ environment = $ this -> createEnvironment ();
45
46
$ source = \sprintf ('<twig:%s></twig:%s> ' , $ name , $ name );
46
47
47
48
$ template = $ environment ->createTemplate ($ source );
48
49
49
- self :: assertInstanceOf (TemplateWrapper::class, $ template );
50
+ $ this -> assertInstanceOf (TemplateWrapper::class, $ template );
50
51
}
51
52
52
53
/**
53
54
* @dataProvider provideValidComponentNames
54
55
*/
55
56
public function testAcceptHtmlSelfClosingComponentTagWithValidComponentName (string $ name ): void
56
57
{
57
- $ environment = self :: createEnvironment ();
58
+ $ environment = $ this -> createEnvironment ();
58
59
$ source = \sprintf ('<twig:%s /> ' , $ name );
59
60
60
61
$ template = $ environment ->createTemplate ($ source );
61
62
62
- self ::assertInstanceOf (TemplateWrapper::class, $ template );
63
+ $ this ->assertInstanceOf (TemplateWrapper::class, $ template );
64
+ }
65
+
66
+ public function testItThrowsWhenComponentNameCannotBeParsed (): void
67
+ {
68
+ $ environment = $ this ->createEnvironment ();
69
+ $ source = '{% component [] %}{% endcomponent %} ' ;
70
+
71
+ $ this ->expectException (SyntaxError::class);
72
+ $ this ->expectExceptionMessage ('Could not parse component name in "foo.html.twig ' );
73
+ $ this ->expectExceptionMessage (')" at line 1. ' );
74
+
75
+ $ environment ->createTemplate ($ source , 'foo.html.twig ' );
63
76
}
64
77
65
78
public static function provideValidComponentNames (): iterable
0 commit comments