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