. namespace Tests\Unit; if (!defined('INSTALLDIR')) { define('INSTALLDIR', dirname(dirname(__DIR__))); } if (!defined('GNUSOCIAL')) { define('GNUSOCIAL', true); } use PHPUnit\Framework\TestCase; require_once INSTALLDIR . "/lib/callableleftcurry.php"; final class CallableLeftCurryTest extends TestCase { /** * @dataProvider provider * @param $callback_test * @param $curry_params * @param $call_params * @param $expected */ public function testCallableLeftCurry($callback_test, $curry_params, $call_params, $expected) { $params = array_merge([$callback_test], $curry_params); $curried = call_user_func_array('callableLeftCurry', $params); $result = call_user_func_array($curried, $call_params); $this->assertEquals($expected, $result); } static public function provider() { $obj = new CurryTestHelperObj('oldval'); return [[['Tests\Unit\CallableLeftCurryTest', 'callback_test'], ['curried'], ['called'], 'called|curried'], [['Tests\Unit\CallableLeftCurryTest', 'callback_test'], ['curried1', 'curried2'], ['called1', 'called2'], 'called1|called2|curried1|curried2'], [['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'], [$obj], ['newval1'], 'oldval|newval1'], // Confirm object identity is retained... [['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'], [$obj], ['newval2'], 'newval1|newval2']]; } static function callback_test() { $args = func_get_args(); return implode("|", $args); } static function callback_testObj($val, $obj) { $old = $obj->val; $obj->val = $val; return "$old|$val"; } } class CurryTestHelperObj { public $val = ''; function __construct($val) { $this->val = $val; } }