@@ -56,6 +56,55 @@ public function testPhpCodeScanner()
5656 $ this ->assertSame (['php-format ' ], $ translation ->getFlags ()->toArray ());
5757 }
5858
59+ /**
60+ * @see https://github.com/php-gettext/PHP-Scanner/issues/19
61+ */
62+ public function testCommentsInArrays ()
63+ {
64+ $ code = <<<'PHP'
65+ <?php
66+ /* PREV: Comment 1 */
67+ $arg = [__('String 1')];
68+
69+ $args = array_merge($args, [
70+ 'title' => /* PREV: Comment 2 */ __('String 2'),
71+ 'noscript' => [
72+ /* PREV: Comment 3 */
73+ Flash::INFO => [__('String 3')]
74+ ],
75+ 'breadcrumb' => [
76+ ['text' => /* PREV: Comment 4 */ d__('admin', 'String 4'), 'link' => get_homepage_url()],
77+ ],
78+ 'metatags' => new Meta([
79+ /* PREV: Comment 5 */
80+ 'description' => __('String 5'),
81+ ]),
82+ ]);
83+ PHP;
84+
85+ $ scanner = new PhpScanner (
86+ Translations ::create ('default ' ),
87+ Translations ::create ('admin ' )
88+ );
89+ $ scanner ->setFunctions (['__ ' => 'gettext ' , 'd__ ' => 'dgettext ' ]);
90+ $ scanner ->ignoreInvalidFunctions (true );
91+ $ scanner ->setDefaultDomain ('default ' );
92+ $ scanner ->extractCommentsStartingWith ('PREV: ' );
93+ $ scanner ->scanString ($ code , 'file.php ' );
94+
95+ ['default ' => $ default , 'admin ' => $ admin ] = $ scanner ->getTranslations ();
96+
97+ foreach ([1 , 2 , 3 , 5 ] as $ number ) {
98+ $ translation = $ default ->find (null , "String $ number " );
99+ $ this ->assertNotNull ($ translation );
100+ $ this ->assertSame (["PREV: Comment $ number " ], $ translation ->getExtractedComments ()->toArray ());
101+ }
102+
103+ $ translation = $ admin ->find (null , 'String 4 ' );
104+ $ this ->assertNotNull ($ translation );
105+ $ this ->assertSame (['PREV: Comment 4 ' ], $ translation ->getExtractedComments ()->toArray ());
106+ }
107+
59108 public function testInvalidFunction ()
60109 {
61110 $ this ->expectException (Exception::class);
0 commit comments