Refactoring
This commit is contained in:
384
lib/composer/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/MethodProphecySpec.php
vendored
Normal file
384
lib/composer/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/MethodProphecySpec.php
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Prophecy;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class ClassWithFinalMethod
|
||||
{
|
||||
final public function finalMethod() {}
|
||||
}
|
||||
|
||||
class MethodProphecySpec extends ObjectBehavior
|
||||
{
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\ObjectProphecy $objectProphecy
|
||||
* @param \ReflectionClass $reflection
|
||||
*/
|
||||
function let($objectProphecy, $reflection)
|
||||
{
|
||||
$objectProphecy->reveal()->willReturn($reflection);
|
||||
|
||||
$this->beConstructedWith($objectProphecy, 'getName', null);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Prophecy\Prophecy\MethodProphecy');
|
||||
}
|
||||
|
||||
function its_constructor_throws_MethodNotFoundException_for_unexisting_method($objectProphecy)
|
||||
{
|
||||
$this->shouldThrow('Prophecy\Exception\Doubler\MethodNotFoundException')->during(
|
||||
'__construct', array($objectProphecy, 'getUnexisting', null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassWithFinalMethod $subject
|
||||
*/
|
||||
function its_constructor_throws_MethodProphecyException_for_final_methods($objectProphecy, $subject)
|
||||
{
|
||||
$objectProphecy->reveal()->willReturn($subject);
|
||||
|
||||
$this->shouldThrow('Prophecy\Exception\Prophecy\MethodProphecyException')->during(
|
||||
'__construct', array($objectProphecy, 'finalMethod', null)
|
||||
);
|
||||
}
|
||||
|
||||
function its_constructor_transforms_array_passed_as_3rd_argument_to_ArgumentsWildcard(
|
||||
$objectProphecy
|
||||
)
|
||||
{
|
||||
$this->beConstructedWith($objectProphecy, 'getName', array(42, 33));
|
||||
|
||||
$wildcard = $this->getArgumentsWildcard();
|
||||
$wildcard->shouldNotBe(null);
|
||||
$wildcard->__toString()->shouldReturn('exact(42), exact(33)');
|
||||
}
|
||||
|
||||
function its_constructor_does_not_touch_third_argument_if_it_is_null($objectProphecy)
|
||||
{
|
||||
$this->beConstructedWith($objectProphecy, 'getName', null);
|
||||
|
||||
$wildcard = $this->getArgumentsWildcard();
|
||||
$wildcard->shouldBe(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Promise\PromiseInterface $promise
|
||||
*/
|
||||
function it_records_promise_through_will_method($promise, $objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->will($promise);
|
||||
$this->getPromise()->shouldReturn($promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Promise\PromiseInterface $promise
|
||||
*/
|
||||
function it_adds_itself_to_ObjectProphecy_during_call_to_will($objectProphecy, $promise)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->shouldBeCalled();
|
||||
|
||||
$this->will($promise);
|
||||
}
|
||||
|
||||
function it_adds_ReturnPromise_during_willReturn_call($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->willReturn(42);
|
||||
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\ReturnPromise');
|
||||
}
|
||||
|
||||
function it_adds_ThrowPromise_during_willThrow_call($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->willThrow('RuntimeException');
|
||||
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\ThrowPromise');
|
||||
}
|
||||
|
||||
function it_adds_ReturnArgumentPromise_during_willReturnArgument_call($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->willReturnArgument();
|
||||
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\ReturnArgumentPromise');
|
||||
}
|
||||
|
||||
function it_adds_ReturnArgumentPromise_during_willReturnArgument_call_with_index_argument($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->willReturnArgument(1);
|
||||
$promise = $this->getPromise();
|
||||
$promise->shouldBeAnInstanceOf('Prophecy\Promise\ReturnArgumentPromise');
|
||||
$promise->execute(array('one', 'two'), $objectProphecy, $this)->shouldReturn('two');
|
||||
}
|
||||
|
||||
function it_adds_CallbackPromise_during_will_call_with_callback_argument($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$callback = function () {};
|
||||
|
||||
$this->will($callback);
|
||||
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\CallbackPromise');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
*/
|
||||
function it_records_prediction_through_should_method($prediction, $objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->callOnWrappedObject('should', array($prediction));
|
||||
$this->getPrediction()->shouldReturn($prediction);
|
||||
}
|
||||
|
||||
function it_adds_CallbackPrediction_during_should_call_with_callback_argument($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$callback = function () {};
|
||||
|
||||
$this->callOnWrappedObject('should', array($callback));
|
||||
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\CallbackPrediction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
*/
|
||||
function it_adds_itself_to_ObjectProphecy_during_call_to_should($objectProphecy, $prediction)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->shouldBeCalled();
|
||||
|
||||
$this->callOnWrappedObject('should', array($prediction));
|
||||
}
|
||||
|
||||
function it_adds_CallPrediction_during_shouldBeCalled_call($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->callOnWrappedObject('shouldBeCalled', array());
|
||||
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\CallPrediction');
|
||||
}
|
||||
|
||||
function it_adds_NoCallsPrediction_during_shouldNotBeCalled_call($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->callOnWrappedObject('shouldNotBeCalled', array());
|
||||
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\NoCallsPrediction');
|
||||
}
|
||||
|
||||
function it_adds_CallTimesPrediction_during_shouldBeCalledTimes_call($objectProphecy)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->callOnWrappedObject('shouldBeCalledTimes', array(5));
|
||||
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\CallTimesPrediction');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
*/
|
||||
function it_checks_prediction_via_shouldHave_method_call(
|
||||
$objectProphecy, $arguments, $prediction, $call1, $call2
|
||||
)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
|
||||
$this->withArguments($arguments);
|
||||
$this->callOnWrappedObject('shouldHave', array($prediction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
*/
|
||||
function it_sets_return_promise_during_shouldHave_call_if_none_was_set_before(
|
||||
$objectProphecy, $arguments, $prediction, $call1, $call2
|
||||
)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
|
||||
$this->withArguments($arguments);
|
||||
$this->callOnWrappedObject('shouldHave', array($prediction));
|
||||
|
||||
$this->getPromise()->shouldReturnAnInstanceOf('Prophecy\Promise\ReturnPromise');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
* @param \Prophecy\Promise\PromiseInterface $promise
|
||||
*/
|
||||
function it_does_not_set_return_promise_during_shouldHave_call_if_it_was_set_before(
|
||||
$objectProphecy, $arguments, $prediction, $call1, $call2, $promise
|
||||
)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
|
||||
$this->will($promise);
|
||||
$this->withArguments($arguments);
|
||||
$this->callOnWrappedObject('shouldHave', array($prediction));
|
||||
|
||||
$this->getPromise()->shouldReturn($promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction1
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction2
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
* @param \Prophecy\Promise\PromiseInterface $promise
|
||||
*/
|
||||
function it_records_checked_predictions(
|
||||
$objectProphecy, $arguments, $prediction1, $prediction2, $call1, $call2, $promise
|
||||
)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
$prediction1->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->willReturn();
|
||||
$prediction2->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->willReturn();
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
|
||||
$this->will($promise);
|
||||
$this->withArguments($arguments);
|
||||
$this->callOnWrappedObject('shouldHave', array($prediction1));
|
||||
$this->callOnWrappedObject('shouldHave', array($prediction2));
|
||||
|
||||
$this->getCheckedPredictions()->shouldReturn(array($prediction1, $prediction2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
* @param \Prophecy\Promise\PromiseInterface $promise
|
||||
*/
|
||||
function it_records_even_failed_checked_predictions(
|
||||
$objectProphecy, $arguments, $prediction, $call1, $call2, $promise
|
||||
)
|
||||
{
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->willThrow(new \RuntimeException());
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
|
||||
$this->will($promise);
|
||||
$this->withArguments($arguments);
|
||||
|
||||
try {
|
||||
$this->callOnWrappedObject('shouldHave', array($prediction));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
$this->getCheckedPredictions()->shouldReturn(array($prediction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
*/
|
||||
function it_checks_prediction_via_shouldHave_method_call_with_callback(
|
||||
$objectProphecy, $arguments, $prediction, $call1, $call2
|
||||
)
|
||||
{
|
||||
$callback = function ($calls, $object, $method) {
|
||||
throw new \RuntimeException;
|
||||
};
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
|
||||
$this->withArguments($arguments);
|
||||
$this->shouldThrow('RuntimeException')->duringShouldHave($callback);
|
||||
}
|
||||
|
||||
function it_does_nothing_during_checkPrediction_if_no_prediction_set()
|
||||
{
|
||||
$this->checkPrediction()->shouldReturn(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
* @param \Prophecy\Prediction\PredictionInterface $prediction
|
||||
* @param \Prophecy\Call\Call $call1
|
||||
* @param \Prophecy\Call\Call $call2
|
||||
*/
|
||||
function it_checks_set_prediction_during_checkPrediction(
|
||||
$objectProphecy, $arguments, $prediction, $call1, $call2
|
||||
)
|
||||
{
|
||||
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
|
||||
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
|
||||
$objectProphecy->addMethodProphecy($this)->willReturn(null);
|
||||
|
||||
$this->withArguments($arguments);
|
||||
$this->callOnWrappedObject('should', array($prediction));
|
||||
$this->checkPrediction();
|
||||
}
|
||||
|
||||
function it_links_back_to_ObjectProphecy_through_getter($objectProphecy)
|
||||
{
|
||||
$this->getObjectProphecy()->shouldReturn($objectProphecy);
|
||||
}
|
||||
|
||||
function it_has_MethodName()
|
||||
{
|
||||
$this->getMethodName()->shouldReturn('getName');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $wildcard
|
||||
*/
|
||||
function it_contains_ArgumentsWildcard_it_was_constructed_with($objectProphecy, $wildcard)
|
||||
{
|
||||
$this->beConstructedWith($objectProphecy, 'getName', $wildcard);
|
||||
|
||||
$this->getArgumentsWildcard()->shouldReturn($wildcard);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $wildcard
|
||||
*/
|
||||
function its_ArgumentWildcard_is_mutable_through_setter($wildcard)
|
||||
{
|
||||
$this->withArguments($wildcard);
|
||||
|
||||
$this->getArgumentsWildcard()->shouldReturn($wildcard);
|
||||
}
|
||||
|
||||
function its_withArguments_transforms_passed_array_into_ArgumentsWildcard()
|
||||
{
|
||||
$this->withArguments(array(42, 33));
|
||||
|
||||
$wildcard = $this->getArgumentsWildcard();
|
||||
$wildcard->shouldNotBe(null);
|
||||
$wildcard->__toString()->shouldReturn('exact(42), exact(33)');
|
||||
}
|
||||
|
||||
function its_withArguments_throws_exception_if_wrong_arguments_provided()
|
||||
{
|
||||
$this->shouldThrow('Prophecy\Exception\InvalidArgumentException')->duringWithArguments(42);
|
||||
}
|
||||
}
|
||||
319
lib/composer/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/ObjectProphecySpec.php
vendored
Normal file
319
lib/composer/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/ObjectProphecySpec.php
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Prophecy;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ObjectProphecySpec extends ObjectBehavior
|
||||
{
|
||||
/**
|
||||
* @param \Prophecy\Doubler\LazyDouble $lazyDouble
|
||||
* @param \Prophecy\Prophecy\ProphecySubjectInterface $double
|
||||
*/
|
||||
function let($lazyDouble, $double)
|
||||
{
|
||||
$this->beConstructedWith($lazyDouble);
|
||||
|
||||
$lazyDouble->getInstance()->willReturn($double);
|
||||
}
|
||||
|
||||
function it_implements_ProphecyInterface()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Prophecy\ProphecyInterface');
|
||||
}
|
||||
|
||||
function it_sets_parentClass_during_willExtend_call($lazyDouble)
|
||||
{
|
||||
$lazyDouble->setParentClass('123')->shouldBeCalled();
|
||||
|
||||
$this->willExtend('123');
|
||||
}
|
||||
|
||||
function it_adds_interface_during_willImplement_call($lazyDouble)
|
||||
{
|
||||
$lazyDouble->addInterface('222')->shouldBeCalled();
|
||||
|
||||
$this->willImplement('222');
|
||||
}
|
||||
|
||||
function it_sets_constructor_arguments_during_willBeConstructedWith_call($lazyDouble)
|
||||
{
|
||||
$lazyDouble->setArguments(array(1, 2, 5))->shouldBeCalled();
|
||||
|
||||
$this->willBeConstructedWith(array(1, 2, 5));
|
||||
}
|
||||
|
||||
function it_does_not_have_method_prophecies_by_default()
|
||||
{
|
||||
$this->getMethodProphecies()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $method1
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $method2
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
|
||||
*/
|
||||
function it_should_get_method_prophecies_by_method_name($method1, $method2, $arguments)
|
||||
{
|
||||
$method1->getMethodName()->willReturn('getName');
|
||||
$method1->getArgumentsWildcard()->willReturn($arguments);
|
||||
$method2->getMethodName()->willReturn('setName');
|
||||
$method2->getArgumentsWildcard()->willReturn($arguments);
|
||||
|
||||
$this->addMethodProphecy($method1);
|
||||
$this->addMethodProphecy($method2);
|
||||
|
||||
$methods = $this->getMethodProphecies('setName');
|
||||
$methods->shouldHaveCount(1);
|
||||
$methods[0]->getMethodName()->shouldReturn('setName');
|
||||
}
|
||||
|
||||
function it_should_return_empty_array_if_no_method_prophecies_found()
|
||||
{
|
||||
$methods = $this->getMethodProphecies('setName');
|
||||
$methods->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Call\CallCenter $callCenter
|
||||
*/
|
||||
function it_should_proxy_makeProphecyMethodCall_to_CallCenter($lazyDouble, $callCenter)
|
||||
{
|
||||
$this->beConstructedWith($lazyDouble, $callCenter);
|
||||
|
||||
$callCenter->makeCall($this->getWrappedObject(), 'setName', array('everzet'))->willReturn(42);
|
||||
|
||||
$this->makeProphecyMethodCall('setName', array('everzet'))->shouldReturn(42);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Call\CallCenter $callCenter
|
||||
* @param \Prophecy\Prophecy\RevealerInterface $revealer
|
||||
*/
|
||||
function it_should_reveal_arguments_and_return_values_from_callCenter(
|
||||
$lazyDouble, $callCenter, $revealer
|
||||
)
|
||||
{
|
||||
$this->beConstructedWith($lazyDouble, $callCenter, $revealer);
|
||||
|
||||
$revealer->reveal(array('question'))->willReturn(array('life'));
|
||||
$revealer->reveal('answer')->willReturn(42);
|
||||
|
||||
$callCenter->makeCall($this->getWrappedObject(), 'setName', array('life'))->willReturn('answer');
|
||||
|
||||
$this->makeProphecyMethodCall('setName', array('question'))->shouldReturn(42);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Call\CallCenter $callCenter
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $wildcard
|
||||
* @param \Prophecy\Call\Call $call
|
||||
*/
|
||||
function it_should_proxy_getProphecyMethodCalls_to_CallCenter(
|
||||
$lazyDouble, $callCenter, $wildcard, $call
|
||||
)
|
||||
{
|
||||
$this->beConstructedWith($lazyDouble, $callCenter);
|
||||
|
||||
$callCenter->findCalls('setName', $wildcard)->willReturn(array($call));
|
||||
|
||||
$this->findProphecyMethodCalls('setName', $wildcard)->shouldReturn(array($call));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard
|
||||
*/
|
||||
function its_addMethodProphecy_adds_method_prophecy(
|
||||
$methodProphecy, $argumentsWildcard
|
||||
)
|
||||
{
|
||||
$methodProphecy->getArgumentsWildcard()->willReturn($argumentsWildcard);
|
||||
$methodProphecy->getMethodName()->willReturn('getUsername');
|
||||
|
||||
$this->addMethodProphecy($methodProphecy);
|
||||
|
||||
$this->getMethodProphecies()->shouldReturn(array(
|
||||
'getUsername' => array($methodProphecy)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy1
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy2
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard1
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard2
|
||||
*/
|
||||
function its_addMethodProphecy_handles_prophecies_with_different_arguments(
|
||||
$methodProphecy1, $methodProphecy2, $argumentsWildcard1, $argumentsWildcard2
|
||||
)
|
||||
{
|
||||
$methodProphecy1->getArgumentsWildcard()->willReturn($argumentsWildcard1);
|
||||
$methodProphecy1->getMethodName()->willReturn('getUsername');
|
||||
|
||||
$methodProphecy2->getArgumentsWildcard()->willReturn($argumentsWildcard2);
|
||||
$methodProphecy2->getMethodName()->willReturn('getUsername');
|
||||
|
||||
$this->addMethodProphecy($methodProphecy1);
|
||||
$this->addMethodProphecy($methodProphecy2);
|
||||
|
||||
$this->getMethodProphecies()->shouldReturn(array(
|
||||
'getUsername' => array(
|
||||
$methodProphecy1,
|
||||
$methodProphecy2,
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy1
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy2
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard1
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard2
|
||||
*/
|
||||
function its_addMethodProphecy_handles_prophecies_for_different_methods(
|
||||
$methodProphecy1, $methodProphecy2, $argumentsWildcard1, $argumentsWildcard2
|
||||
)
|
||||
{
|
||||
$methodProphecy1->getArgumentsWildcard()->willReturn($argumentsWildcard1);
|
||||
$methodProphecy1->getMethodName()->willReturn('getUsername');
|
||||
|
||||
$methodProphecy2->getArgumentsWildcard()->willReturn($argumentsWildcard2);
|
||||
$methodProphecy2->getMethodName()->willReturn('isUsername');
|
||||
|
||||
$this->addMethodProphecy($methodProphecy1);
|
||||
$this->addMethodProphecy($methodProphecy2);
|
||||
|
||||
$this->getMethodProphecies()->shouldReturn(array(
|
||||
'getUsername' => array(
|
||||
$methodProphecy1
|
||||
),
|
||||
'isUsername' => array(
|
||||
$methodProphecy2
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy
|
||||
*/
|
||||
function its_addMethodProphecy_throws_exception_when_method_has_no_ArgumentsWildcard(
|
||||
$methodProphecy
|
||||
)
|
||||
{
|
||||
$methodProphecy->getArgumentsWildcard()->willReturn(null);
|
||||
$methodProphecy->getObjectProphecy()->willReturn($this);
|
||||
$methodProphecy->getMethodName()->willReturn('getTitle');
|
||||
|
||||
$this->shouldThrow('Prophecy\Exception\Prophecy\MethodProphecyException')->duringAddMethodProphecy(
|
||||
$methodProphecy
|
||||
);
|
||||
}
|
||||
|
||||
function it_returns_null_after_checkPredictions_call_if_there_is_no_method_prophecies()
|
||||
{
|
||||
$this->checkProphecyMethodsPredictions()->shouldReturn(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy1
|
||||
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy2
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard1
|
||||
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard2
|
||||
*/
|
||||
function it_throws_AggregateException_during_checkPredictions_if_predictions_fail(
|
||||
$methodProphecy1, $methodProphecy2, $argumentsWildcard1, $argumentsWildcard2
|
||||
)
|
||||
{
|
||||
$methodProphecy1->getMethodName()->willReturn('getName');
|
||||
$methodProphecy1->getArgumentsWildcard()->willReturn($argumentsWildcard1);
|
||||
$methodProphecy1->checkPrediction()
|
||||
->willThrow('Prophecy\Exception\Prediction\AggregateException');
|
||||
|
||||
$methodProphecy2->getMethodName()->willReturn('setName');
|
||||
$methodProphecy2->getArgumentsWildcard()->willReturn($argumentsWildcard2);
|
||||
$methodProphecy2->checkPrediction()
|
||||
->willThrow('Prophecy\Exception\Prediction\AggregateException');
|
||||
|
||||
$this->addMethodProphecy($methodProphecy1);
|
||||
$this->addMethodProphecy($methodProphecy2);
|
||||
|
||||
$this->shouldThrow('Prophecy\Exception\Prediction\AggregateException')
|
||||
->duringCheckProphecyMethodsPredictions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Doubler\Doubler $doubler
|
||||
* @param \Prophecy\Prophecy\ProphecySubjectInterface $reflection
|
||||
*/
|
||||
function it_returns_new_MethodProphecy_instance_for_arbitrary_call($doubler, $reflection)
|
||||
{
|
||||
$doubler->double(Argument::any())->willReturn($reflection);
|
||||
|
||||
$return = $this->getProphecy();
|
||||
$return->shouldBeAnInstanceOf('Prophecy\Prophecy\MethodProphecy');
|
||||
$return->getMethodName()->shouldReturn('getProphecy');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Doubler\Doubler $doubler
|
||||
* @param \Prophecy\Prophecy\ProphecySubjectInterface $reflection
|
||||
*/
|
||||
function it_returns_same_MethodProphecy_for_same_registered_signature($doubler, $reflection)
|
||||
{
|
||||
$doubler->double(Argument::any())->willReturn($reflection);
|
||||
|
||||
$this->addMethodProphecy($methodProphecy1 = $this->getProphecy(1, 2, 3));
|
||||
$methodProphecy2 = $this->getProphecy(1, 2, 3);
|
||||
|
||||
$methodProphecy2->shouldBe($methodProphecy1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Doubler\Doubler $doubler
|
||||
* @param \Prophecy\Prophecy\ProphecySubjectInterface $reflection
|
||||
*/
|
||||
function it_returns_new_MethodProphecy_for_different_signatures($doubler, $reflection)
|
||||
{
|
||||
$doubler->double(Argument::any())->willReturn($reflection);
|
||||
|
||||
$value = new ObjectProphecySpecFixtureB('ABC');
|
||||
$value2 = new ObjectProphecySpecFixtureB('CBA');
|
||||
|
||||
$this->addMethodProphecy($methodProphecy1 = $this->getProphecy(1, 2, 3, $value));
|
||||
$methodProphecy2 = $this->getProphecy(1, 2, 3, $value2);
|
||||
|
||||
$methodProphecy2->shouldNotBe($methodProphecy1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Doubler\Doubler $doubler
|
||||
* @param \Prophecy\Prophecy\ProphecySubjectInterface $reflection
|
||||
*/
|
||||
function it_returns_new_MethodProphecy_for_all_callback_signatures($doubler, $reflection)
|
||||
{
|
||||
$doubler->double(Argument::any())->willReturn($reflection);
|
||||
|
||||
$this->addMethodProphecy($methodProphecy1 = $this->getProphecy(function(){}));
|
||||
$methodProphecy2 = $this->getProphecy(function(){});
|
||||
|
||||
$methodProphecy2->shouldNotBe($methodProphecy1);
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectProphecySpecFixtureA
|
||||
{
|
||||
public $errors;
|
||||
}
|
||||
|
||||
class ObjectProphecySpecFixtureB extends ObjectProphecySpecFixtureA
|
||||
{
|
||||
public $errors;
|
||||
public $value = null;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
51
lib/composer/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/RevealerSpec.php
vendored
Normal file
51
lib/composer/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/RevealerSpec.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Prophecy;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class RevealerSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_revealer()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Prophecy\RevealerInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\ProphecyInterface $prophecy
|
||||
* @param \stdClass $object
|
||||
*/
|
||||
function it_reveals_single_instance_of_ProphecyInterface($prophecy, $object)
|
||||
{
|
||||
$prophecy->reveal()->willReturn($object);
|
||||
|
||||
$this->reveal($prophecy)->shouldReturn($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Prophecy\ProphecyInterface $prophecy1
|
||||
* @param \Prophecy\Prophecy\ProphecyInterface $prophecy2
|
||||
* @param \stdClass $object1
|
||||
* @param \stdClass $object2
|
||||
*/
|
||||
function it_reveals_instances_of_ProphecyInterface_inside_array(
|
||||
$prophecy1, $prophecy2, $object1, $object2
|
||||
)
|
||||
{
|
||||
$prophecy1->reveal()->willReturn($object1);
|
||||
$prophecy2->reveal()->willReturn($object2);
|
||||
|
||||
$this->reveal(array(
|
||||
array('item' => $prophecy2),
|
||||
$prophecy1
|
||||
))->shouldReturn(array(
|
||||
array('item' => $object2),
|
||||
$object1
|
||||
));
|
||||
}
|
||||
|
||||
function it_does_not_touch_non_prophecy_interface()
|
||||
{
|
||||
$this->reveal(42)->shouldReturn(42);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user