]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/CurryTest.php
Give NoticeListItem its own class
[quix0rs-gnu-social.git] / tests / CurryTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
10 define('LACONICA', true);
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class CurryTest extends PHPUnit_Framework_TestCase
15 {
16     /**
17      * @dataProvider provider
18      *
19      */
20     public function testProduction($callback, $curry_params, $call_params, $expected)
21     {
22         $params = array_merge(array($callback), $curry_params);
23         $curried = call_user_func_array('curry', $params);
24         $result = call_user_func_array($curried, $call_params);
25         $this->assertEquals($expected, $result);
26     }
27
28     static public function provider()
29     {
30         $obj = new CurryTestHelperObj('oldval');
31         return array(array(array('CurryTest', 'callback'),
32                            array('curried'),
33                            array('called'),
34                            'called|curried'),
35                      array(array('CurryTest', 'callback'),
36                            array('curried1', 'curried2'),
37                            array('called1', 'called2'),
38                            'called1|called2|curried1|curried2'),
39                      array(array('CurryTest', 'callbackObj'),
40                            array($obj),
41                            array('newval1'),
42                            'oldval|newval1'),
43                      // Confirm object identity is retained...
44                      array(array('CurryTest', 'callbackObj'),
45                            array($obj),
46                            array('newval2'),
47                            'newval1|newval2'));
48     }
49
50     static function callback()
51     {
52         $args = func_get_args();
53         return implode("|", $args);
54     }
55
56     static function callbackObj($val, $obj)
57     {
58         $old = $obj->val;
59         $obj->val = $val;
60         return "$old|$val";
61     }
62 }
63
64 class CurryTestHelperObj
65 {
66     public $val='';
67
68     function __construct($val)
69     {
70         $this->val = $val;
71     }
72 }