Drupal investigation

CallbackPromiseSpec.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace spec\Prophecy\Promise;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Prophecy\MethodProphecy;
  5. use Prophecy\Prophecy\ObjectProphecy;
  6. class CallbackPromiseSpec extends ObjectBehavior
  7. {
  8. function let()
  9. {
  10. $this->beConstructedWith('get_class');
  11. }
  12. function it_is_promise()
  13. {
  14. $this->shouldBeAnInstanceOf('Prophecy\Promise\PromiseInterface');
  15. }
  16. function it_should_execute_closure_callback(ObjectProphecy $object, MethodProphecy $method)
  17. {
  18. $firstArgumentCallback = function ($args) {
  19. return $args[0];
  20. };
  21. $this->beConstructedWith($firstArgumentCallback);
  22. $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one');
  23. }
  24. function it_should_execute_static_array_callback(ObjectProphecy $object, MethodProphecy $method)
  25. {
  26. $firstArgumentCallback = array('spec\Prophecy\Promise\ClassCallback', 'staticCallbackMethod');
  27. $this->beConstructedWith($firstArgumentCallback);
  28. $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one');
  29. }
  30. function it_should_execute_instance_array_callback(ObjectProphecy $object, MethodProphecy $method)
  31. {
  32. $class = new ClassCallback();
  33. $firstArgumentCallback = array($class, 'callbackMethod');
  34. $this->beConstructedWith($firstArgumentCallback);
  35. $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one');
  36. }
  37. function it_should_execute_string_function_callback(ObjectProphecy $object, MethodProphecy $method)
  38. {
  39. $firstArgumentCallback = 'spec\Prophecy\Promise\functionCallbackFirstArgument';
  40. $this->beConstructedWith($firstArgumentCallback);
  41. $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one');
  42. }
  43. }
  44. /**
  45. * Class used to test callbackpromise
  46. *
  47. * @param array
  48. * @return string
  49. */
  50. class ClassCallback
  51. {
  52. /**
  53. * @param array $args
  54. */
  55. function callbackMethod($args)
  56. {
  57. return $args[0];
  58. }
  59. /**
  60. * @param array $args
  61. */
  62. static function staticCallbackMethod($args)
  63. {
  64. return $args[0];
  65. }
  66. }
  67. /**
  68. * Callback function used to test callbackpromise
  69. *
  70. * @param array
  71. * @return string
  72. */
  73. function functionCallbackFirstArgument($args)
  74. {
  75. return $args[0];
  76. }