Skip to content

Commit 1fcc479

Browse files
committed
Add test for namespace statement
1 parent 952fd36 commit 1fcc479

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": ">=7.0",
14-
"js-phpize/js-phpize": "^2.0.0",
14+
"js-phpize/js-phpize": "^2.8.3",
1515
"phug/compiler": "^1.7.2",
1616
"phug/formatter": "^1.7.2"
1717
},

tests/JsPhpize/Example/Example.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Tests\JsPhpize\Example;
4+
5+
class Example
6+
{
7+
public static function foo()
8+
{
9+
return 'bar';
10+
}
11+
}

tests/JsPhpize/JsPhpizePhugTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use JsPhpize\JsPhpizePhug;
77
use PHPUnit\Framework\TestCase;
88
use Phug\Compiler;
9+
use Phug\CompilerEvent;
910
use Phug\Renderer;
1011
use Tests\Thrower;
1112

@@ -102,6 +103,33 @@ public function testPlug()
102103
);
103104
}
104105

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+
105133
public function testTruncatedCode()
106134
{
107135
$compiler = new Compiler([
@@ -123,6 +151,7 @@ public function testTruncatedCode()
123151
$php5Syntax = 'call_user_func(call_user_func($GLOBALS[\'__jpv_dotWithArrayPrototype\'], $items, ' .
124152
'\'forEach\'), function ($item) {';
125153
$actual = $jsPhpize('items.forEach(function (item) {');
154+
126155
self::assertContains(
127156
$jsPhpize('items.forEach(function (item) {'),
128157
[$php5Syntax, $php7Syntax],

0 commit comments

Comments
 (0)