From 0158f4f73db1c6090c09da8cc3cdcfb97af3883b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 15 Dec 2009 13:53:19 -0800 Subject: PHP 5.3 closure-based implementation of curry(); old implementation used as fallback for older PHP versions. Added unit tests to confirm they both work! --- tests/CurryTest.php | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/CurryTest.php (limited to 'tests') diff --git a/tests/CurryTest.php b/tests/CurryTest.php new file mode 100644 index 000000000..37b66cc74 --- /dev/null +++ b/tests/CurryTest.php @@ -0,0 +1,72 @@ +assertEquals($expected, $result); + } + + static public function provider() + { + $obj = new CurryTestHelperObj('oldval'); + return array(array(array('CurryTest', 'callback'), + array('curried'), + array('called'), + 'called|curried'), + array(array('CurryTest', 'callback'), + array('curried1', 'curried2'), + array('called1', 'called2'), + 'called1|called2|curried1|curried2'), + array(array('CurryTest', 'callbackObj'), + array($obj), + array('newval1'), + 'oldval|newval1'), + // Confirm object identity is retained... + array(array('CurryTest', 'callbackObj'), + array($obj), + array('newval2'), + 'newval1|newval2')); + } + + static function callback() + { + $args = func_get_args(); + return implode("|", $args); + } + + static function callbackObj($val, $obj) + { + $old = $obj->val; + $obj->val = $val; + return "$old|$val"; + } +} + +class CurryTestHelperObj +{ + public $val=''; + + function __construct($val) + { + $this->val = $val; + } +} -- cgit v1.2.3-54-g00ecf