1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Prophecy; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Prophecy\Argument\ArgumentsWildcard; |
8
|
|
|
use Prophecy\Doubler\Doubler; |
9
|
|
|
use Prophecy\Prophecy\MethodProphecy; |
10
|
|
|
use Prophecy\Prophecy\ProphecySubjectInterface; |
11
|
|
|
|
12
|
|
|
class ProphetSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
function let(Doubler $doubler, ProphecySubjectInterface $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
|
|
|
function it_constructs_new_prophecy_with_parent_class_if_specified($doubler, ProphecySubjectInterface $newDouble) |
28
|
|
|
{ |
29
|
|
|
$doubler->double(Argument::any(), array())->willReturn($newDouble); |
30
|
|
|
|
31
|
|
|
$this->prophesize('Prophecy\Prophet')->reveal()->shouldReturn($newDouble); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_constructs_new_prophecy_with_interface_if_specified($doubler, ProphecySubjectInterface $newDouble) |
35
|
|
|
{ |
36
|
|
|
$doubler->double(null, Argument::any())->willReturn($newDouble); |
37
|
|
|
|
38
|
|
|
$this->prophesize('ArrayAccess')->reveal()->shouldReturn($newDouble); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_exposes_all_created_prophecies_through_getter() |
42
|
|
|
{ |
43
|
|
|
$prophecy1 = $this->prophesize(); |
44
|
|
|
$prophecy2 = $this->prophesize(); |
45
|
|
|
|
46
|
|
|
$this->getProphecies()->shouldReturn(array($prophecy1, $prophecy2)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_does_nothing_during_checkPredictions_call_if_no_predictions_defined() |
50
|
|
|
{ |
51
|
|
|
$this->checkPredictions()->shouldReturn(null); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
function it_throws_AggregateException_if_defined_predictions_fail( |
|
|
|
|
55
|
|
|
MethodProphecy $method1, |
56
|
|
|
MethodProphecy $method2, |
57
|
|
|
ArgumentsWildcard $arguments1, |
58
|
|
|
ArgumentsWildcard $arguments2 |
59
|
|
|
) { |
60
|
|
|
$method1->getMethodName()->willReturn('getName'); |
61
|
|
|
$method1->getArgumentsWildcard()->willReturn($arguments1); |
62
|
|
|
$method1->checkPrediction()->willReturn(null); |
63
|
|
|
|
64
|
|
|
$method2->getMethodName()->willReturn('isSet'); |
65
|
|
|
$method2->getArgumentsWildcard()->willReturn($arguments2); |
66
|
|
|
$method2->checkPrediction()->willThrow( |
67
|
|
|
'Prophecy\Exception\Prediction\AggregateException' |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$this->prophesize()->addMethodProphecy($method1); |
71
|
|
|
$this->prophesize()->addMethodProphecy($method2); |
72
|
|
|
|
73
|
|
|
$this->shouldThrow('Prophecy\Exception\Prediction\AggregateException') |
74
|
|
|
->duringCheckPredictions(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function it_exposes_doubler_through_getter($doubler) |
78
|
|
|
{ |
79
|
|
|
$this->getDoubler()->shouldReturn($doubler); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.