|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace JsPhpizeTest; |
4 | | - |
5 | 3 | use JsPhpize\JsPhpize; |
6 | 4 |
|
7 | | -class JsPhpizeTest extends \PHPUnit_Framework_TestCase |
| 5 | +class MainMethodsTest extends \PHPUnit_Framework_TestCase |
8 | 6 | { |
9 | 7 | public function testCompileFile() |
10 | 8 | { |
11 | 9 | $jsPhpize = new JsPhpize(); |
12 | | - $actual = $jsPhpize->compileFile(__DIR__ . '/../../examples/basic.js'); |
| 10 | + $actual = $jsPhpize->compileFile(__DIR__ . '/../examples/basic.js'); |
13 | 11 | $expected = <<<'EOD' |
14 | 12 | $GLOBALS["__jp_h_plus"] = function ($base) { |
15 | 13 | foreach (array_slice(func_get_args(), 1) as $value) { |
@@ -50,7 +48,7 @@ public function testCompileFile() |
50 | 48 | $this->assertSame($expected, $actual); |
51 | 49 | $this->assertSame('', $jsPhpize->compileDependencies()); |
52 | 50 |
|
53 | | - $actual = $jsPhpize->compileFile(__DIR__ . '/../../examples/basic.js', true); |
| 51 | + $actual = $jsPhpize->compileFile(__DIR__ . '/../examples/basic.js', true); |
54 | 52 | $expected = <<<'EOD' |
55 | 53 | $foo = array( 'bar' => array( "baz" => "hello" ) ); |
56 | 54 | // Comment |
@@ -97,7 +95,7 @@ public function testCompileFile() |
97 | 95 | $expected = preg_replace('/\s/', '', $expected); |
98 | 96 | $this->assertSame($expected, $actual); |
99 | 97 |
|
100 | | - $jsPhpize->compileFile(__DIR__ . '/../../examples/calcul.js', true); |
| 98 | + $jsPhpize->compileFile(__DIR__ . '/../examples/calcul.js', true); |
101 | 99 | $actual = $jsPhpize->compileDependencies(); |
102 | 100 | $actual = preg_replace('/\s/', '', $actual); |
103 | 101 | $this->assertSame($expected, $actual); |
@@ -127,7 +125,7 @@ public function testCompileSource() |
127 | 125 | $this->assertSame($expected, $actual); |
128 | 126 |
|
129 | 127 | $dir = getcwd(); |
130 | | - chdir(__DIR__ . '/../../examples'); |
| 128 | + chdir(__DIR__ . '/../examples'); |
131 | 129 | $actual = $jsPhpize->compileCode('calcul.js'); |
132 | 130 | chdir($dir); |
133 | 131 | $expected = <<<'EOD' |
@@ -158,4 +156,30 @@ public function testCompileSource() |
158 | 156 | $expected = preg_replace('/\s/', '', $expected); |
159 | 157 | $this->assertSame($expected, $actual); |
160 | 158 | } |
| 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 | + } |
161 | 185 | } |
0 commit comments