Skip to content

Commit dd94d91

Browse files
committed
Test shared variables
1 parent de056c9 commit dd94d91

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<testsuite name="compile">
1414
<file>tests/compile.php</file>
1515
</testsuite>
16-
<testsuite name="JsPhpize">
17-
<file>tests/JsPhpize/JsPhpize.php</file>
16+
<testsuite name="mainMethods">
17+
<file>tests/mainMethods.php</file>
1818
</testsuite>
1919
</testsuites>
2020
<filter>

tests/JsPhpize/JsPhpize.php renamed to tests/mainMethods.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php
22

3-
namespace JsPhpizeTest;
4-
53
use JsPhpize\JsPhpize;
64

7-
class JsPhpizeTest extends \PHPUnit_Framework_TestCase
5+
class MainMethodsTest extends \PHPUnit_Framework_TestCase
86
{
97
public function testCompileFile()
108
{
119
$jsPhpize = new JsPhpize();
12-
$actual = $jsPhpize->compileFile(__DIR__ . '/../../examples/basic.js');
10+
$actual = $jsPhpize->compileFile(__DIR__ . '/../examples/basic.js');
1311
$expected = <<<'EOD'
1412
$GLOBALS["__jp_h_plus"] = function ($base) {
1513
foreach (array_slice(func_get_args(), 1) as $value) {
@@ -50,7 +48,7 @@ public function testCompileFile()
5048
$this->assertSame($expected, $actual);
5149
$this->assertSame('', $jsPhpize->compileDependencies());
5250

53-
$actual = $jsPhpize->compileFile(__DIR__ . '/../../examples/basic.js', true);
51+
$actual = $jsPhpize->compileFile(__DIR__ . '/../examples/basic.js', true);
5452
$expected = <<<'EOD'
5553
$foo = array( 'bar' => array( "baz" => "hello" ) );
5654
// Comment
@@ -97,7 +95,7 @@ public function testCompileFile()
9795
$expected = preg_replace('/\s/', '', $expected);
9896
$this->assertSame($expected, $actual);
9997

100-
$jsPhpize->compileFile(__DIR__ . '/../../examples/calcul.js', true);
98+
$jsPhpize->compileFile(__DIR__ . '/../examples/calcul.js', true);
10199
$actual = $jsPhpize->compileDependencies();
102100
$actual = preg_replace('/\s/', '', $actual);
103101
$this->assertSame($expected, $actual);
@@ -127,7 +125,7 @@ public function testCompileSource()
127125
$this->assertSame($expected, $actual);
128126

129127
$dir = getcwd();
130-
chdir(__DIR__ . '/../../examples');
128+
chdir(__DIR__ . '/../examples');
131129
$actual = $jsPhpize->compileCode('calcul.js');
132130
chdir($dir);
133131
$expected = <<<'EOD'
@@ -158,4 +156,30 @@ public function testCompileSource()
158156
$expected = preg_replace('/\s/', '', $expected);
159157
$this->assertSame($expected, $actual);
160158
}
159+
160+
public function testRender()
161+
{
162+
$jsPhpize = new JsPhpize();
163+
$actual = $jsPhpize->render('return b;', array(
164+
'b' => 42,
165+
));
166+
$expected = 42;
167+
$this->assertSame($expected, $actual);
168+
169+
error_reporting(E_ALL ^ E_NOTICE);
170+
$actual = $jsPhpize->render('return b;');
171+
$expected = null;
172+
$this->assertSame($expected, $actual);
173+
174+
$jsPhpize->share('b', array(31));
175+
$actual = $jsPhpize->render('return b;');
176+
$expected = array(31);
177+
$this->assertSame($expected, $actual);
178+
179+
$jsPhpize->resetSharedVariables();
180+
$actual = $jsPhpize->render('return b;');
181+
$expected = null;
182+
$this->assertSame($expected, $actual);
183+
error_reporting(-1);
184+
}
161185
}

0 commit comments

Comments
 (0)