Skip to content

Commit

Permalink
Add test for namespace statement
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Apr 25, 2020
1 parent 952fd36 commit 1fcc479
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": ">=7.0",
"js-phpize/js-phpize": "^2.0.0",
"js-phpize/js-phpize": "^2.8.3",
"phug/compiler": "^1.7.2",
"phug/formatter": "^1.7.2"
},
Expand Down
11 changes: 11 additions & 0 deletions tests/JsPhpize/Example/Example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tests\JsPhpize\Example;

class Example
{
public static function foo()
{
return 'bar';
}
}
29 changes: 29 additions & 0 deletions tests/JsPhpize/JsPhpizePhugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use JsPhpize\JsPhpizePhug;
use PHPUnit\Framework\TestCase;
use Phug\Compiler;
use Phug\CompilerEvent;
use Phug\Renderer;
use Tests\Thrower;

Expand Down Expand Up @@ -102,6 +103,33 @@ public function testPlug()
);
}

public function testNamespaceInsertion()
{
include_once __DIR__ . '/Example/Example.php';

$compiler = new Compiler([
'compiler_modules' => [JsPhpizePhug::class],
]);
$compiler->attach(CompilerEvent::OUTPUT, function (Compiler\Event\OutputEvent $outputEvent) {
$outputEvent->prependCode('namespace Tests\JsPhpize\Example;');
});

$user = [
'name' => 'Bob',
];

ob_start();
$php = $compiler->compile('a(title=user.name foo=Example::foo())');
eval('?>' . $php);
$html = ob_get_contents();
ob_end_clean();

self::assertSame(
'<a title="Bob" foo="bar"></a>',
$html
);
}

public function testTruncatedCode()
{
$compiler = new Compiler([
Expand All @@ -123,6 +151,7 @@ public function testTruncatedCode()
$php5Syntax = 'call_user_func(call_user_func($GLOBALS[\'__jpv_dotWithArrayPrototype\'], $items, ' .
'\'forEach\'), function ($item) {';
$actual = $jsPhpize('items.forEach(function (item) {');

self::assertContains(
$jsPhpize('items.forEach(function (item) {'),
[$php5Syntax, $php7Syntax],
Expand Down

0 comments on commit 1fcc479

Please sign in to comment.