Completed
Pull Request — master (#566)
by Thomas
04:26
created

Expectation   D

Complexity

Total Complexity 100

Size/Duplication

Total Lines 801
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 94.3%

Importance

Changes 0
Metric Value
dl 0
loc 801
ccs 215
cts 228
cp 0.943
rs 4.4444
c 0
b 0
f 0
wmc 100
lcom 2
cbo 8

50 Methods

Rating   Name   Duplication   Size   Complexity  
A andReturnSelf() 0 4 1
A andReturnValues() 0 5 1
A andReturnUndefined() 0 5 1
A andReturnNull() 0 4 1
A andReturnFalse() 0 4 1
A andReturnTrue() 0 4 1
A andThrow() 0 10 2
A andThrowExceptions() 0 10 3
A __construct() 0 6 1
A __toString() 0 4 1
A verifyCall() 0 14 2
A throwAsNecessary() 0 16 4
A _setValues() 0 9 3
B _getReturnValue() 0 14 5
A isEligible() 0 9 3
A isExpected() 0 9 3
A isCallCountConstrained() 0 4 1
A validateOrder() 0 10 3
A verify() 0 6 2
A isArgumentListMatcher() 0 4 2
B matchArgs() 0 18 5
C _matchArg() 0 33 15
A with() 0 4 1
A withArgsInArray() 0 8 2
A withArgsMatchedByClosure() 0 5 1
A withArgs() 0 12 3
A withNoArgs() 0 5 1
A withAnyArgs() 0 5 1
A andReturn() 0 5 1
A andReturns() 0 4 1
A andReturnUsing() 0 5 1
A andSet() 0 5 1
A set() 0 4 1
A zeroOrMoreTimes() 0 4 1
A times() 0 12 3
A never() 0 4 1
A once() 0 4 1
A twice() 0 4 1
A atLeast() 0 5 1
A atMost() 0 5 1
A between() 0 4 1
A ordered() 0 10 2
A globally() 0 5 1
A _defineOrdered() 0 13 3
A getOrderNumber() 0 4 1
A byDefault() 0 8 2
A getMock() 0 4 1
A passthru() 0 11 2
A __clone() 0 9 2
A getName() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Expectation often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Expectation, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Mockery
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://github.com/padraic/mockery/blob/master/LICENSE
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Mockery
16
 * @package    Mockery
17
 * @copyright  Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18
 * @license    http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19
 */
20
21
namespace Mockery;
22
23
use Closure;
24
use Mockery\Matcher\MultiArgumentClosure;
25
use Mockery\Matcher\ArgumentListMatcher;
26
use Mockery\Matcher\AnyArgs;
27
use Mockery\Matcher\NoArgs;
28
29
class Expectation implements ExpectationInterface
30
{
31
    /**
32
     * Mock object to which this expectation belongs
33
     *
34
     * @var object
35
     */
36
    protected $_mock = null;
37
38
    /**
39
     * Method name
40
     *
41
     * @var string
42
     */
43
    protected $_name = null;
44
45
    /**
46
     * Arguments expected by this expectation
47
     *
48
     * @var array
49
     */
50
    protected $_expectedArgs = array();
51
52
    /**
53
     * Count validator store
54
     *
55
     * @var \Mockery\CountValidator\CountValidatorAbstract[]
56
     */
57
    protected $_countValidators = array();
58
59
    /**
60
     * The count validator class to use
61
     *
62
     * @var string
63
     */
64
    protected $_countValidatorClass = 'Mockery\CountValidator\Exact';
65
66
    /**
67
     * Actual count of calls to this expectation
68
     *
69
     * @var int
70
     */
71
    protected $_actualCount = 0;
72
73
    /**
74
     * Value to return from this expectation
75
     *
76
     * @var mixed
77
     */
78
    protected $_returnValue = null;
79
80
    /**
81
     * Array of return values as a queue for multiple return sequence
82
     *
83
     * @var array
84
     */
85
    protected $_returnQueue = array();
86
87
    /**
88
     * Array of closures executed with given arguments to generate a result
89
     * to be returned
90
     *
91
     * @var array
92
     */
93
    protected $_closureQueue = array();
94
95
    /**
96
     * Array of values to be set when this expectation matches
97
     *
98
     * @var array
99
     */
100
    protected $_setQueue = array();
101
102
    /**
103
     * Integer representing the call order of this expectation
104
     *
105
     * @var int
106
     */
107
    protected $_orderNumber = null;
108
109
    /**
110
     * Integer representing the call order of this expectation on a global basis
111
     *
112
     * @var int
113
     */
114
    protected $_globalOrderNumber = null;
115
116
    /**
117
     * Flag indicating that an exception is expected to be throw (not returned)
118
     *
119
     * @var bool
120
     */
121
    protected $_throw = false;
122
123
    /**
124
     * Flag indicating whether the order of calling is determined locally or
125
     * globally
126
     *
127
     * @var bool
128
     */
129
    protected $_globally = false;
130
131
    /**
132
     * Flag indicating if the return value should be obtained from the original
133
     * class method instead of returning predefined values from the return queue
134
     *
135
     * @var bool
136
     */
137
    protected $_passthru = false;
138
139
    /**
140
     * Constructor
141
     *
142
     * @param \Mockery\MockInterface $mock
143
     * @param string $name
144
     */
145 344
    public function __construct(\Mockery\MockInterface $mock, $name)
146
    {
147 344
        $this->_mock = $mock;
148 344
        $this->_name = $name;
149 344
        $this->withAnyArgs();
150 344
    }
151
152
    /**
153
     * Return a string with the method name and arguments formatted
154
     *
155
     * @param string $name Name of the expected method
156
     * @param array $args List of arguments to the method
157
     * @return string
158
     */
159 45
    public function __toString()
160
    {
161 45
        return \Mockery::formatArgs($this->_name, $this->_expectedArgs);
162
    }
163
164
    /**
165
     * Verify the current call, i.e. that the given arguments match those
166
     * of this expectation
167
     *
168
     * @param array $args
169
     * @return mixed
170
     */
171 273
    public function verifyCall(array $args)
172
    {
173 273
        $this->validateOrder();
174 273
        $this->_actualCount++;
175 273
        if (true === $this->_passthru) {
176 3
            return $this->_mock->mockery_callSubjectMethod($this->_name, $args);
177
        }
178
179 271
        $return = $this->_getReturnValue($args);
180 271
        $this->throwAsNecessary($return);
181 264
        $this->_setValues();
182
183 264
        return $return;
184
    }
185
186
    /**
187
     * Throws an exception if the expectation has been configured to do so
188
     *
189
     * @throws \Exception|\Throwable
190
     * @return void
191
     */
192 271
    private function throwAsNecessary($return)
193
    {
194 271
        if (!$this->_throw) {
195 264
            return;
196
        }
197
198 8
        $type = version_compare(PHP_VERSION, '7.0.0') >= 0
199 8
            ? "\Throwable"
200 8
            : "\Exception";
201
202 8
        if ($return instanceof $type) {
203 8
            throw $return;
204
        }
205
206
        return;
0 ignored issues
show
Coding Style introduced by
Empty return statement not required here
Loading history...
207
    }
208
209
    /**
210
     * Sets public properties with queued values to the mock object
211
     *
212
     * @param array $args
0 ignored issues
show
Bug introduced by
There is no parameter named $args. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
213
     * @return mixed
214
     */
215 264
    protected function _setValues()
216
    {
217 264
        foreach ($this->_setQueue as $name => &$values) {
218 8
            if (count($values) > 0) {
219 8
                $value = array_shift($values);
220 8
                $this->_mock->{$name} = $value;
221
            }
222
        }
223 264
    }
224
225
    /**
226
     * Fetch the return value for the matching args
227
     *
228
     * @param array $args
229
     * @return mixed
230
     */
231 271
    protected function _getReturnValue(array $args)
232
    {
233 271
        if (count($this->_closureQueue) > 1) {
234
            return call_user_func_array(array_shift($this->_closureQueue), $args);
235 271
        } elseif (count($this->_closureQueue) > 0) {
236 1
            return call_user_func_array(current($this->_closureQueue), $args);
237 270
        } elseif (count($this->_returnQueue) > 1) {
238 5
            return array_shift($this->_returnQueue);
239 269
        } elseif (count($this->_returnQueue) > 0) {
240 122
            return current($this->_returnQueue);
241
        }
242
243 148
        return $this->_mock->mockery_returnValueForMethod($this->_name);
244
    }
245
246
    /**
247
     * Checks if this expectation is eligible for additional calls
248
     *
249
     * @return bool
250
     */
251 310
    public function isEligible()
252
    {
253 310
        foreach ($this->_countValidators as $validator) {
254 140
            if (!$validator->isEligible($this->_actualCount)) {
255 140
                return false;
256
            }
257
        }
258 307
        return true;
259
    }
260
261 270
    public function isExpected()
262
    {
263 270
        foreach ($this->_countValidators as $validator) {
264 137
            if ($validator->isEligible($this->_actualCount)) {
265 137
                return true;
266
            }
267
        }
268 185
        return false;
269
    }
270
271
    /**
272
     * Check if there is a constraint on call count
273
     *
274
     * @return bool
275
     */
276
    public function isCallCountConstrained()
277
    {
278
        return (count($this->_countValidators) > 0);
279
    }
280
281
    /**
282
     * Verify call order
283
     *
284
     * @return void
285
     */
286 273
    public function validateOrder()
287
    {
288 273
        if ($this->_orderNumber) {
289 15
            $this->_mock->mockery_validateOrder((string) $this, $this->_orderNumber, $this->_mock);
290
        }
291 273
        if ($this->_globalOrderNumber) {
292 1
            $this->_mock->mockery_getContainer()
293 1
                ->mockery_validateOrder((string) $this, $this->_globalOrderNumber, $this->_mock);
294
        }
295 273
    }
296
297
    /**
298
     * Verify this expectation
299
     *
300
     * @return bool
301
     */
302 151
    public function verify()
303
    {
304 151
        foreach ($this->_countValidators as $validator) {
305 122
            $validator->validate($this->_actualCount);
306
        }
307 133
    }
308
309
    /**
310
     * Check if the registered expectation is an ArgumentListMatcher
311
     * @return bool
312
     */
313 317
    private function isArgumentListMatcher()
314
    {
315 317
        return (count($this->_expectedArgs) === 1 && ($this->_expectedArgs[0] instanceof ArgumentListMatcher));
316
    }
317
318
    /**
319
     * Check if passed arguments match an argument expectation
320
     *
321
     * @param array $args
322
     * @return bool
323
     */
324 317
    public function matchArgs(array $args)
325
    {
326 317
        if ($this->isArgumentListMatcher()) {
327 218
            return $this->_matchArg($this->_expectedArgs[0], $args);
328
        }
329 105
        $argCount = count($args);
330 105
        if ($argCount !== count($this->_expectedArgs)) {
331 5
            return false;
332
        }
333 102
        for ($i=0; $i<$argCount; $i++) {
334 102
            $param =& $args[$i];
335 102
            if (!$this->_matchArg($this->_expectedArgs[$i], $param)) {
336 45
                return false;
337
            }
338
        }
339
340 66
        return true;
341
    }
342
343
    /**
344
     * Check if passed argument matches an argument expectation
345
     *
346
     * @param mixed $expected
347
     * @param mixed &$actual
348
     * @return bool
349
     */
350 314
    protected function _matchArg($expected, &$actual)
351
    {
352 314
        if ($expected === $actual) {
353 31
            return true;
354
        }
355 299
        if (!is_object($expected) && !is_object($actual) && $expected == $actual) {
356
            return true;
357
        }
358 299
        if (is_string($expected) && !is_array($actual) && !is_object($actual)) {
359
            # push/pop an error handler here to to make sure no error/exception thrown if $expected is not a regex
360 6
            set_error_handler(function () {
361 6
            });
362 6
            $result = preg_match($expected, (string) $actual);
363 6
            restore_error_handler();
364
365 6
            if ($result) {
366 3
                return true;
367
            }
368
        }
369 298
        if (is_string($expected) && is_object($actual)) {
370 1
            $result = $actual instanceof $expected;
371 1
            if ($result) {
372 1
                return true;
373
            }
374
        }
375 297
        if ($expected instanceof \Mockery\Matcher\MatcherAbstract) {
376 278
            return $expected->match($actual);
377
        }
378 21
        if ($expected instanceof \Hamcrest\Matcher || $expected instanceof \Hamcrest_Matcher) {
0 ignored issues
show
Bug introduced by
The class Hamcrest_Matcher does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
379 3
            return $expected->matches($actual);
380
        }
381 18
        return false;
382
    }
383
384
    /**
385
     * Expected argument setter for the expectation
386
     *
387
     * @param mixed[] ...
388
     * @return self
389
     */
390 130
    public function with(...$args)
391
    {
392 130
        return $this->withArgs($args);
393
    }
394
395
    /**
396
     * Expected arguments for the expectation passed as an array
397
     *
398
     * @param array $arguments
399
     * @return Expectation
400
     */
401 140
    private function withArgsInArray(array $arguments)
402
    {
403 140
        if (empty($arguments)) {
404 3
            return $this->withNoArgs();
405
        }
406 137
        $this->_expectedArgs = $arguments;
407 137
        return $this;
408
    }
409
410
    /**
411
     * Expected arguments have to be matched by the given closure.
412
     *
413
     * @param Closure $closure
414
     * @return Expectation
415
     */
416 6
    private function withArgsMatchedByClosure(Closure $closure)
417
    {
418 6
        $this->_expectedArgs = [new MultiArgumentClosure($closure)];
419 6
        return $this;
420
    }
421
422
    /**
423
     * Expected arguments for the expectation passed as an array or a closure that matches each passed argument on
424
     * each function call.
425
     *
426
     * @param array|Closure $argsOrClosure
427
     * @return Expectation
428
     */
429 147
    public function withArgs($argsOrClosure)
430
    {
431 147
        if (is_array($argsOrClosure)) {
432 140
            $this->withArgsInArray($argsOrClosure);
433
        } elseif ($argsOrClosure instanceof Closure) {
434 6
            $this->withArgsMatchedByClosure($argsOrClosure);
435
        } else {
436 1
            throw new \InvalidArgumentException(sprintf('Call to %s with an invalid argument (%s), only array and '.
437 1
                'closure are allowed', __METHOD__, $argsOrClosure));
438
        }
439 146
        return $this;
440
    }
441
442
    /**
443
     * Set with() as no arguments expected
444
     *
445
     * @return Expectation
446
     */
447 7
    public function withNoArgs()
448
    {
449 7
        $this->_expectedArgs = [new NoArgs()];
450 7
        return $this;
451
    }
452
453
    /**
454
     * Set expectation that any arguments are acceptable
455
     *
456
     * @return Expectation
457
     */
458 344
    public function withAnyArgs()
459
    {
460 344
        $this->_expectedArgs = [new AnyArgs()];
461 344
        return $this;
462
    }
463
464
    /**
465
     * Set a return value, or sequential queue of return values
466
     *
467
     * @param mixed[] ...
468
     * @return self
469
     */
470 135
    public function andReturn(...$args)
471
    {
472 135
        $this->_returnQueue = $args;
473 135
        return $this;
474
    }
475
476
    /**
477
     * Set a return value, or sequential queue of return values
478
     *
479
     * @param mixed[] ...
480
     * @return self
481
     */
482
    public function andReturns(...$args)
483
    {
484
        return call_user_func_array([$this, 'andReturn'], $args);
485
    }
486
487
    /**
488
     * Return this mock, like a fluent interface
489
     *
490
     * @return Expectation
491
     */
492 1
    public function andReturnSelf()
493
    {
494 1
        return $this->andReturn($this->_mock);
495
    }
496
497
    /**
498
     * Set a sequential queue of return values with an array
499
     *
500
     * @param array $values
501
     * @return Expectation
502
     */
503 2
    public function andReturnValues(array $values)
504
    {
505 2
        call_user_func_array(array($this, 'andReturn'), $values);
506 2
        return $this;
507
    }
508
509
    /**
510
     * Set a closure or sequence of closures with which to generate return
511
     * values. The arguments passed to the expected method are passed to the
512
     * closures as parameters.
513
     *
514
     * @param callable[] $args
515
     * @return self
516
     */
517 1
    public function andReturnUsing(...$args)
518
    {
519 1
        $this->_closureQueue = $args;
520 1
        return $this;
521
    }
522
523
    /**
524
     * Return a self-returning black hole object.
525
     *
526
     * @return Expectation
527
     */
528 1
    public function andReturnUndefined()
529
    {
530 1
        $this->andReturn(new \Mockery\Undefined);
531 1
        return $this;
532
    }
533
534
    /**
535
     * Return null. This is merely a language construct for Mock describing.
536
     *
537
     * @return Expectation
538
     */
539 4
    public function andReturnNull()
540
    {
541 4
        return $this->andReturn(null);
542
    }
543
544 1
    public function andReturnFalse()
545
    {
546 1
        return $this->andReturn(false);
547
    }
548
549 1
    public function andReturnTrue()
550
    {
551 1
        return $this->andReturn(true);
552
    }
553
554
    /**
555
     * Set Exception class and arguments to that class to be thrown
556
     *
557
     * @param string|\Exception $exception
558
     * @param string $message
559
     * @param int $code
560
     * @param \Exception $previous
561
     * @return Expectation
562
     */
563 7
    public function andThrow($exception, $message = '', $code = 0, \Exception $previous = null)
564
    {
565 7
        $this->_throw = true;
566 7
        if (is_object($exception)) {
567 3
            $this->andReturn($exception);
568
        } else {
569 4
            $this->andReturn(new $exception($message, $code, $previous));
570
        }
571 7
        return $this;
572
    }
573
574
    /**
575
     * Set Exception classes to be thrown
576
     *
577
     * @param array $exceptions
578
     * @return Expectation
579
     */
580 2
    public function andThrowExceptions(array $exceptions)
581
    {
582 2
        $this->_throw = true;
583 2
        foreach ($exceptions as $exception) {
584 2
            if (!is_object($exception)) {
585 2
                throw new Exception('You must pass an array of exception objects to andThrowExceptions');
586
            }
587
        }
588 1
        return $this->andReturnValues($exceptions);
589
    }
590
591
    /**
592
     * Register values to be set to a public property each time this expectation occurs
593
     *
594
     * @param string $name
595
     * @param array $values
596
     * @return self
597
     */
598 8
    public function andSet($name, ...$values)
599
    {
600 8
        $this->_setQueue[$name] = $values;
601 8
        return $this;
602
    }
603
604
    /**
605
     * Alias to andSet(). Allows the natural English construct
606
     * - set('foo', 'bar')->andReturn('bar')
607
     *
608
     * @param string $name
609
     * @param mixed $value
610
     * @return Expectation
611
     */
612 3
    public function set($name, $value)
613
    {
614 3
        return call_user_func_array(array($this, 'andSet'), func_get_args());
615
    }
616
617
    /**
618
     * Indicates this expectation should occur zero or more times
619
     *
620
     * @return Expectation
621
     */
622 2
    public function zeroOrMoreTimes()
623
    {
624 2
        $this->atLeast()->never();
625 2
    }
626
627
    /**
628
     * Indicates the number of times this expectation should occur
629
     *
630
     * @param int $limit
631
     * @throws \InvalidArgumentException
632
     * @return self
633
     */
634 160
    public function times($limit = null)
635
    {
636 160
        if (is_null($limit)) {
637
            return $this;
638
        }
639 160
        if (!is_int($limit)) {
640 1
            throw new \InvalidArgumentException('The passed Times limit should be an integer value');
641
        }
642 159
        $this->_countValidators[] = new $this->_countValidatorClass($this, $limit);
643 159
        $this->_countValidatorClass = 'Mockery\CountValidator\Exact';
644 159
        return $this;
645
    }
646
647
    /**
648
     * Indicates that this expectation is never expected to be called
649
     *
650
     * @return Expectation
651
     */
652 38
    public function never()
653
    {
654 38
        return $this->times(0);
655
    }
656
657
    /**
658
     * Indicates that this expectation is expected exactly once
659
     *
660
     * @return Expectation
661
     */
662 110
    public function once()
663
    {
664 110
        return $this->times(1);
665
    }
666
667
    /**
668
     * Indicates that this expectation is expected exactly twice
669
     *
670
     * @return Expectation
671
     */
672 19
    public function twice()
673
    {
674 19
        return $this->times(2);
675
    }
676
677
    /**
678
     * Sets next count validator to the AtLeast instance
679
     *
680
     * @return Expectation
681
     */
682 15
    public function atLeast()
683
    {
684 15
        $this->_countValidatorClass = 'Mockery\CountValidator\AtLeast';
685 15
        return $this;
686
    }
687
688
    /**
689
     * Sets next count validator to the AtMost instance
690
     *
691
     * @return Expectation
692
     */
693 7
    public function atMost()
694
    {
695 7
        $this->_countValidatorClass = 'Mockery\CountValidator\AtMost';
696 7
        return $this;
697
    }
698
699
    /**
700
     * Shorthand for setting minimum and maximum constraints on call counts
701
     *
702
     * @param int $minimum
703
     * @param int $maximum
704
     */
705
    public function between($minimum, $maximum)
706
    {
707
        return $this->atLeast()->times($minimum)->atMost()->times($maximum);
708
    }
709
710
    /**
711
     * Indicates that this expectation must be called in a specific given order
712
     *
713
     * @param string $group Name of the ordered group
714
     * @return Expectation
715
     */
716 17
    public function ordered($group = null)
717
    {
718 17
        if ($this->_globally) {
719 1
            $this->_globalOrderNumber = $this->_defineOrdered($group, $this->_mock->mockery_getContainer());
720
        } else {
721 16
            $this->_orderNumber = $this->_defineOrdered($group, $this->_mock);
722
        }
723 17
        $this->_globally = false;
724 17
        return $this;
725
    }
726
727
    /**
728
     * Indicates call order should apply globally
729
     *
730
     * @return Expectation
731
     */
732 1
    public function globally()
733
    {
734 1
        $this->_globally = true;
735 1
        return $this;
736
    }
737
738
    /**
739
     * Setup the ordering tracking on the mock or mock container
740
     *
741
     * @param string $group
742
     * @param object $ordering
743
     * @return int
744
     */
745 17
    protected function _defineOrdered($group, $ordering)
746
    {
747 17
        $groups = $ordering->mockery_getGroups();
748 17
        if (is_null($group)) {
749 16
            $result = $ordering->mockery_allocateOrder();
750 4
        } elseif (isset($groups[$group])) {
751 2
            $result = $groups[$group];
752
        } else {
753 4
            $result = $ordering->mockery_allocateOrder();
754 4
            $ordering->mockery_setGroup($group, $result);
755
        }
756 17
        return $result;
757
    }
758
759
    /**
760
     * Return order number
761
     *
762
     * @return int
763
     */
764 284
    public function getOrderNumber()
765
    {
766 284
        return $this->_orderNumber;
767
    }
768
769
    /**
770
     * Mark this expectation as being a default
771
     *
772
     * @return Expectation
773
     */
774 35
    public function byDefault()
775
    {
776 35
        $director = $this->_mock->mockery_getExpectationsFor($this->_name);
777 35
        if (!empty($director)) {
778 35
            $director->makeExpectationDefault($this);
779
        }
780 34
        return $this;
781
    }
782
783
    /**
784
     * Return the parent mock of the expectation
785
     *
786
     * @return \Mockery\MockInterface
787
     */
788 29
    public function getMock()
789
    {
790 29
        return $this->_mock;
791
    }
792
793
    /**
794
     * Flag this expectation as calling the original class method with the
795
     * any provided arguments instead of using a return value queue.
796
     *
797
     * @return Expectation
798
     */
799 3
    public function passthru()
800
    {
801 3
        if ($this->_mock instanceof Mock) {
802
            throw new Exception(
803
                'Mock Objects not created from a loaded/existing class are '
804
                . 'incapable of passing method calls through to a parent class'
805
            );
806
        }
807 3
        $this->_passthru = true;
808 3
        return $this;
809
    }
810
811
    /**
812
     * Cloning logic
813
     *
814
     */
815 10
    public function __clone()
816
    {
817 10
        $newValidators = array();
818 10
        $countValidators = $this->_countValidators;
819 10
        foreach ($countValidators as $validator) {
820 7
            $newValidators[] = clone $validator;
821
        }
822 10
        $this->_countValidators = $newValidators;
823 10
    }
824
825 7
    public function getName()
826
    {
827 7
        return $this->_name;
828
    }
829
}
830