123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- 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/util/callableleftcurry.php';
- final class CallableLeftCurryTest extends TestCase
- {
-
- 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);
- static::assertSame($expected, $result);
- }
- public static 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',],
-
- [['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
- [$obj],
- ['newval2'],
- 'newval1|newval2',],];
- }
- public static function callback_test()
- {
- $args = func_get_args();
- return implode('|', $args);
- }
- public static function callback_testObj($val, $obj)
- {
- $old = $obj->val;
- $obj->val = $val;
- return "{$old}|{$val}";
- }
- }
- class CurryTestHelperObj
- {
- public $val = '';
- public function __construct($val)
- {
- $this->val = $val;
- }
- }
|