0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-10 01:28:42 +00:00

use EXPECTREGEX to handle different PHP version's output well

This commit is contained in:
Stefan Siegl 2019-06-23 19:09:12 +02:00
parent 885ac6d249
commit fcd78f830a
No known key found for this signature in database
GPG Key ID: 73942AF5642F3DDA
3 changed files with 261 additions and 582 deletions

View File

@ -54,22 +54,22 @@ try {
?> ?>
===EOF=== ===EOF===
--EXPECTF-- --EXPECTREGEX--
Warning: Creating default object from empty value in %s%eissue_250_001.php on line 9 (?:Warning\: Creating default object from empty value in [^\r\n]+\/issue_250_001\.php on line 9\s*)+
object(TestObject)#%d (3) { object\(TestObject\)\#\d+ \(3\) \{
["data":"TestObject":private]=> \["data"\:"TestObject"\:private\]\=\>
object(V8Object)#%d (0) { object\(V8Object\)\#\d+ \(0\) \{
} \}
["meta":"TestObject":private]=> \["meta"\:"TestObject"\:private\]\=\>
array(0) { array\(0\) \{
} \}
["a"]=> \["a"\]\=\>
object(stdClass)#%d (1) { object\(stdClass\)\#\d+ \(1\) \{
["b"]=> \["b"\]\=\>
object(stdClass)#%d (1) { object\(stdClass\)\#\d+ \(1\) \{
["title"]=> \["title"\]\=\>
string(4) "ouch" string\(4\) "ouch"
} \}
} \}
} \}
===EOF=== \=\=\=EOF\=\=\=

View File

@ -1,10 +1,7 @@
--TEST-- --TEST--
Test V8::executeString() : var_dump Test V8::executeString() : var_dump
--SKIPIF-- --SKIPIF--
<?php <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
require_once(dirname(__FILE__) . '/skipif.inc');
if (PHP_VERSION_ID >= 70300) die('skip Only for php version < 7.3');
?>
--INI-- --INI--
date.timezone=UTC date.timezone=UTC
--FILE-- --FILE--
@ -73,246 +70,250 @@ try {
} }
?> ?>
===EOF=== ===EOF===
--EXPECTF-- --EXPECTREGEX--
---- PHP var_dump of PHP object ---- \-\-\-\- PHP var_dump of PHP object \-\-\-\-
array(11) { array\(11\) \{
["null"]=> \["null"\]\=\>
NULL NULL
["bool"]=> \["bool"\]\=\>
bool(true) bool\(true\)
["string"]=> \["string"\]\=\>
string(6) "string" string\(6\) "string"
["uint"]=> \["uint"\]\=\>
int(1) int\(1\)
["int"]=> \["int"\]\=\>
int(-1) int\(\-1\)
["number"]=> \["number"\]\=\>
float(3.141592654) float\(3\.141592654\)
["date"]=> \["date"\]\=\>
object(DateTime)#%d (3) { object\(DateTime\)\#\d+ \(3\) \{
["date"]=> \["date"\]\=\>
string(%d) "1976-09-27 09:00:00%r(\.0+)?%r" string\(\d+\) "1976\-09\-27 09\:00\:00((\.0+)?)"
["timezone_type"]=> \["timezone_type"\]\=\>
int(3) int\(3\)
["timezone"]=> \["timezone"\]\=\>
string(3) "UTC" string\(3\) "UTC"
} \}
["array"]=> \["array"\]\=\>
array(3) { array\(3\) \{
[0]=> \[0\]\=\>
int(1) int\(1\)
[1]=> \[1\]\=\>
int(2) int\(2\)
[2]=> \[2\]\=\>
int(3) int\(3\)
} \}
["object"]=> \["object"\]\=\>
array(1) { array\(1\) \{
["field"]=> \["field"\]\=\>
string(3) "foo" string\(3\) "foo"
} \}
["function"]=> \["function"\]\=\>
object(Closure)#%d (1) { object\(Closure\)\#\d+ \(1\) \{
["parameter"]=> \["parameter"\]\=\>
array(1) { array\(1\) \{
["$x"]=> \["\$x"\]\=\>
string(10) "<required>" string\(10\) "\<required\>"
} \}
} \}
["phpobject"]=> \["phpobject"\]\=\>
object(Foo)#%d (1) { object\(Foo\)\#\d+ \(1\) \{
["field"]=> \["field"\]\=\>
string(3) "php" string\(3\) "php"
} \}
} \}
--- JS var_dump of PHP object ---- \-\-\- JS var_dump of PHP object \-\-\-\-
array (11) { array \(11\) \{
["null"] => \["null"\] \=\>
NULL NULL
["bool"] => \["bool"\] \=\>
bool(true) bool\(true\)
["string"] => \["string"\] \=\>
string(6) "string" string\(6\) "string"
["uint"] => \["uint"\] \=\>
int(1) int\(1\)
["int"] => \["int"\] \=\>
int(-1) int\(\-1\)
["number"] => \["number"\] \=\>
float(3.141593) float\(3\.141593\)
["date"] => \["date"\] \=\>
object(DateTime)#%d (18) { object\(DateTime\)\#\d+ \(\d+\) \{(?:
["createFromFormat"] => \["createFromImmutable"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \})?
["getLastErrors"] => \["createFromFormat"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["format"] => \["getLastErrors"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["modify"] => \["format"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["add"] => \["modify"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["sub"] => \["add"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["getTimezone"] => \["sub"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["setTimezone"] => \["getTimezone"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["getOffset"] => \["setTimezone"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["setTime"] => \["getOffset"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["setDate"] => \["setTime"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["setISODate"] => \["setDate"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["setTimestamp"] => \["setISODate"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["getTimestamp"] => \["setTimestamp"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["diff"] => \["getTimestamp"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function () { [native code] } function \(\) \{ \[native code\] \}
} \}
["$date"] => \["diff"\] \=\>
string(%d) "1976-09-27 09:00:00%r(\.0+)?%r" object\(Closure\)\#\d+ \{
["$timezone_type"] => function \(\) \{ \[native code\] \}
int(3) \}(?:(?:the following block is missing from PHP 7.4 on){0}
["$timezone"] => \["\$date"\] \=\>
string(3) "UTC" string\(\d+\) "1976\-09\-27 09\:00\:00((\.0+)?)"
} \["\$timezone_type"\] \=\>
["array"] => int\(3\)
array(3) { \["\$timezone"\] \=\>
[0] => string\(3\) "UTC"
int(1) )?\s*\}
[1] => \["array"\] \=\>
int(2) array\(3\) \{
[2] => \[0\] \=\>
int(3) int\(1\)
} \[1\] \=\>
["object"] => int\(2\)
array (1) { \[2\] \=\>
["field"] => int\(3\)
string(3) "foo" \}
} \["object"\] \=\>
["function"] => array \(1\) \{
object(Closure)#%d (0) { \["field"\] \=\>
} string\(3\) "foo"
["phpobject"] => \}
object(Foo)#%d (1) { \["function"\] \=\>
["$field"] => object\(Closure\)\#\d+ \(0\) \{
string(3) "php" \}
} \["phpobject"\] \=\>
} object\(Foo\)\#\d+ \(1\) \{
--- JS var_dump of JS object ---- \["\$field"\] \=\>
object(Object)#%d (12) { string\(3\) "php"
["undefined"] => \}
\}
\-\-\- JS var_dump of JS object \-\-\-\-
object\(Object\)\#\d+ \(12\) \{
\["undefined"\] \=\>
NULL NULL
["null"] => \["null"\] \=\>
NULL NULL
["bool"] => \["bool"\] \=\>
bool(true) bool\(true\)
["string"] => \["string"\] \=\>
string(6) "string" string\(6\) "string"
["uint"] => \["uint"\] \=\>
int(1) int\(1\)
["int"] => \["int"\] \=\>
int(-1) int\(\-1\)
["number"] => \["number"\] \=\>
float(3.141593) float\(3\.141593\)
["regexp"] => \["regexp"\] \=\>
regexp(/regexp/) regexp\(\/regexp\/\)
["array"] => \["array"\] \=\>
array(3) { array\(3\) \{
[0] => \[0\] \=\>
int(1) int\(1\)
[1] => \[1\] \=\>
int(2) int\(2\)
[2] => \[2\] \=\>
int(3) int\(3\)
} \}
["object"] => \["object"\] \=\>
object(Object)#%d (1) { object\(Object\)\#\d+ \(1\) \{
["field"] => \["field"\] \=\>
string(3) "foo" string\(3\) "foo"
} \}
["function"] => \["function"\] \=\>
object(Closure)#%d { object\(Closure\)\#\d+ \{
function id(x) { return x; } function id\(x\) \{ return x; \}
} \}
["phpobject"] => \["phpobject"\] \=\>
object(Foo)#%d (1) { object\(Foo\)\#\d+ \(1\) \{
["$field"] => \["\$field"\] \=\>
string(3) "php" string\(3\) "php"
} \}
} \}
--- PHP var_dump of JS object ---- \-\-\- PHP var_dump of JS object \-\-\-\-
object(V8Object)#%d (12) { object\(V8Object\)\#\d+ \(12\) \{
["undefined"]=> \["undefined"\]\=\>
NULL NULL
["null"]=> \["null"\]\=\>
NULL NULL
["bool"]=> \["bool"\]\=\>
bool(true) bool\(true\)
["string"]=> \["string"\]\=\>
string(6) "string" string\(6\) "string"
["uint"]=> \["uint"\]\=\>
int(1) int\(1\)
["int"]=> \["int"\]\=\>
int(-1) int\(\-1\)
["number"]=> \["number"\]\=\>
float(3.141592654) float\(3\.141592654\)
["regexp"]=> \["regexp"\]\=\>
object(V8Object)#%d (0) { object\(V8Object\)\#\d+ \(0\) \{
} \}
["array"]=> \["array"\]\=\>
array(3) { array\(3\) \{
[0]=> \[0\]\=\>
int(1) int\(1\)
[1]=> \[1\]\=\>
int(2) int\(2\)
[2]=> \[2\]\=\>
int(3) int\(3\)
} \}
["object"]=> \["object"\]\=\>
object(V8Object)#%d (1) { object\(V8Object\)\#\d+ \(1\) \{
["field"]=> \["field"\]\=\>
string(3) "foo" string\(3\) "foo"
} \}
["function"]=> \["function"\]\=\>
object(V8Function)#%d (0) { object\(V8Function\)\#\d+ \(0\) \{
} \}
["phpobject"]=> \["phpobject"\]\=\>
object(Foo)#%d (1) { object\(Foo\)\#\d+ \(1\) \{
["field"]=> \["field"\]\=\>
string(3) "php" string\(3\) "php"
} \}
} \}
===EOF=== \=\=\=EOF\=\=\=

View File

@ -1,322 +0,0 @@
--TEST--
Test V8::executeString() : var_dump
--SKIPIF--
<?php
require_once(dirname(__FILE__) . '/skipif.inc');
if (PHP_VERSION_ID < 70300) die('skip Only for php version >= 7.3');
?>
--INI--
date.timezone=UTC
--FILE--
<?php
# Test var_dump of various types
$JS = <<< EOT
print("--- JS var_dump of PHP object ----\\n");
var_dump(PHP.phptypes);
print("--- JS var_dump of JS object ----\\n");
var types = {
undefined: undefined,
null: null,
bool: true,
string: "string",
uint: 1,
int: -1,
number: 3.141592654,
// XXX this gets parsed with local timezone,
// which is bad for test repeatability.
//date: new Date('September 27, 1976 09:00:00 GMT'),
regexp: /regexp/,
array: [1,2,3],
object: { field: "foo" },
function: function id(x) { return x; },
phpobject: PHP.obj
};
var_dump(types);
print("--- PHP var_dump of JS object ----\\n");
types;
EOT;
class Foo {
var $field = "php";
}
$v8 = new V8Js();
$v8->obj = new Foo;
$phptypes = $v8->phptypes = array(
"null" => NULL,
"bool" => true,
"string" => "string",
"uint" => 1,
"int" => -1,
"number" => 3.141592654,
"date" => new DateTime('September 27, 1976 09:00:00 UTC', new DateTimeZone('UTC')),
//"regexp" => new Regexp('/regexp/'), /* no native PHP regex type */
"array" => array(1,2,3),
"object" => array( "field" => "foo" ),
"function" => (function ($x) { return $x; }),
"phpobject" => new Foo
);
echo "---- PHP var_dump of PHP object ----\n";
var_dump($phptypes);
try {
var_dump($v8->executeString($JS, 'var_dump.js'));
} catch (V8JsScriptException $e) {
echo "Error!\n";
var_dump($e);
}
?>
===EOF===
--EXPECTF--
---- PHP var_dump of PHP object ----
array(11) {
["null"]=>
NULL
["bool"]=>
bool(true)
["string"]=>
string(6) "string"
["uint"]=>
int(1)
["int"]=>
int(-1)
["number"]=>
float(3.141592654)
["date"]=>
object(DateTime)#%d (3) {
["date"]=>
string(%d) "1976-09-27 09:00:00%r(\.0+)?%r"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["array"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["object"]=>
array(1) {
["field"]=>
string(3) "foo"
}
["function"]=>
object(Closure)#%d (1) {
["parameter"]=>
array(1) {
["$x"]=>
string(10) "<required>"
}
}
["phpobject"]=>
object(Foo)#%d (1) {
["field"]=>
string(3) "php"
}
}
--- JS var_dump of PHP object ----
array (11) {
["null"] =>
NULL
["bool"] =>
bool(true)
["string"] =>
string(6) "string"
["uint"] =>
int(1)
["int"] =>
int(-1)
["number"] =>
float(3.141593)
["date"] =>
object(DateTime)#%d (19) {
["createFromImmutable"] =>
object(Closure)#%d {
function () { [native code] }
}
["createFromFormat"] =>
object(Closure)#%d {
function () { [native code] }
}
["getLastErrors"] =>
object(Closure)#%d {
function () { [native code] }
}
["format"] =>
object(Closure)#%d {
function () { [native code] }
}
["modify"] =>
object(Closure)#%d {
function () { [native code] }
}
["add"] =>
object(Closure)#%d {
function () { [native code] }
}
["sub"] =>
object(Closure)#%d {
function () { [native code] }
}
["getTimezone"] =>
object(Closure)#%d {
function () { [native code] }
}
["setTimezone"] =>
object(Closure)#%d {
function () { [native code] }
}
["getOffset"] =>
object(Closure)#%d {
function () { [native code] }
}
["setTime"] =>
object(Closure)#%d {
function () { [native code] }
}
["setDate"] =>
object(Closure)#%d {
function () { [native code] }
}
["setISODate"] =>
object(Closure)#%d {
function () { [native code] }
}
["setTimestamp"] =>
object(Closure)#%d {
function () { [native code] }
}
["getTimestamp"] =>
object(Closure)#%d {
function () { [native code] }
}
["diff"] =>
object(Closure)#%d {
function () { [native code] }
}
["$date"] =>
string(%d) "1976-09-27 09:00:00%r(\.0+)?%r"
["$timezone_type"] =>
int(3)
["$timezone"] =>
string(3) "UTC"
}
["array"] =>
array(3) {
[0] =>
int(1)
[1] =>
int(2)
[2] =>
int(3)
}
["object"] =>
array (1) {
["field"] =>
string(3) "foo"
}
["function"] =>
object(Closure)#%d (0) {
}
["phpobject"] =>
object(Foo)#%d (1) {
["$field"] =>
string(3) "php"
}
}
--- JS var_dump of JS object ----
object(Object)#%d (12) {
["undefined"] =>
NULL
["null"] =>
NULL
["bool"] =>
bool(true)
["string"] =>
string(6) "string"
["uint"] =>
int(1)
["int"] =>
int(-1)
["number"] =>
float(3.141593)
["regexp"] =>
regexp(/regexp/)
["array"] =>
array(3) {
[0] =>
int(1)
[1] =>
int(2)
[2] =>
int(3)
}
["object"] =>
object(Object)#%d (1) {
["field"] =>
string(3) "foo"
}
["function"] =>
object(Closure)#%d {
function id(x) { return x; }
}
["phpobject"] =>
object(Foo)#%d (1) {
["$field"] =>
string(3) "php"
}
}
--- PHP var_dump of JS object ----
object(V8Object)#%d (12) {
["undefined"]=>
NULL
["null"]=>
NULL
["bool"]=>
bool(true)
["string"]=>
string(6) "string"
["uint"]=>
int(1)
["int"]=>
int(-1)
["number"]=>
float(3.141592654)
["regexp"]=>
object(V8Object)#%d (0) {
}
["array"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["object"]=>
object(V8Object)#%d (1) {
["field"]=>
string(3) "foo"
}
["function"]=>
object(V8Function)#%d (0) {
}
["phpobject"]=>
object(Foo)#%d (1) {
["field"]=>
string(3) "php"
}
}
===EOF===