cvs: ZendEngine2 /tests closure_017.phpt closure_018.phpt closure_019.phpt closure_020.phpt closure_021.phpt

"Felipe Pena" <[email protected]>
Newsgroups gmane.comp.php.cvs.zend
Message-ID <cvsfelipe1216042772@cvsserver>
felipe		Mon Jul 14 13:39:32 2008 UTC

  Modified files:              
    /ZendEngine2/tests	closure_017.phpt closure_018.phpt 
                      	closure_019.phpt closure_020.phpt 
                      	closure_021.phpt 
  Log:
  - New tests
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_017.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_017.phpt
diff -u /dev/null ZendEngine2/tests/closure_017.phpt:1.2
--- /dev/null	Mon Jul 14 13:39:32 2008
+++ ZendEngine2/tests/closure_017.phpt	Mon Jul 14 13:39:32 2008
@@ -0,0 +1,12 @@
+--TEST--
+Closure 017: Trying to destroy an active lambda function
+--FILE--
+<?php
+
+$a = function(&$a) { $a = 1; };
+
+$a($a);
+
+?>
+--EXPECTF--
+Fatal error: Cannot destroy active lambda function in %s on line %d
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_018.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_018.phpt
diff -u /dev/null ZendEngine2/tests/closure_018.phpt:1.2
--- /dev/null	Mon Jul 14 13:39:32 2008
+++ ZendEngine2/tests/closure_018.phpt	Mon Jul 14 13:39:32 2008
@@ -0,0 +1,28 @@
+--TEST--
+Closure 018: Assigning lambda to static var and returning by ref
+--FILE--
+<?php
+
+class foo {
+	public function test(&$x) {
+		static $lambda;
+		$lambda = function &() use (&$x) { 
+			return $x = $x * $x;
+		};
+		return $lambda();
+	}
+}
+
+$test = new foo;
+
+$y = 2;
+var_dump($test->test($y));
+var_dump($x = $test->test($y));
+var_dump($y, $x);
+
+?>
+--EXPECT--
+int(4)
+int(16)
+int(16)
+int(16)
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_019.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_019.phpt
diff -u /dev/null ZendEngine2/tests/closure_019.phpt:1.2
--- /dev/null	Mon Jul 14 13:39:32 2008
+++ ZendEngine2/tests/closure_019.phpt	Mon Jul 14 13:39:32 2008
@@ -0,0 +1,26 @@
+--TEST--
+Closure 019: Calling lambda using $GLOBALS and global $var
+--FILE--
+<?php
+
+$lambda = function &(&$x) {
+	return $x = $x * $x;
+};
+
+function test() {
+	global $lambda;
+	
+	$y = 3;
+	var_dump($GLOBALS['lambda']($y));
+	var_dump($lambda($y));
+	var_dump($GLOBALS['lambda'](1));
+}
+
+test();
+
+?>
+--EXPECTF--
+int(9)
+int(81)
+
+Fatal error: Cannot pass parameter 1 by reference in %s on line %d
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_020.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_020.phpt
diff -u /dev/null ZendEngine2/tests/closure_020.phpt:1.2
--- /dev/null	Mon Jul 14 13:39:32 2008
+++ ZendEngine2/tests/closure_020.phpt	Mon Jul 14 13:39:32 2008
@@ -0,0 +1,36 @@
+--TEST--
+Closure 020: Trying to access private property outside class
+--FILE--
+<?php
+
+class foo {
+	private $test = 3;
+	
+	public function x() {
+		$a = &$this;
+		$this->a = function() use (&$a) { return $a; };
+		var_dump($this->a->__invoke());
+		var_dump(is_a($this->a, 'closure'));
+		var_dump(is_callable($this->a));
+		
+		return $this->a;
+	}
+}
+
+$foo = new foo;
+$y = $foo->x();
+var_dump($y()->test);
+
+?>
+--EXPECTF--
+object(foo)#%d (%d) {
+  [u"test":u"foo":private]=>
+  int(3)
+  [u"a"]=>
+  object(Closure)#%d (0) {
+  }
+}
+bool(true)
+bool(true)
+
+Fatal error: Cannot access private property foo::$test in %s on line %d
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_021.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_021.phpt
diff -u /dev/null ZendEngine2/tests/closure_021.phpt:1.2
--- /dev/null	Mon Jul 14 13:39:32 2008
+++ ZendEngine2/tests/closure_021.phpt	Mon Jul 14 13:39:32 2008
@@ -0,0 +1,22 @@
+--TEST--
+Closure 021: Throwing exception inside lambda
+--FILE--
+<?php
+
+$foo = function() {
+	try {
+		throw new Exception('test!');
+	} catch(Exception $e) {
+		throw $e;
+	}
+};
+
+try {
+	$foo();
+} catch (Exception $e) {
+	var_dump($e->getMessage());
+}
+
+?>
+--EXPECT--
+unicode(5) "test!"



-- 
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.