]> granicus.if.org Git - php/commitdiff
- MFH: New tests
authorFelipe Pena <felipe@php.net>
Sun, 11 May 2008 03:50:28 +0000 (03:50 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 11 May 2008 03:50:28 +0000 (03:50 +0000)
26 files changed:
Zend/tests/031.phpt [new file with mode: 0644]
Zend/tests/032.phpt [new file with mode: 0644]
Zend/tests/033.phpt [new file with mode: 0644]
Zend/tests/anonymous_func_001.phpt [new file with mode: 0644]
Zend/tests/anonymous_func_002.phpt [new file with mode: 0644]
Zend/tests/anonymous_func_003.phpt [new file with mode: 0644]
Zend/tests/dynamic_call_001.phpt [new file with mode: 0644]
Zend/tests/dynamic_call_002.phpt [new file with mode: 0644]
Zend/tests/dynamic_call_003.phpt [new file with mode: 0644]
Zend/tests/dynamic_call_004.phpt [new file with mode: 0644]
Zend/tests/exception_001.phpt [new file with mode: 0644]
Zend/tests/exception_002.phpt [new file with mode: 0644]
Zend/tests/exception_003.phpt [new file with mode: 0644]
Zend/tests/heredoc_015.phpt [new file with mode: 0644]
Zend/tests/heredoc_016.phpt [new file with mode: 0644]
Zend/tests/heredoc_017.phpt [new file with mode: 0644]
Zend/tests/instanceof_001.phpt [new file with mode: 0644]
Zend/tests/instanceof_002.phpt [new file with mode: 0644]
Zend/tests/jump14.phpt [new file with mode: 0644]
Zend/tests/list_003.phpt [new file with mode: 0644]
Zend/tests/list_004.phpt [new file with mode: 0644]
Zend/tests/list_005.phpt [new file with mode: 0644]
Zend/tests/nowdoc_016.phpt [new file with mode: 0644]
Zend/tests/nowdoc_017.phpt [new file with mode: 0644]
Zend/tests/objects_022.phpt [new file with mode: 0644]
Zend/tests/objects_023.phpt [new file with mode: 0644]

diff --git a/Zend/tests/031.phpt b/Zend/tests/031.phpt
new file mode 100644 (file)
index 0000000..8db52a5
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Testing array with '[]' passed as argument by value
+--FILE--
+<?php 
+
+function test($var) { }
+test($arr[]);
+
+?>
+--EXPECTF--
+Fatal error: Cannot use [] for reading in %s on line %d
diff --git a/Zend/tests/032.phpt b/Zend/tests/032.phpt
new file mode 100644 (file)
index 0000000..8f7f994
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Testing array with '[]' passed as argument by reference
+--FILE--
+<?php 
+
+function test(&$var) { }
+test($arr[]);
+
+print "ok!\n";
+
+?>
+--EXPECT--
+ok!
diff --git a/Zend/tests/033.phpt b/Zend/tests/033.phpt
new file mode 100644 (file)
index 0000000..c865115
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Using undefined multidimensional array
+--FILE--
+<?php 
+
+$arr[1][2][3][4][5];
+
+echo $arr[1][2][3][4][5];
+
+$arr[1][2][3][4][5]->foo;
+
+$arr[1][2][3][4][5]->foo = 1;
+
+$arr[][] = 2;
+
+$arr[][]->bar = 2;
+
+?>
+--EXPECTF--
+
+Notice: Undefined variable: arr in %s on line %d
+
+Notice: Undefined variable: arr in %s on line %d
+
+Notice: Undefined variable: arr in %s on line %d
+
+Notice: Trying to get property of non-object in %s on line %d
+
+Strict Standards: Creating default object from empty value in %s on line %d
+
+Strict Standards: Creating default object from empty value in %s on line %d
diff --git a/Zend/tests/anonymous_func_001.phpt b/Zend/tests/anonymous_func_001.phpt
new file mode 100644 (file)
index 0000000..644a7f4
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Testing calls to anonymous function
+--FILE--
+<?php 
+
+for ($i = 0; $i < 10; $i++) {
+       $a = create_function('', 'return '. $i .';');
+       var_dump($a());
+       
+       $b = "\0lambda_". ($i + 1);
+       var_dump($b());
+}
+
+?>
+--EXPECT--
+int(0)
+int(0)
+int(1)
+int(1)
+int(2)
+int(2)
+int(3)
+int(3)
+int(4)
+int(4)
+int(5)
+int(5)
+int(6)
+int(6)
+int(7)
+int(7)
+int(8)
+int(8)
+int(9)
+int(9)
diff --git a/Zend/tests/anonymous_func_002.phpt b/Zend/tests/anonymous_func_002.phpt
new file mode 100644 (file)
index 0000000..4c40b62
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Testing anonymous function return as array key and accessing $GLOBALS
+--FILE--
+<?php 
+
+$test = create_function('$v', 'return $v;');
+
+$arr = array(create_function('', 'return $GLOBALS["arr"];'), 2);
+
+var_dump($arr[$test(1)]);
+var_dump($arr[$test(0)]() == $arr);
+
+?>
+--EXPECT--
+int(2)
+bool(true)
diff --git a/Zend/tests/anonymous_func_003.phpt b/Zend/tests/anonymous_func_003.phpt
new file mode 100644 (file)
index 0000000..32c5cf0
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Using throw $var with anonymous function return
+--FILE--
+<?php 
+
+try {
+       $a = create_function('', 'return new Exception("test");');
+       throw $a();
+} catch (Exception $e) {
+       var_dump($e->getMessage() == 'test');
+}
+
+?>
+--EXPECT--
+bool(true)
diff --git a/Zend/tests/dynamic_call_001.phpt b/Zend/tests/dynamic_call_001.phpt
new file mode 100644 (file)
index 0000000..94e4203
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Testing dynamic call to constructor (old-style)
+--FILE--
+<?php 
+
+class foo { 
+       public function foo() {
+       }       
+}
+
+$a = 'foo';
+
+$a::$a();
+
+?>
+--EXPECTF--
+Fatal error: Non-static method foo::foo() cannot be called statically in %s on line %d
diff --git a/Zend/tests/dynamic_call_002.phpt b/Zend/tests/dynamic_call_002.phpt
new file mode 100644 (file)
index 0000000..dcb1529
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Testing dynamic call with invalid value for method name
+--FILE--
+<?php 
+
+$a = new stdClass;
+
+$a::$a();
+
+?>
+--EXPECTF--
+Fatal error: Function name must be a string in %s on line %d
diff --git a/Zend/tests/dynamic_call_003.phpt b/Zend/tests/dynamic_call_003.phpt
new file mode 100644 (file)
index 0000000..15b830e
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Testing dynamic call with invalid method name
+--FILE--
+<?php 
+
+$a = new stdClass;
+$b = 1;
+
+$a::$b();
+
+?>
+--EXPECTF--
+Fatal error: Function name must be a string in %s on line %d
diff --git a/Zend/tests/dynamic_call_004.phpt b/Zend/tests/dynamic_call_004.phpt
new file mode 100644 (file)
index 0000000..6e83303
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Testing dynamic call with undefined variables
+--FILE--
+<?php 
+
+$a::$b();
+
+?>
+--EXPECTF--
+Notice: Undefined variable: a in %s on line %d
+
+Fatal error: Class name must be a valid object or a string in %s on line %d
diff --git a/Zend/tests/exception_001.phpt b/Zend/tests/exception_001.phpt
new file mode 100644 (file)
index 0000000..ab74a92
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Testing nested exceptions
+--FILE--
+<?php
+
+try {
+       try {
+               try {
+                       try {
+                               throw new Exception(NULL);
+                       } catch (Exception $e) {
+                               var_dump($e->getMessage());
+                               throw $e;
+                       }
+               } catch (Exception $e) {
+                       var_dump($e->getMessage());
+                       throw $e;
+               }
+       } catch (Exception $e) {
+               var_dump($e->getMessage());
+               throw $e;
+       }
+} catch (Exception $e) {
+       var_dump($e->getMessage());
+       throw $e;
+}
+
+?>
+--EXPECTF--
+string(0) ""
+string(0) ""
+string(0) ""
+string(0) ""
+
+Fatal error: Uncaught exception 'Exception' in %s:%d
+Stack trace:
+#0 {main}
+  thrown in %s on line %d
diff --git a/Zend/tests/exception_002.phpt b/Zend/tests/exception_002.phpt
new file mode 100644 (file)
index 0000000..25f0c61
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Testing exception and GOTO
+--FILE--
+<?php 
+
+goto foo;
+
+try {
+       print 1;
+       
+       foo:
+       print 2;
+} catch (Exception $e) {
+       
+}
+
+?>
+--EXPECT--
+2
diff --git a/Zend/tests/exception_003.phpt b/Zend/tests/exception_003.phpt
new file mode 100644 (file)
index 0000000..e060aac
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Throwing exception in global scope
+--FILE--
+<?php 
+
+throw new Exception(1);
+
+?>
+--EXPECTF--
+
+Fatal error: Uncaught exception 'Exception' with message '1' in %s:%d
+Stack trace:
+#0 {main}
+  thrown in %s on line %d
diff --git a/Zend/tests/heredoc_015.phpt b/Zend/tests/heredoc_015.phpt
new file mode 100644 (file)
index 0000000..21658cf
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+Testing heredoc with escape sequences
+--FILE--
+<?php 
+
+$test = <<<TEST
+TEST;
+
+var_dump(strlen($test) == 0);
+
+$test = <<<TEST
+\
+TEST;
+
+var_dump(strlen($test) == 1);
+
+$test = <<<TEST
+\0
+TEST;
+
+var_dump(strlen($test) == 1);
+
+$test = <<<TEST
+\n
+TEST;
+
+var_dump(strlen($test) == 1);
+
+$test = <<<TEST
+\\'
+TEST;
+
+var_dump(strlen($test) == 2);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/heredoc_016.phpt b/Zend/tests/heredoc_016.phpt
new file mode 100644 (file)
index 0000000..de00036
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+Testing heredoc (double quotes) with escape sequences
+--FILE--
+<?php 
+
+$test = <<<"TEST"
+TEST;
+
+var_dump(strlen($test) == 0);
+
+$test = <<<"TEST"
+\
+TEST;
+
+var_dump(strlen($test) == 1);
+
+$test = <<<"TEST"
+\0
+TEST;
+
+var_dump(strlen($test) == 1);
+
+$test = <<<"TEST"
+\n
+TEST;
+
+var_dump(strlen($test) == 1);
+
+$test = <<<"TEST"
+\\'
+TEST;
+
+var_dump(strlen($test) == 2);
+
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/heredoc_017.phpt b/Zend/tests/heredoc_017.phpt
new file mode 100644 (file)
index 0000000..e0ffddf
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Testinh heredoc syntax
+--FILE--
+<?php 
+
+$a = <<<A
+       A;
+;
+ A;
+\;
+A;
+
+var_dump(strlen($a) == 12);
+
+?>
+--EXPECT--
+bool(true)
diff --git a/Zend/tests/instanceof_001.phpt b/Zend/tests/instanceof_001.phpt
new file mode 100644 (file)
index 0000000..b88e174
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Testing instanceof operator with several operators
+--FILE--
+<?php 
+
+$a = new stdClass;
+var_dump($a instanceof stdClass);
+
+var_dump(new stdCLass instanceof stdClass);
+
+$b = create_function('', 'return new stdClass;');
+var_dump($b() instanceof stdClass);
+
+$c = array(new stdClass);
+var_dump($c[0] instanceof stdClass);
+
+var_dump(@$inexistent instanceof stdClass);
+
+var_dump("$a" instanceof stdClass);
+
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+
+Catchable fatal error: Object of class stdClass could not be converted to string in %s on line %d
diff --git a/Zend/tests/instanceof_002.phpt b/Zend/tests/instanceof_002.phpt
new file mode 100644 (file)
index 0000000..d3f4a35
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Testing instanceof operator with class and interface inheriteds
+--FILE--
+<?php 
+
+interface ITest {
+}
+
+interface IFoo extends ITest {
+}
+
+class foo extends stdClass implements ITest {
+}
+
+var_dump(new foo instanceof stdClass);
+var_dump(new foo instanceof ITest);
+var_dump(new foo instanceof IFoo);
+
+class bar extends foo implements IFoo {
+}
+
+var_dump(new bar instanceof stdClass);
+var_dump(new bar instanceof ITest);
+var_dump(new bar instanceof IFoo);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/jump14.phpt b/Zend/tests/jump14.phpt
new file mode 100644 (file)
index 0000000..2cc6391
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Testing GOTO inside blocks
+--FILE--
+<?php 
+
+goto A;
+
+{
+       B:
+               goto C; 
+               return;
+}
+
+A:
+       goto B;
+
+
+
+{
+       C:
+       {
+               print "Done!\n";
+       }
+}
+
+?>
+--EXPECT--
+Done!
diff --git a/Zend/tests/list_003.phpt b/Zend/tests/list_003.phpt
new file mode 100644 (file)
index 0000000..4a509f6
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+list() with non-array
+--FILE--
+<?php
+
+list($a) = NULL;
+
+list($b) = 1;
+
+list($c) = 1.;
+
+list($d) = 'foo';
+
+list($e) = print '';
+
+var_dump($a, $b, $c, $d, $e);
+
+?>
+--EXPECT--
+NULL
+NULL
+NULL
+NULL
+NULL
diff --git a/Zend/tests/list_004.phpt b/Zend/tests/list_004.phpt
new file mode 100644 (file)
index 0000000..862a4e4
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+list() with array reference
+--FILE--
+<?php
+
+$arr = array(2, 1);
+$b =& $arr;
+
+list(,$a) = $b;
+
+var_dump($a, $b);
+
+?>
+--EXPECT--
+int(1)
+array(2) {
+  [0]=>
+  int(2)
+  [1]=>
+  int(1)
+}
diff --git a/Zend/tests/list_005.phpt b/Zend/tests/list_005.phpt
new file mode 100644 (file)
index 0000000..4afc353
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Testing list() with several variables
+--FILE--
+<?php
+
+$a = "foo";
+
+list($a, $b, $c) = $a;
+
+var_dump($a, $b, $c);
+
+print "----\n";
+
+$a = 1;
+
+list($a, $b, $c) = $a;
+
+var_dump($a, $b, $c);
+
+print "----\n";
+
+$a = new stdClass;
+
+list($a, $b, $c) = $a;
+
+var_dump($a, $b, $c);
+
+print "----\n";
+
+$a = array(1, 2, 3);
+
+list($a, $b, $c) = $a;
+
+var_dump($a, $b, $c);
+
+?>
+--EXPECTF--
+string(1) "f"
+string(1) "o"
+string(1) "o"
+----
+NULL
+NULL
+NULL
+----
+
+Fatal error: Cannot use object of type stdClass as array in %s on line %d
diff --git a/Zend/tests/nowdoc_016.phpt b/Zend/tests/nowdoc_016.phpt
new file mode 100644 (file)
index 0000000..01eea4e
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+Testing nowdocs with escape sequences
+--FILE--
+<?php 
+
+$test = <<<'TEST'
+TEST;
+
+var_dump(strlen($test));
+
+$test = <<<'TEST'
+\
+TEST;
+
+var_dump(strlen($test));
+
+$test = <<<'TEST'
+\0
+TEST;
+
+var_dump(strlen($test));
+
+$test = <<<'TEST'
+\n
+TEST;
+
+var_dump(strlen($test));
+
+$test = <<<'TEST'
+\\'
+TEST;
+
+var_dump(strlen($test));
+
+?>
+--EXPECT--
+int(0)
+int(1)
+int(2)
+int(2)
+int(3)
diff --git a/Zend/tests/nowdoc_017.phpt b/Zend/tests/nowdoc_017.phpt
new file mode 100644 (file)
index 0000000..5d29a86
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Testing nowdoc in default value for property
+--FILE--
+<?php 
+
+class foo {
+    public $bar = <<<'EOT'
+bar
+EOT;
+}
+
+print "ok!\n";
+
+?>
+--EXPECT--
+ok!
diff --git a/Zend/tests/objects_022.phpt b/Zend/tests/objects_022.phpt
new file mode 100644 (file)
index 0000000..5a80e0a
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Testing 'self', 'parent' as type-hint
+--FILE--
+<?php 
+
+interface iTest { }
+class baz implements iTest {}
+class bar { }
+class foo extends bar {
+    public function testFoo(self $obj) {
+        var_dump($obj);
+    }
+    public function testBar(parent $obj) {
+        var_dump($obj);
+    }
+    public function testBaz(iTest $obj) {
+        var_dump($obj);
+    }
+}
+$foo = new foo;
+$foo->testFoo(new foo);
+$foo->testBar(new bar);
+$foo->testBaz(new baz);
+$foo->testFoo(new stdClass); // Catchable fatal error
+
+?>
+--EXPECTF--
+object(foo)#%d (0) {
+}
+object(bar)#%d (0) {
+}
+object(baz)#%d (0) {
+}
+
+Catchable fatal error: Argument 1 passed to foo::testFoo() must be an instance of foo, instance of stdClass given, called in %s on line %d and defined in %s on line %d
diff --git a/Zend/tests/objects_023.phpt b/Zend/tests/objects_023.phpt
new file mode 100644 (file)
index 0000000..042a20e
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Creating instances dynamically
+--FILE--
+<?php 
+
+$arr = array(new stdClass, 'stdClass');
+
+new $arr[0]();
+new $arr[1]();
+
+print "ok\n";
+
+?>
+--EXPECT--
+ok