summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/tests
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/phpdbg/tests')
-rw-r--r--sapi/phpdbg/tests/basic_run.phpt8
-rw-r--r--sapi/phpdbg/tests/breakpoints_001.phpt33
-rw-r--r--sapi/phpdbg/tests/breakpoints_002.phpt40
-rw-r--r--sapi/phpdbg/tests/breakpoints_003.phpt33
-rw-r--r--sapi/phpdbg/tests/breakpoints_004.phpt41
-rw-r--r--sapi/phpdbg/tests/breakpoints_005.phpt28
-rw-r--r--sapi/phpdbg/tests/breakpoints_006.phpt26
-rw-r--r--sapi/phpdbg/tests/breakpoints_007.phpt25
-rw-r--r--sapi/phpdbg/tests/breakpoints_008.phpt34
-rw-r--r--sapi/phpdbg/tests/clean_001.phpt60
-rw-r--r--sapi/phpdbg/tests/clear_001.phpt44
-rw-r--r--sapi/phpdbg/tests/commands/0001_basic.test8
-rw-r--r--sapi/phpdbg/tests/commands/0002_set.test21
-rw-r--r--sapi/phpdbg/tests/commands/0101_info.test19
-rw-r--r--sapi/phpdbg/tests/commands/0102_print.test28
-rw-r--r--sapi/phpdbg/tests/commands/0103_register.test28
-rw-r--r--sapi/phpdbg/tests/commands/0104_clean.test15
-rw-r--r--sapi/phpdbg/tests/commands/0105_clear.test18
-rw-r--r--sapi/phpdbg/tests/commands/0106_compile.test18
-rw-r--r--sapi/phpdbg/tests/delimiter.phpt7
-rw-r--r--sapi/phpdbg/tests/exceptions_001.phpt46
-rw-r--r--sapi/phpdbg/tests/exceptions_002.phpt51
-rw-r--r--sapi/phpdbg/tests/exceptions_003.phpt54
-rw-r--r--sapi/phpdbg/tests/finish_leave_001.phpt41
-rw-r--r--sapi/phpdbg/tests/generator_run.phpt24
-rw-r--r--sapi/phpdbg/tests/include.inc3
-rw-r--r--sapi/phpdbg/tests/include_once.phpt16
-rw-r--r--sapi/phpdbg/tests/info_001.phpt80
-rw-r--r--sapi/phpdbg/tests/info_002.phpt31
-rw-r--r--sapi/phpdbg/tests/next_001.phpt37
-rw-r--r--sapi/phpdbg/tests/normal_exit.phpt15
-rw-r--r--sapi/phpdbg/tests/phpdbg_break_next.phpt22
-rw-r--r--sapi/phpdbg/tests/phpdbg_oplog_001.phpt58
-rw-r--r--sapi/phpdbg/tests/phpdbg_oplog_002.phpt16
-rw-r--r--sapi/phpdbg/tests/print_001.phpt67
-rw-r--r--sapi/phpdbg/tests/print_002.phpt51
-rw-r--r--sapi/phpdbg/tests/run-tests.php597
-rw-r--r--sapi/phpdbg/tests/run_001.phpt56
-rw-r--r--sapi/phpdbg/tests/run_002.phpt50
-rw-r--r--sapi/phpdbg/tests/set_exception_handler.phpt19
-rw-r--r--sapi/phpdbg/tests/stdin_001.phpt25
-rw-r--r--sapi/phpdbg/tests/stepping_001.phpt65
-rw-r--r--sapi/phpdbg/tests/watch_001.phpt45
43 files changed, 1251 insertions, 752 deletions
diff --git a/sapi/phpdbg/tests/basic_run.phpt b/sapi/phpdbg/tests/basic_run.phpt
new file mode 100644
index 0000000000..beb19b535a
--- /dev/null
+++ b/sapi/phpdbg/tests/basic_run.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Basic run
+--PHPDBG--
+r
+q
+--EXPECTF--
+prompt> [Nothing to execute!]
+prompt>
diff --git a/sapi/phpdbg/tests/breakpoints_001.phpt b/sapi/phpdbg/tests/breakpoints_001.phpt
new file mode 100644
index 0000000000..934f0d3554
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_001.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Fundamental breakpoints functionality
+--PHPDBG--
+b 3
+r
+b 4
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:3]
+prompt> [Breakpoint #0 at %s:3, hits: 1]
+>00003: echo 1;
+ 00004: echo 2;
+ 00005: echo 3;
+prompt> [Breakpoint #1 added at %s:4]
+prompt> 1
+[Breakpoint #1 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> 234
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
+
diff --git a/sapi/phpdbg/tests/breakpoints_002.phpt b/sapi/phpdbg/tests/breakpoints_002.phpt
new file mode 100644
index 0000000000..18aaef1f36
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_002.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Preserve breakpoints on restart
+--PHPDBG--
+b breakpoints_002.php:4
+r
+b 3
+r
+y
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> [Breakpoint #1 added at %s:3]
+prompt> Do you really want to restart execution? (type y or n): [Breakpoint #1 at %s:3, hits: 1]
+>00003: echo 1;
+ 00004: echo 2;
+ 00005: echo 3;
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> 234
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
+
diff --git a/sapi/phpdbg/tests/breakpoints_003.phpt b/sapi/phpdbg/tests/breakpoints_003.phpt
new file mode 100644
index 0000000000..8caa64632b
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_003.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test deleting breakpoints
+--PHPDBG--
+b 4
+b del 0
+b 5
+r
+b del 1
+r
+y
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Deleted breakpoint #0]
+prompt> [Breakpoint #1 added at %s:5]
+prompt> 12
+[Breakpoint #1 at %s:5, hits: 1]
+>00005: echo 3;
+ 00006: echo 4;
+ 00007:
+prompt> [Deleted breakpoint #1]
+prompt> Do you really want to restart execution? (type y or n): 1234
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
+
diff --git a/sapi/phpdbg/tests/breakpoints_004.phpt b/sapi/phpdbg/tests/breakpoints_004.phpt
new file mode 100644
index 0000000000..27ebd0bea2
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_004.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test opcode breakpoints
+--PHPDBG--
+b ZEND_ECHO
+r
+c
+
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at ZEND_ECHO]
+prompt> [Breakpoint #0 in ZEND_ECHO at %s:3, hits: 1]
+>00003: echo 1;
+ 00004: echo 2;
+ 00005: echo 3;
+prompt> 1
+[Breakpoint #0 in ZEND_ECHO at %s:4, hits: 2]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> 2
+[Breakpoint #0 in ZEND_ECHO at %s:5, hits: 3]
+>00005: echo 3;
+ 00006: echo 4;
+ 00007:
+prompt> 3
+[Breakpoint #0 in ZEND_ECHO at %s:6, hits: 4]
+>00006: echo 4;
+ 00007:
+prompt> 4
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
diff --git a/sapi/phpdbg/tests/breakpoints_005.phpt b/sapi/phpdbg/tests/breakpoints_005.phpt
new file mode 100644
index 0000000000..653dab9fcc
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_005.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test breakpoint into function context
+--PHPDBG--
+b breakpoints_005.php:4
+r
+ev $bar
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #0 at %s:4, hits: 1]
+>00004: var_dump($bar);
+ 00005: }
+ 00006:
+prompt> test
+prompt> string(4) "test"
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function foo($bar) {
+ var_dump($bar);
+}
+
+foo("test");
+
diff --git a/sapi/phpdbg/tests/breakpoints_006.phpt b/sapi/phpdbg/tests/breakpoints_006.phpt
new file mode 100644
index 0000000000..fa6f0cdc5b
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_006.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Basic function breakpoints
+--PHPDBG--
+b foo
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at foo]
+prompt> [Breakpoint #0 in foo() at %s:4, hits: 1]
+>00004: var_dump($bar);
+ 00005: }
+ 00006:
+prompt> string(4) "test"
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function foo($bar) {
+ var_dump($bar);
+}
+
+foo("test");
+
diff --git a/sapi/phpdbg/tests/breakpoints_007.phpt b/sapi/phpdbg/tests/breakpoints_007.phpt
new file mode 100644
index 0000000000..f921c257c5
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_007.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Basic method breakpoints
+--PHPDBG--
+b bar::foo
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at bar::foo]
+prompt> [Breakpoint #0 in bar::foo() at %s:5, hits: 1]
+>00005: var_dump($bar);
+ 00006: }
+ 00007: }
+prompt>
+--FILE--
+<?php
+
+class bar {
+ function foo($bar) {
+ var_dump($bar);
+ }
+}
+
+(new bar)->foo("test");
+
diff --git a/sapi/phpdbg/tests/breakpoints_008.phpt b/sapi/phpdbg/tests/breakpoints_008.phpt
new file mode 100644
index 0000000000..cbe5042c2b
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_008.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test namespaced and non-lowercase breakpoint names
+--PHPDBG--
+b foo\bar::foo
+b \Foo\Bar::Foo
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at foo\bar::foo]
+prompt> [Breakpoint exists at Foo\Bar::Foo]
+prompt> [Breakpoint #0 in foo\bar::foo() at %s:6, hits: 1]
+>00006: var_dump($bar);
+ 00007: }
+ 00008: }
+prompt> string(4) "test"
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+ }
+}
+
+namespace {
+ (new \Foo\Bar)->Foo("test");
+}
+
diff --git a/sapi/phpdbg/tests/clean_001.phpt b/sapi/phpdbg/tests/clean_001.phpt
new file mode 100644
index 0000000000..0500850448
--- /dev/null
+++ b/sapi/phpdbg/tests/clean_001.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Cleaning must preserve breakpoints
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 4
+b foo
+r
+c
+clean
+y
+c
+r
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #1 added at foo]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: foo();
+prompt> 23
+[Breakpoint #1 in foo() at %s:9, hits: 1]
+>00009: echo 4;
+ 00010: }
+ 00011:
+prompt> Do you really want to clean your current environment? (type y or n): Cleaning Execution Environment
+Classes %d
+Functions %d
+Constants %d
+Includes 0
+prompt> [Not running]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: foo();
+prompt> 23
+[Breakpoint #1 in foo() at %s:9, hits: 1]
+>00009: echo 4;
+ 00010: }
+ 00011:
+prompt> 4
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+foo();
+
+function foo() {
+ echo 4;
+}
diff --git a/sapi/phpdbg/tests/clear_001.phpt b/sapi/phpdbg/tests/clear_001.phpt
new file mode 100644
index 0000000000..96d73990eb
--- /dev/null
+++ b/sapi/phpdbg/tests/clear_001.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test clearing breakpoints
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 4
+b foo
+r
+clear
+c
+i b
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #1 added at foo]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: foo();
+prompt> Clearing Breakpoints
+File 1
+Functions 1
+Methods 0
+Oplines 0
+File oplines 0
+Function oplines 0
+Method oplines 0
+Conditionals 0
+prompt> 234
+[Script ended normally]
+prompt> prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+foo();
+
+function foo() {
+ echo 4;
+}
diff --git a/sapi/phpdbg/tests/commands/0001_basic.test b/sapi/phpdbg/tests/commands/0001_basic.test
deleted file mode 100644
index 08aa9ab664..0000000000
--- a/sapi/phpdbg/tests/commands/0001_basic.test
+++ /dev/null
@@ -1,8 +0,0 @@
-#######################################################
-# name: basic
-# purpose: check basic functionality of phpdbg console
-# expect: TEST::EXACT
-# options: -rr
-#######################################################
-# [Nothing to execute!]
-#######################################################
diff --git a/sapi/phpdbg/tests/commands/0002_set.test b/sapi/phpdbg/tests/commands/0002_set.test
deleted file mode 100644
index 468ac6d9ea..0000000000
--- a/sapi/phpdbg/tests/commands/0002_set.test
+++ /dev/null
@@ -1,21 +0,0 @@
-#################################################
-# name: set
-# purpose: tests for set commands
-# expect: TEST::CISTRING
-# options: -rr
-#################################################
-# setting prompt color
-# setting error color
-# setting notice color
-# Failed to find breakpoint #0
-# oplog disabled
-# opened oplog test.log
-# nothing
-#################################################
-set color prompt none
-set color error none
-set color notice none
-set prompt promot>
-set break 0
-set oplog
-set oplog test.log
diff --git a/sapi/phpdbg/tests/commands/0101_info.test b/sapi/phpdbg/tests/commands/0101_info.test
deleted file mode 100644
index 397a45c992..0000000000
--- a/sapi/phpdbg/tests/commands/0101_info.test
+++ /dev/null
@@ -1,19 +0,0 @@
-#################################################
-# name: info
-# purpose: test info commands
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[User Classes (%d)]
-#User Class test (3)
-#|---- in phpdbginit code on line %d
-#################################################
-<:
-class test {
- public function testMethod(){}
- private function testPrivateMethod(){}
- protected function testProtectedMethod(){}
-}
-:>
-info classes
-q
diff --git a/sapi/phpdbg/tests/commands/0102_print.test b/sapi/phpdbg/tests/commands/0102_print.test
deleted file mode 100644
index de4acb7651..0000000000
--- a/sapi/phpdbg/tests/commands/0102_print.test
+++ /dev/null
@@ -1,28 +0,0 @@
-#################################################
-# name: print
-# purpose: test print commands
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[User Class: test]
-#Methods (3):
-#L%d-%d test::testMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-# L%d-%d test::testPrivateMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-# L%d-%d test::testProtectedMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-#[User Method testMethod]
-# L%d-%d test::testMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-#################################################
-<:
-class test {
- public function testMethod(){}
- private function testPrivateMethod(){}
- protected function testProtectedMethod(){}
-}
-:>
-print class test
-print method test::testMethod
-q
diff --git a/sapi/phpdbg/tests/commands/0103_register.test b/sapi/phpdbg/tests/commands/0103_register.test
deleted file mode 100644
index 703a12f771..0000000000
--- a/sapi/phpdbg/tests/commands/0103_register.test
+++ /dev/null
@@ -1,28 +0,0 @@
-#################################################
-# name: register
-# purpose: test registration functions
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Registered test_function]
-#array(5) {
-# [0]=>
-# int(1)
-# [1]=>
-# int(2)
-# [2]=>
-# int(3)
-# [3]=>
-# int(4)
-# [4]=>
-# int(5)
-#}
-#################################################
-<:
-function test_function() {
- var_dump(func_get_args());
-}
-:>
-R test_function
-test_function 1 2 3 4 5
-q
diff --git a/sapi/phpdbg/tests/commands/0104_clean.test b/sapi/phpdbg/tests/commands/0104_clean.test
deleted file mode 100644
index c7a579be17..0000000000
--- a/sapi/phpdbg/tests/commands/0104_clean.test
+++ /dev/null
@@ -1,15 +0,0 @@
-#################################################
-# name: clean
-# purpose: test cleaning environment
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Cleaning Execution Environment]
-#Classes %d
-#Functions %d
-#Constants %d
-#Includes %d
-#[Nothing to execute!]
-#################################################
-clean
-quit
diff --git a/sapi/phpdbg/tests/commands/0105_clear.test b/sapi/phpdbg/tests/commands/0105_clear.test
deleted file mode 100644
index b547b0d6ba..0000000000
--- a/sapi/phpdbg/tests/commands/0105_clear.test
+++ /dev/null
@@ -1,18 +0,0 @@
-#################################################
-# name: clear
-# purpose: test clearing breakpoints
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Clearing Breakpoints]
-#File%w%d
-#Functions%w%d
-#Methods%w%d
-#Oplines%w%d
-#File oplines%w%d
-#Function oplines%w%d
-#Method oplines%w%d
-#Conditionals%w%d
-#################################################
-clear
-quit
diff --git a/sapi/phpdbg/tests/commands/0106_compile.test b/sapi/phpdbg/tests/commands/0106_compile.test
deleted file mode 100644
index 7193600ea3..0000000000
--- a/sapi/phpdbg/tests/commands/0106_compile.test
+++ /dev/null
@@ -1,18 +0,0 @@
-#################################################
-# name: compile
-# purpose: test compiling code
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Attempting compilation of %s]
-#[Success]
-#Hello World
-#################################################
-<:
-define('OUT',
- tempnam(null, "phpdbg"));
-file_put_contents(OUT, "<?php echo \"Hello World\"; ?>");
-phpdbg_exec(OUT);
-:>
-run
-quit
diff --git a/sapi/phpdbg/tests/delimiter.phpt b/sapi/phpdbg/tests/delimiter.phpt
new file mode 100644
index 0000000000..da5f681783
--- /dev/null
+++ b/sapi/phpdbg/tests/delimiter.phpt
@@ -0,0 +1,7 @@
+--TEST--
+Test # delimiter parsing and execution
+--PHPDBG--
+ev 1 + 3 # ev 2 ** 3#q
+--EXPECTF--
+prompt> 4
+8
diff --git a/sapi/phpdbg/tests/exceptions_001.phpt b/sapi/phpdbg/tests/exceptions_001.phpt
new file mode 100644
index 0000000000..991ea1cc71
--- /dev/null
+++ b/sapi/phpdbg/tests/exceptions_001.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Properly handle exceptions going to be uncaught
+--PHPDBG--
+r
+t
+ev 1 + 2
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> handle first
+[Uncaught Error in %s on line 16: Call to undefined function foo()]
+>00016: foo(); // Error
+ 00017: } catch (\Exception $e) {
+ 00018: var_dump($e);
+prompt> frame #0: {closure}() at %s:16
+frame #1: {main} at %s:20
+prompt> 3
+prompt> [Uncaught Error in %s on line 16]
+Error: Call to undefined function foo() in %s:16
+Stack trace:
+#0 %s(20): {closure}()
+#1 {main}
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ } finally {
+ print "handle first\n";
+ return "ok";
+ }
+})();
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ }
+})();
diff --git a/sapi/phpdbg/tests/exceptions_002.phpt b/sapi/phpdbg/tests/exceptions_002.phpt
new file mode 100644
index 0000000000..f304cc25db
--- /dev/null
+++ b/sapi/phpdbg/tests/exceptions_002.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test exceptions in eval during exception
+--PHPDBG--
+r
+ev next_error()
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> handle first
+[Uncaught Error in %s on line 16: Call to undefined function foo()]
+>00016: foo(); // Error
+ 00017: } catch (\Exception $e) {
+ 00018: var_dump($e);
+prompt>
+Fatal error: Uncaught Error: Call to undefined function next_error() in eval()'d code:1
+Stack trace:
+#0 %s(16): unknown()
+#1 %s(20): {closure}()
+#2 {main}
+ thrown in eval()'d code on line 1
+prompt> [Uncaught Error in %s on line 16]
+Error: Call to undefined function foo() in %s:16
+Stack trace:
+#0 %s(20): {closure}()
+#1 {main}
+[Script ended normally]
+prompt> [The stack contains nothing !]
+prompt>
+--FILE--
+<?php
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ } finally {
+ print "handle first\n";
+ return "ok";
+ }
+})();
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ }
+})();
diff --git a/sapi/phpdbg/tests/exceptions_003.phpt b/sapi/phpdbg/tests/exceptions_003.phpt
new file mode 100644
index 0000000000..252fe32f1a
--- /dev/null
+++ b/sapi/phpdbg/tests/exceptions_003.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test breaks on HANDLE_EXCEPTION
+--PHPDBG--
+b 5
+r
+s
+
+s
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:5]
+prompt> [Breakpoint #0 at %s:5, hits: 1]
+>00005: x();
+ 00006: } finally {
+ 00007: print "ok\n";
+prompt> [L0 %s HANDLE_EXCEPTION %s]
+>00005: x();
+ 00006: } finally {
+ 00007: print "ok\n";
+prompt> [L7 %s ECHO "ok " %s]
+>00007: print "ok\n";
+ 00008: }
+ 00009: } catch (Error $e) {
+prompt> ok
+[L7 %s FAST_RET<TO_CATCH> ~%d J7 %s]
+[L9 %s CATCH "Error" $e 1 %s]
+>00005: x();
+ 00006: } finally {
+ 00007: print "ok\n";
+prompt> [L10 %s ECHO "caught " %s]
+>00010: print "caught\n";
+ 00011: }
+ 00012:
+prompt> caught
+[L14 %s RETURN 1 %s]
+>00014:
+prompt>
+--FILE--
+<?php
+
+try {
+ try {
+ x();
+ } finally {
+ print "ok\n";
+ }
+} catch (Error $e) {
+ print "caught\n";
+}
+
+?>
diff --git a/sapi/phpdbg/tests/finish_leave_001.phpt b/sapi/phpdbg/tests/finish_leave_001.phpt
new file mode 100644
index 0000000000..774776c05f
--- /dev/null
+++ b/sapi/phpdbg/tests/finish_leave_001.phpt
@@ -0,0 +1,41 @@
+--TEST--
+test finish and leave commands
+--PHPDBG--
+b bar
+b 5
+r
+finish
+leave
+leave
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at bar]
+prompt> [Breakpoint #1 added at %s:5]
+prompt> [Breakpoint #0 in bar() at %s:9, hits: 1]
+>00009: return "world";
+ 00010: }
+ 00011:
+prompt> [Breakpoint #1 at %s:5, hits: 1]
+>00005: return ["hello", $other];
+ 00006: }
+ 00007:
+prompt> [Breaking for leave at %s:5]
+>00005: return ["hello", $other];
+ 00006: }
+ 00007:
+prompt> [Already at the end of the function]
+prompt>
+--FILE--
+<?php
+function foo() {
+ $other = bar();
+
+ return ["hello", $other];
+}
+
+function bar() {
+ return "world";
+}
+
+foo();
diff --git a/sapi/phpdbg/tests/generator_run.phpt b/sapi/phpdbg/tests/generator_run.phpt
new file mode 100644
index 0000000000..798d77051e
--- /dev/null
+++ b/sapi/phpdbg/tests/generator_run.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Ensure proper saving of EX(opline)
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> caught Generator exception
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function gen() {
+ try {
+ throw new Exception;
+ } catch(Exception $e) {
+ yield "caught Generator exception";
+ }
+}
+
+foreach (gen() as $v) {
+ print $v;
+}
diff --git a/sapi/phpdbg/tests/include.inc b/sapi/phpdbg/tests/include.inc
new file mode 100644
index 0000000000..fb1b7ca841
--- /dev/null
+++ b/sapi/phpdbg/tests/include.inc
@@ -0,0 +1,3 @@
+<?php
+
+echo 1;
diff --git a/sapi/phpdbg/tests/include_once.phpt b/sapi/phpdbg/tests/include_once.phpt
new file mode 100644
index 0000000000..0a00e04cde
--- /dev/null
+++ b/sapi/phpdbg/tests/include_once.phpt
@@ -0,0 +1,16 @@
+--TEST--
+include_once must include only once
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> 1
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+include_once __DIR__.'/include.inc';
+include_once __DIR__.'/include.inc';
+
diff --git a/sapi/phpdbg/tests/info_001.phpt b/sapi/phpdbg/tests/info_001.phpt
new file mode 100644
index 0000000000..b988235757
--- /dev/null
+++ b/sapi/phpdbg/tests/info_001.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Test basic info functionality
+--INI--
+auto_globals_jit=0
+--PHPDBG--
+i classes
+i funcs
+b foo
+r
+i v
+i g
+i b
+i d
+i F
+i e
+i l
+c
+i v
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [User Classes (1)]
+User Class Foo\Bar (2)
+|---- in %s on line 4
+prompt> [User Functions (1)]
+|-------- foo in %s on line 14
+prompt> [Breakpoint #0 added at foo]
+prompt> string(4) "test"
+[Breakpoint #0 in foo() at %s:15, hits: 1]
+>00015: var_dump(strrev($baz));
+ 00016: }
+ 00017:
+prompt> [Variables in foo() (1)]
+Address Refs Type Variable
+%s 1 string $baz
+string (4) "test"
+prompt> [Superglobal variables (8)]
+Address Refs Type Variable
+%s 2 array $_GET
+%s 2 array $_POST
+%s 2 array $_COOKIE
+%s 2 array $_SERVER
+%s 2 array $_ENV
+%s 1 array $_REQUEST
+%s 2 array $_FILES
+%s 1 array &$GLOBALS
+prompt> ------------------------------------------------
+Function Breakpoints:
+#0 foo
+prompt> [User-defined constants (0)]
+prompt> [Included files: 0]
+prompt> [No error found!]
+prompt> [Literal Constants in foo() (2)]
+|-------- C0 -------> [var_dump]
+|-------- C1 -------> [strrev]
+prompt> string(4) "tset"
+[Script ended normally]
+prompt> [No active op array!]
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+
+ function baz() { }
+ }
+}
+
+namespace {
+ function foo($baz) {
+ var_dump(strrev($baz));
+ }
+
+ (new \Foo\Bar)->Foo("test");
+ foo("test");
+}
diff --git a/sapi/phpdbg/tests/info_002.phpt b/sapi/phpdbg/tests/info_002.phpt
new file mode 100644
index 0000000000..faeca0e430
--- /dev/null
+++ b/sapi/phpdbg/tests/info_002.phpt
@@ -0,0 +1,31 @@
+--TEST--
+info constants test
+--PHPDBG--
+b 10
+r
+i d
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:10]
+prompt> [Breakpoint #0 at %s:10, hits: 1]
+>00010: print B;
+ 00011:
+prompt> [User-defined constants (2)]
+Address Refs Type Constant
+%s 1 integer A
+int (10)
+%s 1 integer B
+int (100)
+prompt>
+--FILE--
+<?php
+
+const A = 10;
+const B = C::D * A;
+
+class C {
+ const D = 10;
+}
+
+print B;
diff --git a/sapi/phpdbg/tests/next_001.phpt b/sapi/phpdbg/tests/next_001.phpt
new file mode 100644
index 0000000000..b07d954303
--- /dev/null
+++ b/sapi/phpdbg/tests/next_001.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test next command on function boundaries
+--PHPDBG--
+b 4
+r
+n
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 0;
+ 00005: }
+ 00006:
+prompt> 0
+[L5 %s RETURN null %s]
+>00005: }
+ 00006:
+ 00007: foo();
+prompt> [L8 %s ECHO 1 %s]
+>00008: echo 1;
+ 00009:
+prompt> 1
+[L9 %s RETURN 1 %s]
+>00009:
+prompt>
+--FILE--
+<?php
+
+function foo() {
+ echo 0;
+}
+
+foo();
+echo 1;
diff --git a/sapi/phpdbg/tests/normal_exit.phpt b/sapi/phpdbg/tests/normal_exit.phpt
new file mode 100644
index 0000000000..692614e98f
--- /dev/null
+++ b/sapi/phpdbg/tests/normal_exit.phpt
@@ -0,0 +1,15 @@
+--TEST--
+A script with die() must end "normally"
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Script ended normally]
+prompt>
+--FILE--
+<?php
+
+(function($argv) {
+ die();
+})($argv);
diff --git a/sapi/phpdbg/tests/phpdbg_break_next.phpt b/sapi/phpdbg/tests/phpdbg_break_next.phpt
new file mode 100644
index 0000000000..37ee2e8282
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_break_next.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Test phpdbg_break_next() function
+--PHPDBG--
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> A
+[Breakpoint #0 added at %s]
+[Breakpoint #0 in %s at %s:5, hits: 1]
+>00005: echo 'B';
+ 00006:
+prompt> B
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 'A';
+phpdbg_break_next();
+echo 'B';
diff --git a/sapi/phpdbg/tests/phpdbg_oplog_001.phpt b/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
new file mode 100644
index 0000000000..e4e558b9fa
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Test phpdbg_*_oplog() functions
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> halloarray(2) {
+ ["%s"]=>
+ array(5) {
+ [13]=>
+ int(1)
+ [17]=>
+ int(2)
+ [18]=>
+ int(2)
+ [19]=>
+ int(3)
+ [21]=>
+ int(4)
+ }
+ ["A::b"]=>
+ array(3) {
+ [4]=>
+ int(1)
+ [5]=>
+ int(3)
+ [8]=>
+ int(2)
+ }
+}
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+class A {
+ public function b($c = 1) {
+ if ($c == 1) {
+ // comment
+ }
+ }
+}
+
+phpdbg_start_oplog();
+
+echo "hallo";
+
+// fcalls
+
+$a = new A();
+$a->b();
+$a->b('ha');
+
+var_dump(phpdbg_end_oplog(["functions" => true]));
+
diff --git a/sapi/phpdbg/tests/phpdbg_oplog_002.phpt b/sapi/phpdbg/tests/phpdbg_oplog_002.phpt
new file mode 100644
index 0000000000..b9ba905caa
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_oplog_002.phpt
@@ -0,0 +1,16 @@
+--TEST--
+phpdbg_end_oplog() alone must not crash
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt>
+Warning: Can not end an oplog without starting it in %s on line 3
+NULL
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+var_dump(phpdbg_end_oplog());
diff --git a/sapi/phpdbg/tests/print_001.phpt b/sapi/phpdbg/tests/print_001.phpt
new file mode 100644
index 0000000000..94ccedc3cf
--- /dev/null
+++ b/sapi/phpdbg/tests/print_001.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Basic print functionality
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+p foo
+p class \Foo\bar
+p
+p e
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [User Function foo (8 ops)]
+L14-16 foo() %s - %s + 8 ops
+ L14 #0 RECV 1 $baz
+ L15 #1 INIT_FCALL%s %d %s "var_dump"
+ L15 #2 INIT_FCALL%s %d %s "strrev"
+ L15 #3 SEND_VAR $baz 1
+ L15 #4 DO_%cCALL @0
+ L15 #5 SEND_VAR @0 1
+ L15 #6 DO_%cCALL
+ L16 #7 RETURN null
+prompt> [User Class: Foo\Bar (2 methods)]
+L5-7 Foo\Bar::Foo() %s - %s + 5 ops
+ L5 #0 RECV 1 $bar
+ L6 #1 INIT_NS_FCALL_BY_NAME "Foo\\var_dump"
+ L6 #2 SEND_VAR_EX $bar 1
+ L6 #3 DO_FCALL
+ L7 #4 RETURN null
+L9-9 Foo\Bar::baz() %s - %s + 1 ops
+ L9 #0 RETURN null
+prompt> [Not Executing!]
+prompt> [Context %s (11 ops)]
+L1-21 {main}() %s - %s + 11 ops
+ L4 #0 NOP
+ L14 #1 NOP
+ L18 #2 NEW "Foo\\Bar" @1
+ L18 #3 DO_FCALL
+ L18 #4 INIT_METHOD_CALL @1 "Foo"
+ L18 #5 SEND_VAL_EX "test" 1
+ L18 #6 DO_FCALL
+ L19 #7 INIT_FCALL%s %d %s "foo"
+ L19 #8 SEND_VAL "test" 1
+ L19 #9 DO_FCALL
+ L21 #10 RETURN 1
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+
+ function baz() { }
+ }
+}
+
+namespace {
+ function foo($baz) {
+ var_dump(strrev($baz));
+ }
+
+ (new \Foo\Bar)->Foo("test");
+ foo("test");
+}
diff --git a/sapi/phpdbg/tests/print_002.phpt b/sapi/phpdbg/tests/print_002.phpt
new file mode 100644
index 0000000000..3a824986c1
--- /dev/null
+++ b/sapi/phpdbg/tests/print_002.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Relative print commands
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b foo
+r
+p
+p o
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at foo]
+prompt> string(4) "test"
+[Breakpoint #0 in foo() at %s:15, hits: 1]
+>00015: var_dump(strrev($baz));
+ 00016: }
+ 00017:
+prompt> [Stack in foo() (8 ops)]
+L14-16 foo() %s - %s + 8 ops
+ L14 #0 RECV 1 $baz
+ L15 #1 INIT_FCALL%s %d %s "var_dump"
+ L15 #2 INIT_FCALL%s %d %s "strrev"
+ L15 #3 SEND_VAR $baz 1
+ L15 #4 DO_%cCALL @0
+ L15 #5 SEND_VAR @0 1
+ L15 #6 DO_%cCALL
+ L16 #7 RETURN null
+prompt> [L15 %s INIT_FCALL%s %d %s "var_dump" %s]
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+
+ function baz() { }
+ }
+}
+
+namespace {
+ function foo($baz) {
+ var_dump(strrev($baz));
+ }
+
+ (new \Foo\Bar)->Foo("test");
+ foo("test");
+}
diff --git a/sapi/phpdbg/tests/run-tests.php b/sapi/phpdbg/tests/run-tests.php
deleted file mode 100644
index 1cc31d815e..0000000000
--- a/sapi/phpdbg/tests/run-tests.php
+++ /dev/null
@@ -1,597 +0,0 @@
-<?php
-namespace phpdbg\testing {
-
- /*
- * Workaround ...
- */
- if (!defined('DIR_SEP'))
- define('DIR_SEP', '\\' . DIRECTORY_SEPARATOR);
-
- /**
- * TestConfigurationExceptions are thrown
- * when the configuration prohibits tests executing
- *
- * @package phpdbg
- * @subpackage testing
- */
- class TestConfigurationException extends \Exception {
-
- /**
- *
- * @param array Tests confguration
- * @param message Exception message
- * @param ... formatting parameters
- */
- public function __construct() {
- $argv = func_get_args();
-
- if (count($argv)) {
-
- $this->config = array_shift($argv);
- $this->message = vsprintf(
- array_shift($argv), $argv);
- }
- }
- }
-
- /**
- *
- * @package phpdbg
- * @subpackage testing
- */
- class TestsConfiguration implements \ArrayAccess {
-
- /**
- *
- * @param array basic configuration
- * @param array argv
- */
- public function __construct($config, $cmd) {
- $this->options = $config;
- while (($key = array_shift($cmd))) {
- switch (substr($key, 0, 1)) {
- case '-': switch(substr($key, 1, 1)) {
- case '-': {
- $arg = substr($key, 2);
- if (($e=strpos($arg, '=')) !== false) {
- $key = substr($arg, 0, $e);
- $value = substr($arg, $e+1);
- } else {
- $key = $arg;
- $value = array_shift($cmd);
- }
-
- if (isset($key) && isset($value)) {
- switch ($key) {
- case 'phpdbg':
- case 'width':
- $this->options[$key] = $value;
- break;
-
- default: {
- if (isset($config[$key])) {
- if (is_array($config[$key])) {
- $this->options[$key][] = $value;
- } else {
- $this->options[$key] = array($config[$key], $value);
- }
- } else {
- $this->options[$key] = $value;
- }
- }
- }
-
- }
- } break;
-
- default:
- $this->flags[] = substr($key, 1);
- } break;
- }
- }
-
- if (!is_executable($this->options['phpdbg'])) {
- throw new TestConfigurationException(
- $this->options, 'phpdbg could not be found at the specified path (%s)', $this->options['phpdbg']);
- } else $this->options['phpdbg'] = realpath($this->options['phpdbg']);
-
- $this->options['width'] = (integer) $this->options['width'];
-
- /* display properly, all the time */
- if ($this->options['width'] < 50) {
- $this->options['width'] = 50;
- }
-
- /* calculate column widths */
- $this->options['lwidth'] = ceil($this->options['width'] / 3);
- $this->options['rwidth'] = ceil($this->options['width'] - $this->options['lwidth']) - 5;
- }
-
- public function hasFlag($flag) {
- return in_array(
- $flag, $this->flags);
- }
-
- public function offsetExists($offset) { return isset($this->options[$offset]); }
- public function offsetGet($offset) { return $this->options[$offset]; }
- public function offsetUnset($offset) { unset($this->options[$offset]); }
- public function offsetSet($offset, $data) { $this->options[$offset] = $data; }
-
- protected $options = array();
- protected $flags = array();
- }
-
- /**
- * Tests is the console programming API for the test suite
- *
- * @package phpdbg
- * @subpackage testing
- */
- class Tests {
-
- /**
- * Construct the console object
- *
- * @param array basic configuration
- * @param array command line
- */
- public function __construct(TestsConfiguration $config) {
- $this->config = $config;
-
- if ($this->config->hasFlag('help') ||
- $this->config->hasFlag('h')) {
- $this->showUsage();
- exit;
- }
- }
-
- /**
- * Find valid paths as specified by configuration
- *
- */
- public function findPaths($in = null) {
- $paths = array();
- $where = ($in != null) ? array($in) : $this->config['path'];
-
- foreach ($where as $path) {
- if ($path) {
- if (is_dir($path)) {
- $paths[] = $path;
- foreach (scandir($path) as $child) {
- if ($child != '.' && $child != '..') {
- $paths = array_merge(
- $paths, $this->findPaths("$path/$child"));
- }
- }
- }
- }
- }
-
- return $paths;
- }
-
- /**
- *
- * @param string the path to log
- */
- public function logPath($path) {
- printf(
- '%s [%s]%s',
- str_repeat(
- '-', $this->config['width'] - strlen($path)),
- $path, PHP_EOL);
- }
-
- /**
- *
- * @param string the path to log
- */
- public function logPathStats($path) {
- if (!isset($this->stats[$path])) {
- return;
- }
-
- $total = array_sum($this->stats[$path]);
-
- if ($total) {
- @$this->totals[true] += $this->stats[$path][true];
- @$this->totals[false] += $this->stats[$path][false];
-
- $stats = @sprintf(
- "%d/%d %%%d",
- $this->stats[$path][true],
- $this->stats[$path][false],
- (100 / $total) * $this->stats[$path][true]);
-
- printf(
- '%s [%s]%s',
- str_repeat(
- ' ', $this->config['width'] - strlen($stats)),
- $stats, PHP_EOL);
-
- printf("%s%s", str_repeat('-', $this->config['width']+3), PHP_EOL);
- printf("%s", PHP_EOL);
- }
- }
-
- /**
- *
- */
- public function logStats() {
- $total = array_sum($this->totals);
- $stats = @sprintf(
- "%d/%d %%%d",
- $this->totals[true],
- $this->totals[false],
- (100 / $total) * $this->totals[true]);
- printf(
- '%s [%s]%s',
- str_repeat(
- ' ', $this->config['width'] - strlen($stats)),
- $stats, PHP_EOL);
-
- }
-
- /**
- *
- */
- protected function showUsage() {
- printf('usage: php %s [flags] [options]%s', $this->config['exec'], PHP_EOL);
- printf('[options]:%s', PHP_EOL);
- printf("\t--path\t\tadd a path to scan outside of tests directory%s", PHP_EOL);
- printf("\t--width\t\tset line width%s", PHP_EOL);
- printf("\t--options\toptions to pass to phpdbg%s", PHP_EOL);
- printf("\t--phpdbg\tpath to phpdbg binary%s", PHP_EOL);
- printf('[flags]:%s', PHP_EOL);
- printf("\t-diff2stdout\t\twrite diff to stdout instead of files%s", PHP_EOL);
- printf("\t-nodiff\t\tdo not write diffs on failure%s", PHP_EOL);
- printf("\t-nolog\t\tdo not write logs on failure%s", PHP_EOL);
- printf('[examples]:%s', PHP_EOL);
- printf("\tphp %s --phpdbg=/usr/local/bin/phpdbg --path=/usr/src/phpdbg/tests --options -n%s",
- $this->config['exec'], PHP_EOL);
-
- }
-
- /**
- * Find valid tests at the specified path (assumed valid)
- *
- * @param string a valid path
- */
- public function findTests($path) {
- $tests = array();
-
- foreach (scandir($path) as $file) {
- if ($file == '.' || $file == '..')
- continue;
-
- $test = sprintf('%s/%s', $path, $file);
-
- if (preg_match('~\.test$~', $test)) {
- $tests[] = new Test($this->config, $test);
- }
- }
-
- return $tests;
- }
-
- /**
- *
- * @param Test the test to log
- */
- public function logTest($path, Test $test) {
- @$this->stats[$path][($result=$test->getResult())]++;
-
- printf(
- "%-{$this->config['lwidth']}s %-{$this->config['rwidth']}s [%s]%s",
- $test->name,
- $test->purpose,
- $result ? "PASS" : "FAIL",
- PHP_EOL);
-
- return $result;
- }
-
- protected $config;
- }
-
- class Test {
- /*
- * Expect exact line for line match
- */
- const EXACT = 0x00000001;
-
- /*
- * Expect strpos() !== false
- */
- const STRING = 0x00000010;
-
- /*
- * Expect stripos() !== false
- */
- const CISTRING = 0x00000100;
-
- /*
- * Formatted output
- */
- const FORMAT = 0x00001000;
-
- /**
- * Format specifiers
- */
- private static $format = array(
- 'search' => array(
- '%e',
- '%s',
- '%S',
- '%a',
- '%A',
- '%w',
- '%i',
- '%d',
- '%x',
- '%f',
- '%c',
- '%t',
- '%T'
- ),
- 'replace' => array(
- DIR_SEP,
- '[^\r\n]+',
- '[^\r\n]*',
- '.+',
- '.*',
- '\s*',
- '[+-]?\d+',
- '\d+',
- '[0-9a-fA-F]+',
- '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?',
- '.',
- '\t',
- '\t+'
- )
- );
-
- /**
- * Constructs a new Test object given a specilized phpdbginit file
- *
- * @param array configuration
- * @param string file
- */
- public function __construct(TestsConfiguration $config, $file) {
- if (($handle = fopen($file, 'r'))) {
- while (($line = fgets($handle))) {
- $trim = trim($line);
-
- switch (substr($trim, 0, 1)) {
- case '#': if (($chunks = array_map('trim', preg_split('~:~', substr($trim, 1), 2)))) {
- if (property_exists($this, $chunks[0])) {
- switch ($chunks[0]) {
- case 'expect': {
- if ($chunks[1]) {
- switch (strtoupper($chunks[1])) {
- case 'TEST::EXACT':
- case 'EXACT': { $this->expect = TEST::EXACT; } break;
-
- case 'TEST::STRING':
- case 'STRING': { $this->expect = TEST::STRING; } break;
-
- case 'TEST::CISTRING':
- case 'CISTRING': { $this->expect = TEST::CISTRING; } break;
-
- case 'TEST::FORMAT':
- case 'FORMAT': { $this->expect = TEST::FORMAT; } break;
-
- default:
- throw new TestConfigurationException(
- $this->config, "unknown type of expectation (%s)", $chunks[1]);
- }
- }
- } break;
-
- default: {
- $this->$chunks[0] = $chunks[1];
- }
- }
- } else switch(substr($trim, 1, 1)) {
- case '#': { /* do nothing */ } break;
-
- default: {
- $line = preg_replace(
- "~(\r\n)~", "\n", substr($trim, 1));
-
- $line = trim($line);
-
- switch ($this->expect) {
- case TEST::FORMAT:
- $this->match[] = str_replace(
- self::$format['search'],
- self::$format['replace'], preg_quote($line));
- break;
-
- default: $this->match[] = $line;
- }
- }
- }
- } break;
-
- default:
- break 2;
- }
- }
- fclose($handle);
-
- $this->config = $config;
- $this->file = $file;
- }
- }
-
- /**
- * Obvious!!
- *
- */
- public function getResult() {
- $options = sprintf('-i%s -nqb', $this->file);
-
- if ($this->options) {
- $options = sprintf(
- '%s %s %s',
- $options,
- $this->config['options'],
- $this->options
- );
- } else {
- $options = sprintf(
- '%s %s', $options, $this->config['options']
- );
- }
-
- $result = `{$this->config['phpdbg']} {$options}`;
-
- if ($result) {
- foreach (preg_split('~(\r|\n)~', $result) as $num => $line) {
- if (!$line && !isset($this->match[$num]))
- continue;
-
- switch ($this->expect) {
- case TEST::EXACT: {
- if (strcmp($line, $this->match[$num]) !== 0) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
-
- case TEST::STRING: {
- if (strpos($line, $this->match[$num]) === false) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
-
- case TEST::CISTRING: {
- if (stripos($line, $this->match[$num]) === false) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
-
- case TEST::FORMAT: {
- $line = trim($line);
- if (!preg_match("/^{$this->match[$num]}\$/s", $line)) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
- }
- }
- }
-
- $this->writeLog($result);
- $this->writeDiff();
-
- return (count($this->diff) == 0);
- }
-
- /**
- * Write diff to disk if configuration allows it
- *
- */
- protected function writeDiff() {
- if (count($this->diff['wants'])) {
- if (!$this->config->hasFlag('nodiff')) {
- if ($this->config->hasFlag('diff2stdout')) {
- $difffile = "php://stdout";
- file_put_contents($difffile, "====DIFF====\n");
- } else {
- $difffile = sprintf(
- '%s/%s.diff',
- dirname($this->file), basename($this->file));
- }
-
- if (($diff = fopen($difffile, 'w+'))) {
-
- foreach ($this->diff['wants'] as $line => $want) {
- $got = $this->diff['gets'][$line];
-
- fprintf(
- $diff, '(%d) -%s%s', $line+1, $want, PHP_EOL);
- fprintf(
- $diff, '(%d) +%s%s', $line+1, $got, PHP_EOL);
- }
-
- fclose($diff);
- }
- }
- } else unlink($diff);
- }
-
- /**
- * Write log to disk if configuration allows it
- *
- */
- protected function writeLog($result = null) {
- $log = sprintf(
- '%s/%s.log',
- dirname($this->file), basename($this->file));
-
- if (count($this->diff) && $result) {
- if (!in_array('nolog', $this->config['flags'])) {
- @file_put_contents(
- $log, $result);
- }
- } else unlink($log);
- }
-
- public $name;
- public $purpose;
- public $file;
- public $options;
- public $expect;
-
- protected $match;
- protected $diff;
- protected $stats;
- protected $totals;
- }
-}
-
-namespace {
- use \phpdbg\Testing\Test;
- use \phpdbg\Testing\Tests;
- use \phpdbg\Testing\TestsConfiguration;
-
- $cwd = dirname(__FILE__);
- $cmd = $_SERVER['argv'];
-
- $retval = 0;
-
- {
- $config = new TestsConfiguration(array(
- 'exec' => realpath(array_shift($cmd)),
- 'phpdbg' => realpath(sprintf(
- '%s/../phpdbg', $cwd
- )),
- 'path' => array(
- realpath(dirname(__FILE__))
- ),
- 'flags' => array(),
- 'width' => 75
- ), $cmd);
-
- $tests = new Tests($config);
-
- foreach ($tests->findPaths() as $path) {
- $tests->logPath($path);
-
- foreach ($tests->findTests($path) as $test) {
- $retval |= !$tests->logTest($path, $test);
- }
-
- $tests->logPathStats($path);
- }
-
- $tests->logStats();
- }
-
- die($retval);
-}
-?>
diff --git a/sapi/phpdbg/tests/run_001.phpt b/sapi/phpdbg/tests/run_001.phpt
new file mode 100644
index 0000000000..30aab1f17a
--- /dev/null
+++ b/sapi/phpdbg/tests/run_001.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Test argv passing
+--PHPDBG--
+r
+r 1 2 3
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> int(5)
+array(5) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(2) "--"
+ [2]=>
+ string(1) "1"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ string(1) "3"
+}
+[Script ended normally]
+prompt> int(5)
+array(4) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(1) "1"
+ [2]=>
+ string(1) "2"
+ [3]=>
+ string(1) "3"
+}
+[Script ended normally]
+prompt> int(5)
+array(5) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(2) "--"
+ [2]=>
+ string(1) "1"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ string(1) "3"
+}
+[Script ended normally]
+prompt>
+--ARGS--
+1 2 3
+--FILE--
+<?php
+
+var_dump($argc, $argv);
diff --git a/sapi/phpdbg/tests/run_002.phpt b/sapi/phpdbg/tests/run_002.phpt
new file mode 100644
index 0000000000..02f6889d6d
--- /dev/null
+++ b/sapi/phpdbg/tests/run_002.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Stdin and escaped args being passed to run command
+--CLEAN--
+<?php
+@unlink("run_002_tmp.fixture");
+?>
+--PHPDBG--
+ev file_put_contents("run_002_tmp.fixture", "stdin\ndata")
+b 6
+r <run_002_tmp.fixture
+r arg1 '_ \' arg2 "' < run_002_tmp.fixture
+y
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> 10
+prompt> [Breakpoint #0 added at %s:6]
+prompt> array(1) {
+ [0]=>
+ string(%d) "%s"
+}
+string(10) "stdin
+data"
+[Breakpoint #0 at %s:6, hits: 1]
+>00006: echo "ok\n";
+ 00007:
+prompt> Do you really want to restart execution? (type y or n): array(3) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(4) "arg1"
+ [2]=>
+ string(10) "_ ' arg2 ""
+}
+string(10) "stdin
+data"
+[Breakpoint #0 at %s:6, hits: 1]
+>00006: echo "ok\n";
+ 00007:
+prompt> ok
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+var_dump($argv);
+var_dump(stream_get_contents(STDIN));
+
+echo "ok\n";
diff --git a/sapi/phpdbg/tests/set_exception_handler.phpt b/sapi/phpdbg/tests/set_exception_handler.phpt
new file mode 100644
index 0000000000..7d4d4faca0
--- /dev/null
+++ b/sapi/phpdbg/tests/set_exception_handler.phpt
@@ -0,0 +1,19 @@
+--TEST--
+set_exception_handler() in phpdbg
+--PHPDBG--
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Uncaught Exception in %s on line 4: test]
+>00004: throw new Exception("test");
+ 00005:
+prompt> EX
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+set_exception_handler(function () { print "EX\n"; });
+throw new Exception("test");
diff --git a/sapi/phpdbg/tests/stdin_001.phpt b/sapi/phpdbg/tests/stdin_001.phpt
new file mode 100644
index 0000000000..0bc940caef
--- /dev/null
+++ b/sapi/phpdbg/tests/stdin_001.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test stdin input with breakpoints
+--PHPDBG--
+stdin foo
+<?php
+
+echo "Hello, world!\n";
+foo
+b 3
+r
+c
+r
+q
+--EXPECTF--
+prompt> [Successful compilation of stdin input]
+prompt> [Breakpoint #0 added at -:3]
+prompt> [Breakpoint #0 at -:3, hits: 1]
+>00003: echo "Hello, world!\n";
+ 00004:
+prompt> Hello, world!
+[Script ended normally]
+prompt> [Breakpoint #0 at -:3, hits: 1]
+>00003: echo "Hello, world!\n";
+ 00004:
+prompt> \ No newline at end of file
diff --git a/sapi/phpdbg/tests/stepping_001.phpt b/sapi/phpdbg/tests/stepping_001.phpt
new file mode 100644
index 0000000000..9c3429897b
--- /dev/null
+++ b/sapi/phpdbg/tests/stepping_001.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Stepping with exceptions must not be stuck at CATCH
+--PHPDBG--
+b ZEND_THROW
+r
+s
+
+
+
+
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at ZEND_THROW]
+prompt> [Breakpoint #0 in ZEND_THROW at %s:4, hits: 1]
+>00004: throw new Exception;
+ 00005: }
+ 00006:
+prompt> [L0 %s HANDLE_EXCEPTION %s]
+>00004: throw new Exception;
+ 00005: }
+ 00006:
+prompt> [L0 %s HANDLE_EXCEPTION %s]
+[L9 %s CATCH "Exception" $e 1 %s]
+>00008: foo();
+ 00009: } catch (Exception $e) {
+ 00010: echo "ok";
+prompt> [L10 %s ECHO "ok" %s]
+>00010: echo "ok";
+ 00011: } finally {
+ 00012: echo " ... ok";
+prompt> ok
+[L11 %s FAST_CALL J8 ~%d %s]
+>00011: } finally {
+ 00012: echo " ... ok";
+ 00013: }
+prompt> [L12 %s ECHO " ... ok" %s]
+>00012: echo " ... ok";
+ 00013: }
+ 00014:
+prompt> ... ok
+[L12 %s FAST_RET ~%d %s]
+[L11 %s JMP J10 %s]
+>00011: } finally {
+ 00012: echo " ... ok";
+ 00013: }
+prompt> [L14 %s RETURN 1 %s]
+>00014:
+prompt>
+--FILE--
+<?php
+
+function foo() {
+ throw new Exception;
+}
+
+try {
+ foo();
+} catch (Exception $e) {
+ echo "ok";
+} finally {
+ echo " ... ok";
+}
diff --git a/sapi/phpdbg/tests/watch_001.phpt b/sapi/phpdbg/tests/watch_001.phpt
new file mode 100644
index 0000000000..ea7da1a87d
--- /dev/null
+++ b/sapi/phpdbg/tests/watch_001.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Test simple recursive watchpoint
+--PHPDBG--
+b 3
+r
+w r $b
+c
+
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:3]
+prompt> [Breakpoint #0 at %s:3, hits: 1]
+>00003: $a = 1;
+ 00004: $b = [$a];
+ 00005:
+prompt> [Set recursive watchpoint on $b]
+prompt> [Breaking on watchpoint $b]
+Old value:
+New value: Array ([0] => 1)
+>00006: unset($b);
+ 00007: $b = 2;
+ 00008:
+prompt> [Breaking on watchpoint $b]
+Old value inaccessible or destroyed
+New value:
+>00007: $b = 2;
+ 00008:
+prompt> [Breaking on watchpoint $b]
+Old value:
+New value: 2
+>00008:
+prompt> [$b was removed, removing watchpoint recursively]
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+$a = 1;
+$b = [$a];
+
+unset($b);
+$b = 2;