CallbackPromiseSpec.php (2646B)
1 <?php 2 3 namespace spec\Prophecy\Promise; 4 5 use PhpSpec\ObjectBehavior; 6 7 class CallbackPromiseSpec extends ObjectBehavior 8 { 9 function let() 10 { 11 $this->beConstructedWith('get_class'); 12 } 13 14 function it_is_promise() 15 { 16 $this->shouldBeAnInstanceOf('Prophecy\Promise\PromiseInterface'); 17 } 18 19 /** 20 * @param \Prophecy\Prophecy\ObjectProphecy $object 21 * @param \Prophecy\Prophecy\MethodProphecy $method 22 */ 23 function it_should_execute_closure_callback($object, $method) 24 { 25 $firstArgumentCallback = function ($args) { 26 return $args[0]; 27 }; 28 29 $this->beConstructedWith($firstArgumentCallback); 30 31 $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one'); 32 } 33 34 /** 35 * @param \Prophecy\Prophecy\ObjectProphecy $object 36 * @param \Prophecy\Prophecy\MethodProphecy $method 37 */ 38 function it_should_execute_static_array_callback($object, $method) 39 { 40 $firstArgumentCallback = array('spec\Prophecy\Promise\ClassCallback', 'staticCallbackMethod'); 41 42 $this->beConstructedWith($firstArgumentCallback); 43 44 $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one'); 45 } 46 47 /** 48 * @param \Prophecy\Prophecy\ObjectProphecy $object 49 * @param \Prophecy\Prophecy\MethodProphecy $method 50 */ 51 function it_should_execute_instance_array_callback($object, $method) 52 { 53 $class = new ClassCallback(); 54 $firstArgumentCallback = array($class, 'callbackMethod'); 55 56 $this->beConstructedWith($firstArgumentCallback); 57 58 $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one'); 59 } 60 61 /** 62 * @param \Prophecy\Prophecy\ObjectProphecy $object 63 * @param \Prophecy\Prophecy\MethodProphecy $method 64 */ 65 function it_should_execute_string_function_callback($object, $method) 66 { 67 $firstArgumentCallback = 'spec\Prophecy\Promise\functionCallbackFirstArgument'; 68 69 $this->beConstructedWith($firstArgumentCallback); 70 71 $this->execute(array('one', 'two'), $object, $method)->shouldReturn('one'); 72 } 73 74 } 75 76 /** 77 * Class used to test callbackpromise 78 * 79 * @param array 80 * @return string 81 */ 82 class ClassCallback 83 { 84 /** 85 * @param array $args 86 */ 87 function callbackMethod($args) 88 { 89 return $args[0]; 90 } 91 92 /** 93 * @param array $args 94 */ 95 static function staticCallbackMethod($args) 96 { 97 return $args[0]; 98 } 99 } 100 101 /** 102 * Callback function used to test callbackpromise 103 * 104 * @param array 105 * @return string 106 */ 107 function functionCallbackFirstArgument($args) 108 { 109 return $args[0]; 110 }