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

namespace specProphecyProphecy;

use 
PhpSpecObjectBehavior;
use 
ProphecyArgument;

class 
ObjectProphecySpec extends ObjectBehavior
{
    
/**
     * @param ProphecyDoublerLazyDouble                $lazyDouble
     * @param ProphecyProphecyProphecySubjectInterface $double
     */
    
function let($lazyDouble$double)
    {
        
$this->beConstructedWith($lazyDouble);

        
$lazyDouble->getInstance()->willReturn($double);
    }

    function 
it_implements_ProphecyInterface()
    {
        
$this->shouldBeAnInstanceOf('ProphecyProphecyProphecyInterface');
    }

    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(125))->shouldBeCalled();

        
$this->willBeConstructedWith(array(125));
    }

    function 
it_does_not_have_method_prophecies_by_default()
    {
        
$this->getMethodProphecies()->shouldHaveCount(0);
    }

    
/**
     * @param ProphecyProphecyMethodProphecy    $method1
     * @param ProphecyProphecyMethodProphecy    $method2
     * @param ProphecyArgumentArgumentsWildcard $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 ProphecyCallCallCenter $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 ProphecyCallCallCenter            $callCenter
     * @param ProphecyProphecyRevealerInterface $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 ProphecyCallCallCenter            $callCenter
     * @param ProphecyArgumentArgumentsWildcard $wildcard
     * @param ProphecyCallCall                  $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 ProphecyProphecyMethodProphecy    $methodProphecy
     * @param ProphecyArgumentArgumentsWildcard $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 ProphecyProphecyMethodProphecy    $methodProphecy1
     * @param ProphecyProphecyMethodProphecy    $methodProphecy2
     * @param ProphecyArgumentArgumentsWildcard $argumentsWildcard1
     * @param ProphecyArgumentArgumentsWildcard $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 ProphecyProphecyMethodProphecy    $methodProphecy1
     * @param ProphecyProphecyMethodProphecy    $methodProphecy2
     * @param ProphecyArgumentArgumentsWildcard $argumentsWildcard1
     * @param ProphecyArgumentArgumentsWildcard $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 ProphecyProphecyMethodProphecy $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('ProphecyExceptionProphecyMethodProphecyException')->duringAddMethodProphecy(
            
$methodProphecy
        
);
    }

    function 
it_returns_null_after_checkPredictions_call_if_there_is_no_method_prophecies()
    {
        
$this->checkProphecyMethodsPredictions()->shouldReturn(null);
    }

    
/**
     * @param ProphecyProphecyMethodProphecy    $methodProphecy1
     * @param ProphecyProphecyMethodProphecy    $methodProphecy2
     * @param ProphecyArgumentArgumentsWildcard $argumentsWildcard1
     * @param ProphecyArgumentArgumentsWildcard $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('ProphecyExceptionPredictionAggregateException');

        
$methodProphecy2->getMethodName()->willReturn('setName');
        
$methodProphecy2->getArgumentsWildcard()->willReturn($argumentsWildcard2);
        
$methodProphecy2->checkPrediction()
            ->
willThrow('ProphecyExceptionPredictionAggregateException');

        
$this->addMethodProphecy($methodProphecy1);
        
$this->addMethodProphecy($methodProphecy2);

        
$this->shouldThrow('ProphecyExceptionPredictionAggregateException')
            ->
duringCheckProphecyMethodsPredictions();
    }

    
/**
     * @param ProphecyDoublerDoubler                   $doubler
     * @param ProphecyProphecyProphecySubjectInterface $reflection
     */
    
function it_returns_new_MethodProphecy_instance_for_arbitrary_call($doubler$reflection)
    {
        
$doubler->double(Argument::any())->willReturn($reflection);

        
$return $this->getProphecy();
        
$return->shouldBeAnInstanceOf('ProphecyProphecyMethodProphecy');
        
$return->getMethodName()->shouldReturn('getProphecy');
    }

    
/**
     * @param ProphecyDoublerDoubler                   $doubler
     * @param ProphecyProphecyProphecySubjectInterface $reflection
     */
    
function it_returns_same_MethodProphecy_for_same_registered_signature($doubler$reflection)
    {
        
$doubler->double(Argument::any())->willReturn($reflection);

        
$this->addMethodProphecy($methodProphecy1 $this->getProphecy(123));
        
$methodProphecy2 $this->getProphecy(123);

        
$methodProphecy2->shouldBe($methodProphecy1);
    }

    
/**
     * @param ProphecyDoublerDoubler                   $doubler
     * @param ProphecyProphecyProphecySubjectInterface $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(123$value));
        
$methodProphecy2 $this->getProphecy(123$value2);

        
$methodProphecy2->shouldNotBe($methodProphecy1);
    }

    
/**
     * @param ProphecyDoublerDoubler                   $doubler
     * @param ProphecyProphecyProphecySubjectInterface $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;
    }
}
Онлайн: 6
Реклама