cfe42223
曹明
提交初始代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
<?php
namespace spec\Prophecy\Prophecy;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument\ArgumentsWildcard;
use Prophecy\Call\Call;
use Prophecy\Prediction\PredictionInterface;
use Prophecy\Promise\PromiseInterface;
use Prophecy\Prophecy\ObjectProphecy;
class ClassWithFinalMethod
{
final public function finalMethod() {}
}
class MethodProphecySpec extends ObjectBehavior
{
function let(ObjectProphecy $objectProphecy, \ReflectionClass $reflection)
{
$objectProphecy->reveal()->willReturn($reflection);
$this->beConstructedWith($objectProphecy, 'getName', null);
}
function it_is_initializable()
{
$this->shouldHaveType('Prophecy\Prophecy\MethodProphecy');
}
function its_constructor_throws_MethodNotFoundException_for_unexisting_method($objectProphecy)
{
$this->shouldThrow('Prophecy\Exception\Doubler\MethodNotFoundException')->during(
'__construct', array($objectProphecy, 'getUnexisting', null)
);
}
function its_constructor_throws_MethodProphecyException_for_final_methods($objectProphecy, ClassWithFinalMethod $subject)
{
$objectProphecy->reveal()->willReturn($subject);
$this->shouldThrow('Prophecy\Exception\Prophecy\MethodProphecyException')->during(
'__construct', array($objectProphecy, 'finalMethod', null)
);
}
function its_constructor_transforms_array_passed_as_3rd_argument_to_ArgumentsWildcard(
$objectProphecy
)
{
$this->beConstructedWith($objectProphecy, 'getName', array(42, 33));
$wildcard = $this->getArgumentsWildcard();
$wildcard->shouldNotBe(null);
$wildcard->__toString()->shouldReturn('exact(42), exact(33)');
}
function its_constructor_does_not_touch_third_argument_if_it_is_null($objectProphecy)
{
$this->beConstructedWith($objectProphecy, 'getName', null);
$wildcard = $this->getArgumentsWildcard();
$wildcard->shouldBe(null);
}
function it_records_promise_through_will_method(PromiseInterface $promise, $objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->will($promise);
$this->getPromise()->shouldReturn($promise);
}
function it_adds_itself_to_ObjectProphecy_during_call_to_will(PromiseInterface $objectProphecy, $promise)
{
$objectProphecy->addMethodProphecy($this)->shouldBeCalled();
$this->will($promise);
}
function it_adds_ReturnPromise_during_willReturn_call($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->willReturn(42);
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\ReturnPromise');
}
function it_adds_ThrowPromise_during_willThrow_call($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->willThrow('RuntimeException');
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\ThrowPromise');
}
function it_adds_ReturnArgumentPromise_during_willReturnArgument_call($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->willReturnArgument();
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\ReturnArgumentPromise');
}
function it_adds_ReturnArgumentPromise_during_willReturnArgument_call_with_index_argument($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->willReturnArgument(1);
$promise = $this->getPromise();
$promise->shouldBeAnInstanceOf('Prophecy\Promise\ReturnArgumentPromise');
$promise->execute(array('one', 'two'), $objectProphecy, $this)->shouldReturn('two');
}
function it_adds_CallbackPromise_during_will_call_with_callback_argument($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$callback = function () {};
$this->will($callback);
$this->getPromise()->shouldBeAnInstanceOf('Prophecy\Promise\CallbackPromise');
}
function it_records_prediction_through_should_method(PredictionInterface $prediction, $objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->callOnWrappedObject('should', array($prediction));
$this->getPrediction()->shouldReturn($prediction);
}
function it_adds_CallbackPrediction_during_should_call_with_callback_argument($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$callback = function () {};
$this->callOnWrappedObject('should', array($callback));
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\CallbackPrediction');
}
function it_adds_itself_to_ObjectProphecy_during_call_to_should($objectProphecy, PredictionInterface $prediction)
{
$objectProphecy->addMethodProphecy($this)->shouldBeCalled();
$this->callOnWrappedObject('should', array($prediction));
}
function it_adds_CallPrediction_during_shouldBeCalled_call($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->callOnWrappedObject('shouldBeCalled', array());
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\CallPrediction');
}
function it_adds_NoCallsPrediction_during_shouldNotBeCalled_call($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->callOnWrappedObject('shouldNotBeCalled', array());
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\NoCallsPrediction');
}
function it_adds_CallTimesPrediction_during_shouldBeCalledTimes_call($objectProphecy)
{
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->callOnWrappedObject('shouldBeCalledTimes', array(5));
$this->getPrediction()->shouldBeAnInstanceOf('Prophecy\Prediction\CallTimesPrediction');
}
function it_checks_prediction_via_shouldHave_method_call(
$objectProphecy,
ArgumentsWildcard $arguments,
PredictionInterface $prediction,
Call $call1,
Call $call2
) {
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$this->withArguments($arguments);
$this->callOnWrappedObject('shouldHave', array($prediction));
}
function it_sets_return_promise_during_shouldHave_call_if_none_was_set_before(
$objectProphecy,
ArgumentsWildcard $arguments,
PredictionInterface $prediction,
Call $call1,
Call $call2
) {
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$this->withArguments($arguments);
$this->callOnWrappedObject('shouldHave', array($prediction));
$this->getPromise()->shouldReturnAnInstanceOf('Prophecy\Promise\ReturnPromise');
}
function it_does_not_set_return_promise_during_shouldHave_call_if_it_was_set_before(
$objectProphecy,
ArgumentsWildcard $arguments,
PredictionInterface $prediction,
Call $call1,
Call $call2,
PromiseInterface $promise
) {
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$this->will($promise);
$this->withArguments($arguments);
$this->callOnWrappedObject('shouldHave', array($prediction));
$this->getPromise()->shouldReturn($promise);
}
function it_records_checked_predictions(
$objectProphecy,
ArgumentsWildcard $arguments,
PredictionInterface $prediction1,
PredictionInterface $prediction2,
Call $call1,
Call $call2,
PromiseInterface $promise
) {
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$prediction1->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->willReturn();
$prediction2->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->willReturn();
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$this->will($promise);
$this->withArguments($arguments);
$this->callOnWrappedObject('shouldHave', array($prediction1));
$this->callOnWrappedObject('shouldHave', array($prediction2));
$this->getCheckedPredictions()->shouldReturn(array($prediction1, $prediction2));
}
function it_records_even_failed_checked_predictions(
$objectProphecy,
ArgumentsWildcard $arguments,
PredictionInterface $prediction,
Call $call1,
Call $call2,
PromiseInterface $promise
) {
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->willThrow(new \RuntimeException());
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$this->will($promise);
$this->withArguments($arguments);
try {
$this->callOnWrappedObject('shouldHave', array($prediction));
} catch (\Exception $e) {}
$this->getCheckedPredictions()->shouldReturn(array($prediction));
}
function it_checks_prediction_via_shouldHave_method_call_with_callback(
$objectProphecy,
ArgumentsWildcard $arguments,
Call $call1,
Call $call2
) {
$callback = function ($calls, $object, $method) {
throw new \RuntimeException;
};
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$this->withArguments($arguments);
$this->shouldThrow('RuntimeException')->duringShouldHave($callback);
}
function it_does_nothing_during_checkPrediction_if_no_prediction_set()
{
$this->checkPrediction()->shouldReturn(null);
}
function it_checks_set_prediction_during_checkPrediction(
$objectProphecy,
ArgumentsWildcard $arguments,
PredictionInterface $prediction,
Call $call1,
Call $call2
) {
$prediction->check(array($call1, $call2), $objectProphecy->getWrappedObject(), $this)->shouldBeCalled();
$objectProphecy->findProphecyMethodCalls('getName', $arguments)->willReturn(array($call1, $call2));
$objectProphecy->addMethodProphecy($this)->willReturn(null);
$this->withArguments($arguments);
$this->callOnWrappedObject('should', array($prediction));
$this->checkPrediction();
}
function it_links_back_to_ObjectProphecy_through_getter($objectProphecy)
{
$this->getObjectProphecy()->shouldReturn($objectProphecy);
}
function it_has_MethodName()
{
$this->getMethodName()->shouldReturn('getName');
}
function it_contains_ArgumentsWildcard_it_was_constructed_with($objectProphecy, ArgumentsWildcard $wildcard)
{
$this->beConstructedWith($objectProphecy, 'getName', $wildcard);
$this->getArgumentsWildcard()->shouldReturn($wildcard);
}
function its_ArgumentWildcard_is_mutable_through_setter(ArgumentsWildcard $wildcard)
{
$this->withArguments($wildcard);
$this->getArgumentsWildcard()->shouldReturn($wildcard);
}
function its_withArguments_transforms_passed_array_into_ArgumentsWildcard()
{
$this->withArguments(array(42, 33));
$wildcard = $this->getArgumentsWildcard();
$wildcard->shouldNotBe(null);
$wildcard->__toString()->shouldReturn('exact(42), exact(33)');
}
function its_withArguments_throws_exception_if_wrong_arguments_provided()
{
$this->shouldThrow('Prophecy\Exception\InvalidArgumentException')->duringWithArguments(42);
}
}
|