Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace spec\Prophecy\Doubler\ClassPatch;
|
Chris@0
|
4
|
Chris@0
|
5 use PhpSpec\ObjectBehavior;
|
Chris@0
|
6 use Prophecy\Argument;
|
Chris@0
|
7 use Prophecy\Doubler\Generator\Node\ClassNode;
|
Chris@0
|
8 use Prophecy\Doubler\Generator\Node\MethodNode;
|
Chris@0
|
9
|
Chris@0
|
10 class ProphecySubjectPatchSpec extends ObjectBehavior
|
Chris@0
|
11 {
|
Chris@0
|
12 function it_is_a_patch()
|
Chris@0
|
13 {
|
Chris@0
|
14 $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
Chris@0
|
15 }
|
Chris@0
|
16
|
Chris@0
|
17 function it_has_priority_of_0()
|
Chris@0
|
18 {
|
Chris@0
|
19 $this->getPriority()->shouldReturn(0);
|
Chris@0
|
20 }
|
Chris@0
|
21
|
Chris@0
|
22 function it_supports_any_class(ClassNode $node)
|
Chris@0
|
23 {
|
Chris@0
|
24 $this->supports($node)->shouldReturn(true);
|
Chris@0
|
25 }
|
Chris@0
|
26
|
Chris@0
|
27 function it_forces_class_to_implement_ProphecySubjectInterface(ClassNode $node)
|
Chris@0
|
28 {
|
Chris@0
|
29 $node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface')->shouldBeCalled();
|
Chris@0
|
30
|
Chris@0
|
31 $node->addProperty('objectProphecy', 'private')->willReturn(null);
|
Chris@0
|
32 $node->getMethods()->willReturn(array());
|
Chris@0
|
33 $node->hasMethod(Argument::any())->willReturn(false);
|
Chris@0
|
34 $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
Chris@0
|
35 $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
Chris@0
|
36
|
Chris@0
|
37 $this->apply($node);
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 function it_forces_all_class_methods_except_constructor_to_proxy_calls_into_prophecy_makeCall(
|
Chris@0
|
41 ClassNode $node,
|
Chris@0
|
42 MethodNode $constructor,
|
Chris@0
|
43 MethodNode $method1,
|
Chris@0
|
44 MethodNode $method2,
|
Chris@0
|
45 MethodNode $method3
|
Chris@0
|
46 ) {
|
Chris@0
|
47 $node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface')->willReturn(null);
|
Chris@0
|
48 $node->addProperty('objectProphecy', 'private')->willReturn(null);
|
Chris@0
|
49 $node->hasMethod(Argument::any())->willReturn(false);
|
Chris@0
|
50 $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
Chris@0
|
51 $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
Chris@0
|
52
|
Chris@0
|
53 $constructor->getName()->willReturn('__construct');
|
Chris@0
|
54 $method1->getName()->willReturn('method1');
|
Chris@0
|
55 $method2->getName()->willReturn('method2');
|
Chris@0
|
56 $method3->getName()->willReturn('method3');
|
Chris@0
|
57
|
Chris@0
|
58 $method1->getReturnType()->willReturn('int');
|
Chris@0
|
59 $method2->getReturnType()->willReturn('int');
|
Chris@0
|
60 $method3->getReturnType()->willReturn('void');
|
Chris@0
|
61
|
Chris@0
|
62 $node->getMethods()->willReturn(array(
|
Chris@0
|
63 'method1' => $method1,
|
Chris@0
|
64 'method2' => $method2,
|
Chris@0
|
65 'method3' => $method3,
|
Chris@0
|
66 ));
|
Chris@0
|
67
|
Chris@0
|
68 $constructor->setCode(Argument::any())->shouldNotBeCalled();
|
Chris@0
|
69
|
Chris@0
|
70 $method1->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
|
Chris@0
|
71 ->shouldBeCalled();
|
Chris@0
|
72 $method2->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
|
Chris@0
|
73 ->shouldBeCalled();
|
Chris@0
|
74 $method3->setCode('$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
|
Chris@0
|
75 ->shouldBeCalled();
|
Chris@0
|
76
|
Chris@0
|
77 $this->apply($node);
|
Chris@0
|
78 }
|
Chris@0
|
79 }
|