]> granicus.if.org Git - php/commitdiff
- MFH: New tests
authorFelipe Pena <felipe@php.net>
Mon, 28 Jul 2008 14:10:00 +0000 (14:10 +0000)
committerFelipe Pena <felipe@php.net>
Mon, 28 Jul 2008 14:10:00 +0000 (14:10 +0000)
12 files changed:
Zend/tests/036.phpt [new file with mode: 0644]
Zend/tests/037.phpt [new file with mode: 0644]
Zend/tests/038.phpt [new file with mode: 0644]
Zend/tests/closure_024.phpt [new file with mode: 0644]
Zend/tests/closure_025.phpt [new file with mode: 0644]
Zend/tests/closure_026.phpt [new file with mode: 0644]
Zend/tests/closure_027.phpt [new file with mode: 0644]
Zend/tests/closure_028.phpt [new file with mode: 0644]
Zend/tests/closure_029.phpt [new file with mode: 0644]
Zend/tests/closure_030.phpt [new file with mode: 0644]
Zend/tests/list_007.phpt [new file with mode: 0644]
Zend/tests/objects_031.phpt [new file with mode: 0644]

diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt
new file mode 100644 (file)
index 0000000..6feb23f
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Trying to use lambda in array offset
+--FILE--
+<?php
+
+$test[function(){}] = 1;
+$a{function() { }} = 1;
+
+?>
+--EXPECTF--
+Warning: Illegal offset type in %s on line %d
+
+Warning: Illegal offset type in %s on line %d
diff --git a/Zend/tests/037.phpt b/Zend/tests/037.phpt
new file mode 100644 (file)
index 0000000..d7057b4
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Trying to access inexistent static property of Closure
+--FILE--
+<?php
+
+namespace closure;
+
+class closure { static $x = 1;}
+
+$x = __NAMESPACE__;
+var_dump(closure::$x);
+
+var_dump($x::$x);
+
+?>
+--EXPECTF--
+int(1)
+
+Fatal error: Access to undeclared static property: Closure::$x in %s on line %d
diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt
new file mode 100644 (file)
index 0000000..963e73f
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Trying to use lambda as array key
+--FILE--
+<?php
+
+var_dump(array(function() { } => 1));
+
+?>
+--EXPECTF--
+Warning: Illegal offset type in %s on line %d
+array(0) {
+}
diff --git a/Zend/tests/closure_024.phpt b/Zend/tests/closure_024.phpt
new file mode 100644 (file)
index 0000000..504e81e
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Closure 024: Trying to clone the Closure object
+--FILE--
+<?php
+
+$a = function () { 
+       return clone function () {
+               return 1;
+       };
+};
+
+$a();
+
+?>
+--EXPECTF--
+Fatal error: Trying to clone an uncloneable object of class Closure in %s on line %d
diff --git a/Zend/tests/closure_025.phpt b/Zend/tests/closure_025.phpt
new file mode 100644 (file)
index 0000000..8ee187e
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Closure 025: Using closure in create_function()
+--FILE--
+<?php
+
+$a = create_function('$x', 'return function($y) use ($x) { return $x * $y; };');
+
+var_dump($a(2)->__invoke(4));
+
+?>
+--EXPECT--
+int(8)
diff --git a/Zend/tests/closure_026.phpt b/Zend/tests/closure_026.phpt
new file mode 100644 (file)
index 0000000..f9e6bd5
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Closure 026: Assigning a closure object to an array in $this
+--FILE--
+<?php
+
+class foo {
+       public function __construct() {
+               $a =& $this;
+               
+               $a->a[] = function() {
+                       return 1;       
+               };
+               
+               var_dump($this);
+               
+               var_dump($this->a[0]());
+       }
+}
+
+$x = new foo;
+
+print "--------------\n";
+
+foreach ($x as $b => $c) {
+       var_dump($b, $c);
+       var_dump($c[0]());
+}
+
+?>
+--EXPECTF--
+object(foo)#%d (1) {
+  ["a"]=>
+  array(1) {
+    [0]=>
+    object(Closure)#%d (0) {
+    }
+  }
+}
+int(1)
+--------------
+string(1) "a"
+array(1) {
+  [0]=>
+  object(Closure)#%d (0) {
+  }
+}
+int(1)
diff --git a/Zend/tests/closure_027.phpt b/Zend/tests/closure_027.phpt
new file mode 100644 (file)
index 0000000..7787f72
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Closure 027: Testing Closure type-hint
+--FILE--
+<?php
+
+function test(closure $a) {
+       var_dump($a());
+}
+
+
+test(function() { return new stdclass; });
+
+test(function() { });
+
+$a = function($x) use ($y) {};
+test($a);
+
+test(new stdclass);
+
+?>
+--EXPECTF--
+object(stdClass)#%d (0) {
+}
+NULL
+
+Notice: Undefined variable: y in %s on line %d
+
+Warning: Missing argument 1 for (), called in %s on line %d and defined in %s on line %d
+NULL
+
+Catchable fatal error: Argument 1 passed to test() must be an instance of Closure, instance of stdClass given, called in %s on line %d and defined in %s on line %d
diff --git a/Zend/tests/closure_028.phpt b/Zend/tests/closure_028.phpt
new file mode 100644 (file)
index 0000000..3584075
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Closure 028: Trying to use lambda directly in foreach
+--FILE--
+<?php
+
+foreach (function(){ return 1; } as $y) { 
+       var_dump($y);   
+}
+
+print "ok\n";
+
+?>
+--EXPECT--
+ok
diff --git a/Zend/tests/closure_029.phpt b/Zend/tests/closure_029.phpt
new file mode 100644 (file)
index 0000000..8d909c0
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Closure 029: Testing lambda with instanceof operator
+--FILE--
+<?php
+
+var_dump(function() { } instanceof closure);
+var_dump(function(&$x) { } instanceof closure);
+var_dump(@function(&$x) use ($y, $z) { } instanceof closure);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/closure_030.phpt b/Zend/tests/closure_030.phpt
new file mode 100644 (file)
index 0000000..318d215
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Closure 030: Using lambda with variable variables
+--FILE--
+<?php
+
+$b = function() { return func_get_args(); };
+$a = 'b';
+var_dump($$a(1));
+var_dump($$a->__invoke(2));
+
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  int(1)
+}
+array(1) {
+  [0]=>
+  int(2)
+}
diff --git a/Zend/tests/list_007.phpt b/Zend/tests/list_007.phpt
new file mode 100644 (file)
index 0000000..35a25bc
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Using lambda with list()
+--FILE--
+<?php
+
+list($x, $y) = function() { };
+
+var_dump($x, $y);
+
+?>
+--EXPECT--
+NULL
+NULL
diff --git a/Zend/tests/objects_031.phpt b/Zend/tests/objects_031.phpt
new file mode 100644 (file)
index 0000000..0bf2182
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Cloning stdClass
+--FILE--
+<?php
+
+$x[] = clone new stdclass;
+$x[] = clone new stdclass;
+$x[] = clone new stdclass;
+
+$x[0]->a = 1;
+
+var_dump($x);
+
+?>
+--EXPECTF--
+array(3) {
+  [0]=>
+  object(stdClass)#%d (1) {
+    ["a"]=>
+    int(1)
+  }
+  [1]=>
+  object(stdClass)#%d (0) {
+  }
+  [2]=>
+  object(stdClass)#%d (0) {
+  }
+}