CurryTest.php 2.1 KB

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