@@ -41,6 +41,18 @@ public function testScanOnEmptyCode()
4141 $ this ->assertSame ([], $ functions );
4242 }
4343
44+ public function cmp ($ function , $ file , $ line , $ name , $ args , $ comments = [])
45+ {
46+ $ this ->assertSame ($ file , $ function ->getFilename ());
47+ $ this ->assertSame ($ line , $ function ->getLine ());
48+ $ this ->assertSame ($ line , $ function ->getLastLine ());
49+ $ this ->assertSame ($ name , $ function ->getName ());
50+ $ this ->assertSame ($ args , $ function ->getArguments ());
51+ if ($ comments ) {
52+ $ this ->assertCount (count ($ comments ), $ function ->getComments ());
53+ }
54+ }
55+
4456 public function testTwigFunctionsExtractor ()
4557 {
4658 $ scanner = new TwigFunctionsScanner (
@@ -50,123 +62,55 @@ public function testTwigFunctionsExtractor()
5062 $ file = __DIR__ . '/assets/input.html.twig ' ;
5163 $ code = file_get_contents ($ file );
5264 $ functions = $ scanner ->scan ($ code , $ file );
53-
5465 $ this ->assertCount (11 , $ functions );
5566
5667 // text 1
5768 $ function = array_shift ($ functions );
58- $ this ->assertSame ('__ ' , $ function ->getName ());
59- $ this ->assertSame (1 , $ function ->countArguments ());
60- $ this ->assertSame (['text 1 ' ], $ function ->getArguments ());
61- $ this ->assertSame (2 , $ function ->getLine ());
62- $ this ->assertSame (2 , $ function ->getLastLine ());
63- $ this ->assertSame ($ file , $ function ->getFilename ());
64- $ this ->assertCount (0 , $ function ->getComments ());
69+ $ this ->cmp ($ function , $ file , 2 , '__ ' , ['text 1 ' ]);
6570
6671 // text 2
6772 $ function = array_shift ($ functions );
68- $ this ->assertSame ('__ ' , $ function ->getName ());
69- $ this ->assertSame (2 , $ function ->countArguments ());
70- $ this ->assertSame (['text-domain1 ' , 'text 2 with domain ' ], $ function ->getArguments ());
71- $ this ->assertSame (3 , $ function ->getLine ());
72- $ this ->assertSame (3 , $ function ->getLastLine ());
73- $ this ->assertSame ($ file , $ function ->getFilename ());
74- $ this ->assertCount (0 , $ function ->getComments ());
73+ $ this ->cmp ($ function , $ file , 3 , '__ ' , ['text 2 with domain ' , 'text-domain1 ' ]);
7574
7675 // text 3
7776 $ function = array_shift ($ functions );
78- $ this ->assertSame ('__ ' , $ function ->getName ());
79- $ this ->assertSame (1 , $ function ->countArguments ());
80- $ this ->assertSame (7 , $ function ->getLine ());
81- $ this ->assertSame (7 , $ function ->getLastLine ());
82- $ this ->assertSame ($ file , $ function ->getFilename ());
83- $ this ->assertCount (0 , $ function ->getComments ());
77+ $ this ->cmp ($ function , $ file , 7 , '__ ' , [ 'text 3 (with parenthesis) ' ]);
8478
8579 // text 4
8680 $ function = array_shift ($ functions );
87- $ this ->assertSame ('_x ' , $ function ->getName ());
88- $ this ->assertSame (2 , $ function ->countArguments ());
89- $ this ->assertSame (['some context here ' , 'text 4 ' ], $ function ->getArguments ());
90- $ this ->assertSame (8 , $ function ->getLine ());
91- $ this ->assertSame (8 , $ function ->getLastLine ());
92- $ this ->assertSame ($ file , $ function ->getFilename ());
93- $ this ->assertCount (0 , $ function ->getComments ());
81+ $ this ->cmp ($ function , $ file , 8 , '_x ' , ['text 4 ' , 'some context here ' ]);
9482
9583 // text 5
9684 $ function = array_shift ($ functions );
97- $ this ->assertSame ('_x ' , $ function ->getName ());
98- $ this ->assertSame (3 , $ function ->countArguments ());
99- $ this ->assertSame (
100- ['text-domain2 ' , 'some other context ' , 'text 5 "with double quotes" ' ],
101- $ function ->getArguments ()
102- );
103- $ this ->assertSame (9 , $ function ->getLine ());
104- $ this ->assertSame (9 , $ function ->getLastLine ());
105- $ this ->assertSame ($ file , $ function ->getFilename ());
106- $ this ->assertCount (0 , $ function ->getComments ());
85+ $ this ->cmp ($ function , $ file , 9 , '_x ' , ['text 5 "with double quotes" ' , 'some other context ' , 'text-domain2 ' ]);
10786
10887 // text 6
10988 $ function = array_shift ($ functions );
110- $ this ->assertSame ('__ ' , $ function ->getName ());
111- $ this ->assertSame (1 , $ function ->countArguments ());
112- $ this ->assertSame (['text 6 \'with escaped single quotes \'' ], $ function ->getArguments ());
113- $ this ->assertSame (10 , $ function ->getLine ());
114- $ this ->assertSame (10 , $ function ->getLastLine ());
115- $ this ->assertSame ($ file , $ function ->getFilename ());
116- $ this ->assertCount (0 , $ function ->getComments ());
89+ $ this ->cmp ($ function , $ file , 10 , '__ ' , ['text 6 \'with escaped single quotes \'' ]);
11790
11891 // text 7
11992 $ function = array_shift ($ functions );
120- $ this ->assertSame ('_n ' , $ function ->getName ());
121- $ this ->assertSame (3 , $ function ->countArguments ());
122- $ this ->assertSame (['text-domain2 ' , 'text 7 %d foo ' , 'text 7 %d foos ' ], $ function ->getArguments ());
123- $ this ->assertSame (14 , $ function ->getLine ());
124- $ this ->assertSame (14 , $ function ->getLastLine ());
125- $ this ->assertSame ($ file , $ function ->getFilename ());
126- $ this ->assertCount (0 , $ function ->getComments ());
93+ $ this ->cmp ($ function , $ file , 14 , '_n ' , ['text 7 %d foo ' , 'text 7 %d foos ' , null , 'text-domain2 ' ]);
12794
12895 // text 8
12996 $ function = array_shift ($ functions );
130- $ this ->assertSame ('_nx ' , $ function ->getName ());
131- $ this ->assertSame (3 , $ function ->countArguments ());
132- $ this ->assertSame (['another context ' , 'text 8 %d bar ' , 'text 8 %d bars ' ], $ function ->getArguments ());
133- $ this ->assertSame (15 , $ function ->getLine ());
134- $ this ->assertSame (15 , $ function ->getLastLine ());
135- $ this ->assertSame ($ file , $ function ->getFilename ());
136- $ this ->assertCount (0 , $ function ->getComments ());
97+ $ this ->cmp ($ function , $ file , 15 , '_nx ' , ['text 8 %d bar ' , 'text 8 %d bars ' , null , 'another context ' ]);
13798
13899 // text 9
139100 $ function = array_shift ($ functions );
140- $ this ->assertSame ('__ ' , $ function ->getName ());
141- $ this ->assertSame (1 , $ function ->countArguments ());
142- $ this ->assertSame (['text 9 "with escaped double quotes" ' ], $ function ->getArguments ());
143- $ this ->assertSame (16 , $ function ->getLine ());
144- $ this ->assertSame (16 , $ function ->getLastLine ());
145- $ this ->assertSame ($ file , $ function ->getFilename ());
146- $ this ->assertCount (0 , $ function ->getComments ());
101+ $ this ->cmp ($ function , $ file , 16 , '__ ' , ['text 9 "with escaped double quotes" ' ]);
147102
148103 // text 10
149104 $ function = array_shift ($ functions );
150- $ this ->assertSame ('__ ' , $ function ->getName ());
151- $ this ->assertSame (1 , $ function ->countArguments ());
152- $ this ->assertSame (["text 10 'with single quotes' " ], $ function ->getArguments ());
153- $ this ->assertSame (17 , $ function ->getLine ());
154- $ this ->assertSame (17 , $ function ->getLastLine ());
155- $ this ->assertSame ($ file , $ function ->getFilename ());
156- $ this ->assertCount (0 , $ function ->getComments ());
105+ $ this ->cmp ($ function , $ file , 17 , '__ ' , ["text 10 'with single quotes' " ]);
157106
158107 // text 11
159108 $ function = array_shift ($ functions );
160- $ this ->assertSame ('_n ' , $ function ->getName ());
161- $ this ->assertSame (2 , $ function ->countArguments ());
162- $ this ->assertSame (['text 11 with plural ' , 'The plural form ' ], $ function ->getArguments ());
163- $ this ->assertSame (20 , $ function ->getLine ());
164- $ this ->assertSame (20 , $ function ->getLastLine ());
165- $ this ->assertSame ($ file , $ function ->getFilename ());
166- $ this ->assertCount (0 , $ function ->getComments ());
109+ $ this ->cmp ($ function , $ file , 20 , '_n ' , ['text 11 with plural ' , 'The plural form ' , 5 ]);
110+
167111 /* ToDo
168- $comments = $function->getComments();
169- $this->assertSame("notes: This is an actual note for translators.", array_shift($comments));
112+ $comments = $function->getComments();
113+ $this->assertSame("notes: This is an actual note for translators.", array_shift($comments));
170114 */
171115 }
172116}
0 commit comments