@@ -8,35 +8,9 @@ public function testCompileFile()
88 {
99 $ jsPhpize = new JsPhpize ();
1010 $ actual = $ jsPhpize ->compileFile (__DIR__ . '/../examples/basic.js ' );
11- $ expected = <<<'EOD'
12- $GLOBALS['__jpv_dot'] = function ($base) {
13- foreach (array_slice(func_get_args(), 1) as $key) {
14- $base = is_array($base)
15- ? (isset($base[$key]) ? $base[$key] : null)
16- : (is_object($base)
17- ? (isset($base->$key)
18- ? $base->$key
19- : (method_exists($base, $method = "get" . ucfirst($key))
20- ? $base->$method()
21- : (method_exists($base, $key)
22- ? array($base, $key)
23- : null
24- )
25- )
26- )
27- : null
28- );
29- }
30-
31- return $base;
32- };
33- $GLOBALS['__jpv_plus'] = function ($base) {
34- foreach (array_slice(func_get_args(), 1) as $value) {
35- $base = is_string($base) || is_string($value) ? $base . $value : $base + $value;
36- }
37-
38- return $base;
39- };
11+ $ expected = '$GLOBALS[ \'__jpv_dot \'] = ' . file_get_contents (__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Dot.h ' ) . '; ' ;
12+ $ expected .= '$GLOBALS[ \'__jpv_plus \'] = ' . file_get_contents (__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Plus.h ' ) . '; ' ;
13+ $ expected .= <<<'EOD'
4014$foo = array( 'bar' => array( "baz" => "hello" ) );
4115$biz = 'bar';
4216return call_user_func($GLOBALS['__jpv_plus'], call_user_func($GLOBALS['__jpv_dot'], $foo, 'bar', "baz"), ' ', call_user_func($GLOBALS['__jpv_dot'], $foo, $biz, 'baz'), " ", call_user_func($GLOBALS['__jpv_dot'], $foo, 'bar', 'baz'));
@@ -57,51 +31,16 @@ public function testCompileFile()
5731 $ this ->assertSame ($ expected , $ actual );
5832
5933 $ actual = $ jsPhpize ->compileDependencies ();
60- $ expected = <<<'EOD'
61- $GLOBALS['__jpv_dot'] = function ($base) {
62- foreach (array_slice(func_get_args(), 1) as $key) {
63- $base = is_array($base)
64- ? (isset($base[$key]) ? $base[$key] : null)
65- : (is_object($base)
66- ? (isset($base->$key)
67- ? $base->$key
68- : (method_exists($base, $method = "get" . ucfirst($key))
69- ? $base->$method()
70- : (method_exists($base, $key)
71- ? array($base, $key)
72- : null
73- )
74- )
75- )
76- : null
77- );
78- }
79-
80- return $base;
81- };
82- $GLOBALS['__jpv_plus'] = function ($base) {
83- foreach (array_slice(func_get_args(), 1) as $value) {
84- $base = is_string($base) || is_string($value) ? $base . $value : $base + $value;
85- }
34+ $ expected = '$GLOBALS[ \'__jpv_dot \'] = ' . file_get_contents (__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Dot.h ' ) . '; ' ;
35+ $ expected .= '$GLOBALS[ \'__jpv_plus \'] = ' . file_get_contents (__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Plus.h ' ) . '; ' ;
8636
87- return $base;
88- };
89- EOD;
9037 $ actual = preg_replace ('/\s/ ' , '' , $ actual );
9138 $ expected = preg_replace ('/\s/ ' , '' , $ expected );
9239 $ this ->assertSame ($ expected , $ actual );
9340
9441 $ jsPhpize ->compileFile (__DIR__ . '/../examples/calcul.js ' , true );
9542 $ actual = $ jsPhpize ->compileDependencies ();
96- $ expected = <<<'EOD'
97- $GLOBALS['__jpv_plus'] = function ($base) {
98- foreach (array_slice(func_get_args(), 1) as $value) {
99- $base = is_string($base) || is_string($value) ? $base . $value : $base + $value;
100- }
101-
102- return $base;
103- };
104- EOD;
43+ $ expected = '$GLOBALS[ \'__jpv_plus \'] = ' . file_get_contents (__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Plus.h ' ) . '; ' ;
10544 $ actual = preg_replace ('/\s/ ' , '' , $ actual );
10645 $ expected = preg_replace ('/\s/ ' , '' , $ expected );
10746 $ this ->assertSame ($ expected , $ actual );
@@ -165,28 +104,9 @@ public function testCompileSource()
165104 chdir (__DIR__ . '/../examples ' );
166105 $ actual = $ jsPhpize ->compileCode ('calcul.js ' );
167106 chdir ($ dir );
168- $ expected = <<<'EOD'
169- $GLOBALS['foodot'] = function ($base) {
170- foreach (array_slice(func_get_args(), 1) as $key) {
171- $base = is_array($base)
172- ? (isset($base[$key]) ? $base[$key] : null)
173- : (is_object($base)
174- ? (isset($base->$key)
175- ? $base->$key
176- : (method_exists($base, $method = "get" . ucfirst($key))
177- ? $base->$method()
178- : (method_exists($base, $key)
179- ? array($base, $key)
180- : null
181- )
182- )
183- )
184- : null
185- );
186- }
107+ $ expected = '$GLOBALS[ \'foodot \'] = ' . file_get_contents (__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Dot.h ' ) . '; ' ;
187108
188- return $base;
189- };
109+ $ expected .= <<<'EOD'
190110call_user_func($GLOBALS['foodot'], $calcul, 'js');
191111EOD;
192112 $ actual = preg_replace ('/\s/ ' , '' , $ actual );
0 commit comments