Bläddra i källkod

use EXPECTREGEX to handle different PHP version's output well

Stefan Siegl 5 år sedan
förälder
incheckning
fcd78f830a
3 ändrade filer med 261 tillägg och 582 borttagningar
  1. 19 19
      tests/issue_250_001.phpt
  2. 242 241
      tests/var_dump.phpt
  3. 0 322
      tests/var_dump_73.phpt

+ 19 - 19
tests/issue_250_001.phpt

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

+ 242 - 241
tests/var_dump.phpt

@@ -1,10 +1,7 @@
 --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');
-?>
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
 --INI--
 date.timezone=UTC
 --FILE--
@@ -73,246 +70,250 @@ try {
 }
 ?>
 ===EOF===
---EXPECTF--
----- PHP var_dump of PHP object ----
-array(11) {
-  ["null"]=>
+--EXPECTREGEX--
+\-\-\-\- 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"] =>
+  \["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((\.0+)?)"
+    \["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 (18) {
-    ["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"] =>
+  \["bool"\] \=\>
+  bool\(true\)
+  \["string"\] \=\>
+  string\(6\) "string"
+  \["uint"\] \=\>
+  int\(1\)
+  \["int"\] \=\>
+  int\(\-1\)
+  \["number"\] \=\>
+  float\(3\.141593\)
+  \["date"\] \=\>
+  object\(DateTime\)\#\d+ \(\d+\) \{(?:
+    \["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\] \}
+    \}(?:(?:the following block is missing from PHP 7.4 on){0}
+    \["\$date"\] \=\>
+    string\(\d+\) "1976\-09\-27 09\:00\:00((\.0+)?)"
+    \["\$timezone_type"\] \=\>
+    int\(3\)
+    \["\$timezone"\] \=\>
+    string\(3\) "UTC"
+ )?\s*\}
+  \["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"\] \=\>
   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"]=>
+  \["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"\]\=\>
   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===
+  \["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\=\=\=

+ 0 - 322
tests/var_dump_73.phpt

@@ -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===