Вход Регистрация
Файл: gapps/vendor/phpspec/prophecy/spec/Prophecy/Prophecy/MethodProphecySpec.php
Строк: 450
<?php

namespace specProphecyProphecy;

use 
PhpSpecObjectBehavior;
use 
ProphecyArgumentArgumentsWildcard;
use 
ProphecyCallCall;
use 
ProphecyPredictionPredictionInterface;
use 
ProphecyPromisePromiseInterface;
use 
ProphecyProphecyObjectProphecy;

class 
ClassWithFinalMethod
{
    final public function 
finalMethod() {}
}

class 
MethodProphecySpec extends ObjectBehavior
{
    function 
let(ObjectProphecy $objectProphecyReflectionClass $reflection)
    {
        
$objectProphecy->reveal()->willReturn($reflection);

        
$this->beConstructedWith($objectProphecy'getName'null);
    }

    function 
it_is_initializable()
    {
        
$this->shouldHaveType('ProphecyProphecyMethodProphecy');
    }

    function 
its_constructor_throws_MethodNotFoundException_for_unexisting_method($objectProphecy)
    {
        
$this->shouldThrow('ProphecyExceptionDoublerMethodNotFoundException')->during(
            
'__construct', array($objectProphecy'getUnexisting'null)
        );
    }

    function 
its_constructor_throws_MethodProphecyException_for_final_methods($objectProphecyClassWithFinalMethod $subject)
    {
        
$objectProphecy->reveal()->willReturn($subject);

        
$this->shouldThrow('ProphecyExceptionProphecyMethodProphecyException')->during(
            
'__construct', array($objectProphecy'finalMethod'null)
        );
    }

    function 
its_constructor_transforms_array_passed_as_3rd_argument_to_ArgumentsWildcard(
        
$objectProphecy
    
)
    {
        
$this->beConstructedWith($objectProphecy'getName', array(4233));

        
$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);
    }

    function 
it_records_promise_through_will_method(PromiseInterface $promise$objectProphecy)
    {
        
$objectProphecy->addMethodProphecy($this)->willReturn(null);

        
$this->will($promise);
        
$this->getPromise()->shouldReturn($promise);
    }

    function 
it_adds_itself_to_ObjectProphecy_during_call_to_will(PromiseInterface $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('ProphecyPromiseReturnPromise');
    }

    function 
it_adds_ThrowPromise_during_willThrow_call($objectProphecy)
    {
        
$objectProphecy->addMethodProphecy($this)->willReturn(null);

        
$this->willThrow('RuntimeException');
        
$this->getPromise()->shouldBeAnInstanceOf('ProphecyPromiseThrowPromise');
    }

    function 
it_adds_ReturnArgumentPromise_during_willReturnArgument_call($objectProphecy)
    {
        
$objectProphecy->addMethodProphecy($this)->willReturn(null);

        
$this->willReturnArgument();
        
$this->getPromise()->shouldBeAnInstanceOf('ProphecyPromiseReturnArgumentPromise');
    }

    function 
it_adds_ReturnArgumentPromise_during_willReturnArgument_call_with_index_argument($objectProphecy)
    {
        
$objectProphecy->addMethodProphecy($this)->willReturn(null);

        
$this->willReturnArgument(1);
        
$promise $this->getPromise();
        
$promise->shouldBeAnInstanceOf('ProphecyPromiseReturnArgumentPromise');
        
$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('ProphecyPromiseCallbackPromise');
    }

    function 
it_records_prediction_through_should_method(PredictionInterface $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('ProphecyPredictionCallbackPrediction');
    }

    function 
it_adds_itself_to_ObjectProphecy_during_call_to_should($objectProphecyPredictionInterface $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('ProphecyPredictionCallPrediction');
    }

    function 
it_adds_NoCallsPrediction_during_shouldNotBeCalled_call($objectProphecy)
    {
        
$objectProphecy->addMethodProphecy($this)->willReturn(null);

        
$this->callOnWrappedObject('shouldNotBeCalled', array());
        
$this->getPrediction()->shouldBeAnInstanceOf('ProphecyPredictionNoCallsPrediction');
    }

    function 
it_adds_CallTimesPrediction_during_shouldBeCalledTimes_call($objectProphecy)
    {
        
$objectProphecy->addMethodProphecy($this)->willReturn(null);

        
$this->callOnWrappedObject('shouldBeCalledTimes', array(5));
        
$this->getPrediction()->shouldBeAnInstanceOf('ProphecyPredictionCallTimesPrediction');
    }

    function 
it_checks_prediction_via_shouldHave_method_call(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
PredictionInterface $prediction,
        
Call $call1,
        
Call $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));
    }

    function 
it_sets_return_promise_during_shouldHave_call_if_none_was_set_before(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
PredictionInterface $prediction,
        
Call $call1,
        
Call $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('ProphecyPromiseReturnPromise');
    }

    function 
it_does_not_set_return_promise_during_shouldHave_call_if_it_was_set_before(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
PredictionInterface $prediction,
        
Call $call1,
        
Call $call2,
        
PromiseInterface $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);
    }

    function 
it_records_checked_predictions(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
PredictionInterface $prediction1,
        
PredictionInterface $prediction2,
        
Call $call1,
        
Call $call2,
        
PromiseInterface $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));
    }

    function 
it_records_even_failed_checked_predictions(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
PredictionInterface $prediction,
        
Call $call1,
        
Call $call2,
        
PromiseInterface $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));
    }

    function 
it_checks_prediction_via_shouldHave_method_call_with_callback(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
Call $call1,
        
Call $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);
    }

    function 
it_checks_set_prediction_during_checkPrediction(
        
$objectProphecy,
        
ArgumentsWildcard $arguments,
        
PredictionInterface $prediction,
        
Call $call1,
        
Call $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');
    }

    function 
it_contains_ArgumentsWildcard_it_was_constructed_with($objectProphecyArgumentsWildcard $wildcard)
    {
        
$this->beConstructedWith($objectProphecy'getName'$wildcard);

        
$this->getArgumentsWildcard()->shouldReturn($wildcard);
    }

    function 
its_ArgumentWildcard_is_mutable_through_setter(ArgumentsWildcard $wildcard)
    {
        
$this->withArguments($wildcard);

        
$this->getArgumentsWildcard()->shouldReturn($wildcard);
    }

    function 
its_withArguments_transforms_passed_array_into_ArgumentsWildcard()
    {
        
$this->withArguments(array(4233));

        
$wildcard $this->getArgumentsWildcard();
        
$wildcard->shouldNotBe(null);
        
$wildcard->__toString()->shouldReturn('exact(42), exact(33)');
    }

    function 
its_withArguments_throws_exception_if_wrong_arguments_provided()
    {
        
$this->shouldThrow('ProphecyExceptionInvalidArgumentException')->duringWithArguments(42);
    }
}
Онлайн: 0
Реклама