ProphetSpec.php (2901B)
1 <?php 2 3 namespace spec\Prophecy; 4 5 use PhpSpec\ObjectBehavior; 6 use Prophecy\Argument; 7 8 class ProphetSpec extends ObjectBehavior 9 { 10 /** 11 * @param \Prophecy\Doubler\Doubler $doubler 12 * @param \Prophecy\Prophecy\ProphecySubjectInterface $double 13 */ 14 function let($doubler, $double) 15 { 16 $doubler->double(null, array())->willReturn($double); 17 18 $this->beConstructedWith($doubler); 19 } 20 21 function it_constructs_new_prophecy_on_prophesize_call() 22 { 23 $prophecy = $this->prophesize(); 24 $prophecy->shouldBeAnInstanceOf('Prophecy\Prophecy\ObjectProphecy'); 25 } 26 27 /** 28 * @param \Prophecy\Prophecy\ProphecySubjectInterface $newDouble 29 */ 30 function it_constructs_new_prophecy_with_parent_class_if_specified($doubler, $newDouble) 31 { 32 $doubler->double(Argument::any(), array())->willReturn($newDouble); 33 34 $this->prophesize('Prophecy\Prophet')->reveal()->shouldReturn($newDouble); 35 } 36 37 /** 38 * @param \Prophecy\Prophecy\ProphecySubjectInterface $newDouble 39 */ 40 function it_constructs_new_prophecy_with_interface_if_specified($doubler, $newDouble) 41 { 42 $doubler->double(null, Argument::any())->willReturn($newDouble); 43 44 $this->prophesize('ArrayAccess')->reveal()->shouldReturn($newDouble); 45 } 46 47 function it_exposes_all_created_prophecies_through_getter() 48 { 49 $prophecy1 = $this->prophesize(); 50 $prophecy2 = $this->prophesize(); 51 52 $this->getProphecies()->shouldReturn(array($prophecy1, $prophecy2)); 53 } 54 55 function it_does_nothing_during_checkPredictions_call_if_no_predictions_defined() 56 { 57 $this->checkPredictions()->shouldReturn(null); 58 } 59 60 /** 61 * @param \Prophecy\Prophecy\MethodProphecy $method1 62 * @param \Prophecy\Prophecy\MethodProphecy $method2 63 * @param \Prophecy\Argument\ArgumentsWildcard $arguments1 64 * @param \Prophecy\Argument\ArgumentsWildcard $arguments2 65 */ 66 function it_throws_AggregateException_if_defined_predictions_fail( 67 $method1, $method2, $arguments1, $arguments2 68 ) 69 { 70 $method1->getMethodName()->willReturn('getName'); 71 $method1->getArgumentsWildcard()->willReturn($arguments1); 72 $method1->checkPrediction()->willReturn(null); 73 74 $method2->getMethodName()->willReturn('isSet'); 75 $method2->getArgumentsWildcard()->willReturn($arguments2); 76 $method2->checkPrediction()->willThrow( 77 'Prophecy\Exception\Prediction\AggregateException' 78 ); 79 80 $this->prophesize()->addMethodProphecy($method1); 81 $this->prophesize()->addMethodProphecy($method2); 82 83 $this->shouldThrow('Prophecy\Exception\Prediction\AggregateException') 84 ->duringCheckPredictions(); 85 } 86 87 function it_exposes_doubler_through_getter($doubler) 88 { 89 $this->getDoubler()->shouldReturn($doubler); 90 } 91 }