6
6
use JsPhpize \JsPhpizePhug ;
7
7
use PHPUnit \Framework \TestCase ;
8
8
use Phug \Compiler ;
9
+ use Phug \CompilerEvent ;
9
10
use Phug \Renderer ;
10
11
use Tests \Thrower ;
11
12
@@ -102,6 +103,33 @@ public function testPlug()
102
103
);
103
104
}
104
105
106
+ public function testNamespaceInsertion ()
107
+ {
108
+ include_once __DIR__ . '/Example/Example.php ' ;
109
+
110
+ $ compiler = new Compiler ([
111
+ 'compiler_modules ' => [JsPhpizePhug::class],
112
+ ]);
113
+ $ compiler ->attach (CompilerEvent::OUTPUT , function (Compiler \Event \OutputEvent $ outputEvent ) {
114
+ $ outputEvent ->prependCode ('namespace Tests\JsPhpize\Example; ' );
115
+ });
116
+
117
+ $ user = [
118
+ 'name ' => 'Bob ' ,
119
+ ];
120
+
121
+ ob_start ();
122
+ $ php = $ compiler ->compile ('a(title=user.name foo=Example::foo()) ' );
123
+ eval ('?> ' . $ php );
124
+ $ html = ob_get_contents ();
125
+ ob_end_clean ();
126
+
127
+ self ::assertSame (
128
+ '<a title="Bob" foo="bar"></a> ' ,
129
+ $ html
130
+ );
131
+ }
132
+
105
133
public function testTruncatedCode ()
106
134
{
107
135
$ compiler = new Compiler ([
@@ -123,6 +151,7 @@ public function testTruncatedCode()
123
151
$ php5Syntax = 'call_user_func(call_user_func($GLOBALS[ \'__jpv_dotWithArrayPrototype \'], $items, ' .
124
152
'\'forEach \'), function ($item) { ' ;
125
153
$ actual = $ jsPhpize ('items.forEach(function (item) { ' );
154
+
126
155
self ::assertContains (
127
156
$ jsPhpize ('items.forEach(function (item) { ' ),
128
157
[$ php5Syntax , $ php7Syntax ],
0 commit comments