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 MagicCallPatchSpec 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_supports_anything(ClassNode $node)
|
Chris@0
|
18 {
|
Chris@0
|
19 $this->supports($node)->shouldReturn(true);
|
Chris@0
|
20 }
|
Chris@0
|
21
|
Chris@0
|
22 function it_discovers_api_using_phpdoc(ClassNode $node)
|
Chris@0
|
23 {
|
Chris@0
|
24 $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApi');
|
Chris@0
|
25 $node->getInterfaces()->willReturn(array());
|
Chris@0
|
26
|
Chris@0
|
27 $node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
|
Chris@0
|
28
|
Chris@0
|
29 $this->apply($node);
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 function it_ignores_existing_methods(ClassNode $node)
|
Chris@0
|
33 {
|
Chris@0
|
34 $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiExtended');
|
Chris@0
|
35 $node->getInterfaces()->willReturn(array());
|
Chris@0
|
36
|
Chris@0
|
37 $node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
|
Chris@0
|
38 $node->addMethod(new MethodNode('definedMethod'))->shouldNotBeCalled();
|
Chris@0
|
39
|
Chris@0
|
40 $this->apply($node);
|
Chris@0
|
41 }
|
Chris@0
|
42
|
Chris@0
|
43 function it_ignores_empty_methods_from_phpdoc(ClassNode $node)
|
Chris@0
|
44 {
|
Chris@0
|
45 $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiInvalidMethodDefinition');
|
Chris@0
|
46 $node->getInterfaces()->willReturn(array());
|
Chris@0
|
47
|
Chris@0
|
48 $node->addMethod(new MethodNode(''))->shouldNotBeCalled();
|
Chris@0
|
49
|
Chris@0
|
50 $this->apply($node);
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 function it_discovers_api_using_phpdoc_from_implemented_interfaces(ClassNode $node)
|
Chris@0
|
54 {
|
Chris@0
|
55 $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented');
|
Chris@0
|
56 $node->getInterfaces()->willReturn(array());
|
Chris@0
|
57
|
Chris@0
|
58 $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
|
Chris@0
|
59
|
Chris@0
|
60 $this->apply($node);
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 function it_discovers_api_using_phpdoc_from_own_interfaces(ClassNode $node)
|
Chris@0
|
64 {
|
Chris@0
|
65 $node->getParentClass()->willReturn('stdClass');
|
Chris@0
|
66 $node->getInterfaces()->willReturn(array('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented'));
|
Chris@0
|
67
|
Chris@0
|
68 $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
|
Chris@0
|
69
|
Chris@0
|
70 $this->apply($node);
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 function it_discovers_api_using_phpdoc_from_extended_parent_interfaces(ClassNode $node)
|
Chris@0
|
74 {
|
Chris@0
|
75 $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplementedExtended');
|
Chris@0
|
76 $node->getInterfaces()->willReturn(array());
|
Chris@0
|
77
|
Chris@0
|
78 $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
|
Chris@0
|
79
|
Chris@0
|
80 $this->apply($node);
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@0
|
83 function it_has_50_priority()
|
Chris@0
|
84 {
|
Chris@0
|
85 $this->getPriority()->shouldReturn(50);
|
Chris@0
|
86 }
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * @method void undefinedMethod()
|
Chris@0
|
91 */
|
Chris@0
|
92 class MagicalApi
|
Chris@0
|
93 {
|
Chris@0
|
94 /**
|
Chris@0
|
95 * @return void
|
Chris@0
|
96 */
|
Chris@0
|
97 public function definedMethod()
|
Chris@0
|
98 {
|
Chris@0
|
99
|
Chris@0
|
100 }
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 /**
|
Chris@0
|
104 * @method void invalidMethodDefinition
|
Chris@0
|
105 * @method void
|
Chris@0
|
106 * @method
|
Chris@0
|
107 */
|
Chris@0
|
108 class MagicalApiInvalidMethodDefinition
|
Chris@0
|
109 {
|
Chris@0
|
110 }
|
Chris@0
|
111
|
Chris@0
|
112 /**
|
Chris@0
|
113 * @method void undefinedMethod()
|
Chris@0
|
114 * @method void definedMethod()
|
Chris@0
|
115 */
|
Chris@0
|
116 class MagicalApiExtended extends MagicalApi
|
Chris@0
|
117 {
|
Chris@0
|
118
|
Chris@0
|
119 }
|
Chris@0
|
120
|
Chris@0
|
121 /**
|
Chris@0
|
122 */
|
Chris@0
|
123 class MagicalApiImplemented implements MagicalApiInterface
|
Chris@0
|
124 {
|
Chris@0
|
125
|
Chris@0
|
126 }
|
Chris@0
|
127
|
Chris@0
|
128 /**
|
Chris@0
|
129 */
|
Chris@0
|
130 class MagicalApiImplementedExtended extends MagicalApiImplemented
|
Chris@0
|
131 {
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@0
|
134 /**
|
Chris@0
|
135 * @method void implementedMethod()
|
Chris@0
|
136 */
|
Chris@0
|
137 interface MagicalApiInterface
|
Chris@0
|
138 {
|
Chris@0
|
139
|
Chris@0
|
140 }
|