Overview

Namespaces

  • Composer
    • Autoload
  • Guzzle
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Mock
    • Stream
  • Mockery
    • Adapter
      • Phpunit
    • CountValidator
    • Exception
    • Generator
      • StringManipulation
        • Pass
    • Loader
    • Matcher
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • Fatzebra
      • Message
  • PHP
  • Symfony
    • Component
      • EventDispatcher
        • Debug
        • DependencyInjection
        • Tests
          • Debug
          • DependencyInjection
      • HttpFoundation
        • File
          • Exception
          • MimeType
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
        • Tests
          • File
            • MimeType
          • Session
            • Attribute
            • Flash
            • Storage
              • Handler
              • Proxy
      • Yaml
        • Exception
        • Tests

Classes

  • Symfony\Component\Yaml\Tests\A
  • Symfony\Component\Yaml\Tests\B
  • Symfony\Component\Yaml\Tests\DumperTest
  • Symfony\Component\Yaml\Tests\InlineTest
  • Symfony\Component\Yaml\Tests\ParseExceptionTest
  • Symfony\Component\Yaml\Tests\ParserTest
  • Symfony\Component\Yaml\Tests\YamlTest
  • Overview
  • Namespace
  • Function
  • Tree
  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 padraic@php.net so we can send you a copy immediately.
 14:  *
 15:  * @category   Mockery
 16:  * @package    Mockery
 17:  * @copyright  Copyright (c) 2010-2014 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 Mockery\MockInterface;
 24: 
 25: class Mock implements MockInterface
 26: {
 27: 
 28:     /**
 29:      * Stores an array of all expectation directors for this mock
 30:      *
 31:      * @var array
 32:      */
 33:     protected $_mockery_expectations = array();
 34: 
 35:     /**
 36:      * Flag to indicate whether we can ignore method calls missing from our
 37:      * expectations
 38:      *
 39:      * @var bool
 40:      */
 41:     protected $_mockery_ignoreMissing = false;
 42: 
 43:     /**
 44:      * Flag to indicate whether we can defer method calls missing from our
 45:      * expectations
 46:      *
 47:      * @var bool
 48:      */
 49:     protected $_mockery_deferMissing = false;
 50: 
 51:     /**
 52:      * Flag to indicate whether this mock was verified
 53:      *
 54:      * @var bool
 55:      */
 56:     protected $_mockery_verified = false;
 57: 
 58:     /**
 59:      * Given name of the mock
 60:      *
 61:      * @var string
 62:      */
 63:     protected $_mockery_name = null;
 64: 
 65:     /**
 66:      * Order number of allocation
 67:      *
 68:      * @var int
 69:      */
 70:     protected $_mockery_allocatedOrder = 0;
 71: 
 72:     /**
 73:      * Current ordered number
 74:      *
 75:      * @var int
 76:      */
 77:     protected $_mockery_currentOrder = 0;
 78: 
 79:     /**
 80:      * Ordered groups
 81:      *
 82:      * @var array
 83:      */
 84:     protected $_mockery_groups = array();
 85: 
 86:     /**
 87:      * Mock container containing this mock object
 88:      *
 89:      * @var \Mockery\Container
 90:      */
 91:     protected $_mockery_container = null;
 92: 
 93:     /**
 94:      * Instance of a core object on which methods are called in the event
 95:      * it has been set, and an expectation for one of the object's methods
 96:      * does not exist. This implements a simple partial mock proxy system.
 97:      *
 98:      * @var object
 99:      */
100:     protected $_mockery_partial = null;
101: 
102:     /**
103:      * Flag to indicate we should ignore all expectations temporarily. Used
104:      * mainly to prevent expectation matching when in the middle of a mock
105:      * object recording session.
106:      *
107:      * @var bool
108:      */
109:     protected $_mockery_disableExpectationMatching = false;
110: 
111:     /**
112:      * Stores all stubbed public methods separate from any on-object public
113:      * properties that may exist.
114:      *
115:      * @var array
116:      */
117:     protected $_mockery_mockableProperties = array();
118: 
119:     /**
120:      * @var array
121:      */
122:     protected $_mockery_mockableMethods = array();
123: 
124:     /**
125:      * Just a local cache for this mock's target's methods
126:      *
127:      * @var ReflectionMethod[]
128:      */
129:     protected static $_mockery_methods;
130: 
131:     protected $_mockery_allowMockingProtectedMethods = false;
132: 
133:     protected $_mockery_receivedMethodCalls;
134: 
135:     /**
136:      * If shouldIgnoreMissing is called, this value will be returned on all calls to missing methods
137:      * @var mixed
138:      */
139:     protected $_mockery_defaultReturnValue = null;
140: 
141:     /**
142:      * We want to avoid constructors since class is copied to Generator.php
143:      * for inclusion on extending class definitions.
144:      *
145:      * @param \Mockery\Container $container
146:      * @param object $partialObject
147:      * @return void
148:      */
149:     public function mockery_init(\Mockery\Container $container = null, $partialObject = null)
150:     {
151:         if(is_null($container)) {
152:             $container = new \Mockery\Container;
153:         }
154:         $this->_mockery_container = $container;
155:         if (!is_null($partialObject)) {
156:             $this->_mockery_partial = $partialObject;
157:         }
158: 
159:         if (!\Mockery::getConfiguration()->mockingNonExistentMethodsAllowed()) {
160:             foreach ($this->mockery_getMethods() as $method) {
161:                 if ($method->isPublic() && !$method->isStatic()) $this->_mockery_mockableMethods[] = $method->getName();
162:             }
163:         }
164:     }
165: 
166:     /**
167:      * Set expected method calls
168:      *
169:      * @param mixed
170:      * @return \Mockery\Expectation
171:      */
172:     public function shouldReceive()
173:     {
174:         /** @var array $nonPublicMethods */
175:         $nonPublicMethods = $this->getNonPublicMethods();
176: 
177:         $self = $this;
178:         $allowMockingProtectedMethods = $this->_mockery_allowMockingProtectedMethods;
179: 
180:         $lastExpectation = \Mockery::parseShouldReturnArgs(
181:             $this, func_get_args(), function ($method) use ($self, $nonPublicMethods, $allowMockingProtectedMethods) {
182:                 $rm = $self->mockery_getMethod($method);
183:                 if ($rm) {
184:                     if ($rm->isPrivate()) {
185:                         throw new \InvalidArgumentException("$method() cannot be mocked as it is a private method");
186:                     }
187:                     if (!$allowMockingProtectedMethods && $rm->isProtected()) {
188:                         throw new \InvalidArgumentException("$method() cannot be mocked as it a protected method and mocking protected methods is not allowed for this mock");
189:                     }
190:                 }
191: 
192:                 $director = $self->mockery_getExpectationsFor($method);
193:                 if (!$director) {
194:                     $director = new \Mockery\ExpectationDirector($method, $self);
195:                     $self->mockery_setExpectationsFor($method, $director);
196:                 }
197:                 $expectation = new \Mockery\Expectation($self, $method);
198:                 $director->addExpectation($expectation);
199:                 return $expectation;
200:             }
201:         );
202:         return $lastExpectation;
203:     }
204: 
205:     /**
206:      * Allows additional methods to be mocked that do not explicitly exist on mocked class
207:      * @param String $method name of the method to be mocked
208:      * @return Mock
209:      */
210:     public function shouldAllowMockingMethod($method)
211:     {
212:         $this->_mockery_mockableMethods[] = $method;
213:         return $this;
214:     }
215: 
216:     /**
217:      * Set mock to ignore unexpected methods and return Undefined class
218:      * @param mixed $returnValue the default return value for calls to missing functions on this mock
219:      * @return Mock
220:      */
221:     public function shouldIgnoreMissing($returnValue = null)
222:     {
223:         $this->_mockery_ignoreMissing = true;
224:         $this->_mockery_defaultReturnValue = $returnValue;
225:         return $this;
226:     }
227: 
228:     public function asUndefined()
229:     {
230:         $this->_mockery_ignoreMissing = true;
231:         $this->_mockery_defaultReturnValue = new \Mockery\Undefined;
232:         return $this;
233:     }
234: 
235:     /**
236:      * @return Mock
237:      */
238:     public function shouldAllowMockingProtectedMethods()
239:     {
240:         $this->_mockery_allowMockingProtectedMethods = true;
241:         return $this;
242:     }
243: 
244: 
245:     /**
246:      * Set mock to defer unexpected methods to it's parent
247:      *
248:      * This is particularly useless for this class, as it doesn't have a parent,
249:      * but included for completeness
250:      *
251:      * @return Mock
252:      */
253:     public function shouldDeferMissing()
254:     {
255:         $this->_mockery_deferMissing = true;
256:         return $this;
257:     }
258: 
259:     /**
260:      * Create an obviously worded alias to shouldDeferMissing()
261:      *
262:      * @return Mock
263:      */
264:     public function makePartial()
265:     {
266:         return $this->shouldDeferMissing();
267:     }
268: 
269:     /**
270:      * Accepts a closure which is executed with an object recorder which proxies
271:      * to the partial source object. The intent being to record the
272:      * interactions of a concrete object as a set of expectations on the
273:      * current mock object. The partial may then be passed to a second process
274:      * to see if it fulfils the same (or exact same) contract as the original.
275:      *
276:      * @param Closure $closure
277:      */
278:     public function shouldExpect(\Closure $closure)
279:     {
280:         $recorder = new \Mockery\Recorder($this, $this->_mockery_partial);
281:         $this->_mockery_disableExpectationMatching = true;
282:         $closure($recorder);
283:         $this->_mockery_disableExpectationMatching = false;
284:         return $this;
285:     }
286: 
287:     /**
288:      * In the event shouldReceive() accepting one or more methods/returns,
289:      * this method will switch them from normal expectations to default
290:      * expectations
291:      *
292:      * @return self
293:      */
294:     public function byDefault()
295:     {
296:         foreach ($this->_mockery_expectations as $director) {
297:             $exps = $director->getExpectations();
298:             foreach ($exps as $exp) {
299:                 $exp->byDefault();
300:             }
301:         }
302:         return $this;
303:     }
304: 
305:     /**
306:      * Capture calls to this mock
307:      */
308:     public function __call($method, array $args)
309:     {
310:         return $this->_mockery_handleMethodCall($method, $args);
311:     }
312: 
313:     public static function __callStatic($method, array $args)
314:     {
315:         return self::_mockery_handleStaticMethodCall($method, $args);
316:     }
317: 
318:     /**
319:      * Forward calls to this magic method to the __call method
320:      */
321:     public function __toString()
322:     {
323:         return $this->__call('__toString', array());
324:     }
325: 
326:     /**public function __set($name, $value)
327:     {
328:         $this->_mockery_mockableProperties[$name] = $value;
329:         return $this;
330:     }
331: 
332:     public function __get($name)
333:     {
334:         if (isset($this->_mockery_mockableProperties[$name])) {
335:             return $this->_mockery_mockableProperties[$name];
336:         } elseif(isset($this->{$name})) {
337:             return $this->{$name};
338:         }
339:         throw new \InvalidArgumentException (
340:             'Property ' . __CLASS__ . '::' . $name . ' does not exist on this mock object'
341:         );
342:     }**/
343: 
344:     /**
345:      * Iterate across all expectation directors and validate each
346:      *
347:      * @throws \Mockery\CountValidator\Exception
348:      * @return void
349:      */
350:     public function mockery_verify()
351:     {
352:         if ($this->_mockery_verified) return true;
353:         if (isset($this->_mockery_ignoreVerification)
354:             && $this->_mockery_ignoreVerification == true) {
355:             return true;
356:         }
357:         $this->_mockery_verified = true;
358:         foreach($this->_mockery_expectations as $director) {
359:             $director->verify();
360:         }
361:     }
362: 
363:     /**
364:      * Tear down tasks for this mock
365:      *
366:      * @return void
367:      */
368:     public function mockery_teardown()
369:     {
370: 
371:     }
372: 
373:     /**
374:      * Fetch the next available allocation order number
375:      *
376:      * @return int
377:      */
378:     public function mockery_allocateOrder()
379:     {
380:         $this->_mockery_allocatedOrder += 1;
381:         return $this->_mockery_allocatedOrder;
382:     }
383: 
384:     /**
385:      * Set ordering for a group
386:      *
387:      * @param mixed $group
388:      * @param int $order
389:      */
390:     public function mockery_setGroup($group, $order)
391:     {
392:         $this->_mockery_groups[$group] = $order;
393:     }
394: 
395:     /**
396:      * Fetch array of ordered groups
397:      *
398:      * @return array
399:      */
400:     public function mockery_getGroups()
401:     {
402:         return $this->_mockery_groups;
403:     }
404: 
405:     /**
406:      * Set current ordered number
407:      *
408:      * @param int $order
409:      */
410:     public function mockery_setCurrentOrder($order)
411:     {
412:         $this->_mockery_currentOrder = $order;
413:         return $this->_mockery_currentOrder;
414:     }
415: 
416:     /**
417:      * Get current ordered number
418:      *
419:      * @return int
420:      */
421:     public function mockery_getCurrentOrder()
422:     {
423:         return $this->_mockery_currentOrder;
424:     }
425: 
426:     /**
427:      * Validate the current mock's ordering
428:      *
429:      * @param string $method
430:      * @param int $order
431:      * @throws \Mockery\Exception
432:      * @return void
433:      */
434:     public function mockery_validateOrder($method, $order)
435:     {
436:         if ($order < $this->_mockery_currentOrder) {
437:             $exception = new \Mockery\Exception\InvalidOrderException(
438:                 'Method ' . __CLASS__ . '::' . $method . '()'
439:                 . ' called out of order: expected order '
440:                 . $order . ', was ' . $this->_mockery_currentOrder
441:             );
442:             $exception->setMock($this)
443:                 ->setMethodName($method)
444:                 ->setExpectedOrder($order)
445:                 ->setActualOrder($this->_mockery_currentOrder);
446:             throw $exception;
447:         }
448:         $this->mockery_setCurrentOrder($order);
449:     }
450: 
451:     /**
452:      * Gets the count of expectations for this mock
453:      *
454:      * @return int
455:      */
456:     public function mockery_getExpectationCount()
457:     {
458:         $count = 0;
459:         foreach($this->_mockery_expectations as $director) {
460:             $count += $director->getExpectationCount();
461:         }
462:         return $count;
463:     }
464: 
465:     /**
466:      * Return the expectations director for the given method
467:      *
468:      * @var string $method
469:      * @return \Mockery\ExpectationDirector|null
470:      */
471:     public function mockery_setExpectationsFor($method, \Mockery\ExpectationDirector $director)
472:     {
473:         $this->_mockery_expectations[$method] = $director;
474:     }
475: 
476:     /**
477:      * Return the expectations director for the given method
478:      *
479:      * @var string $method
480:      * @return \Mockery\ExpectationDirector|null
481:      */
482:     public function mockery_getExpectationsFor($method)
483:     {
484:         if (isset($this->_mockery_expectations[$method])) {
485:             return $this->_mockery_expectations[$method];
486:         }
487:     }
488: 
489:     /**
490:      * Find an expectation matching the given method and arguments
491:      *
492:      * @var string $method
493:      * @var array $args
494:      * @return \Mockery\Expectation|null
495:      */
496:     public function mockery_findExpectation($method, array $args)
497:     {
498:         if (!isset($this->_mockery_expectations[$method])) {
499:             return null;
500:         }
501:         $director = $this->_mockery_expectations[$method];
502: 
503:         return $director->findExpectation($args);
504:     }
505: 
506:     /**
507:      * Return the container for this mock
508:      *
509:      * @return \Mockery\Container
510:      */
511:     public function mockery_getContainer()
512:     {
513:         return $this->_mockery_container;
514:     }
515: 
516:     /**
517:      * Return the name for this mock
518:      *
519:      * @return string
520:      */
521:     public function mockery_getName()
522:     {
523:         return __CLASS__;
524:     }
525: 
526:     /**
527:      * @return array
528:      */
529:     public function mockery_getMockableProperties()
530:     {
531:         return $this->_mockery_mockableProperties;
532:     }
533: 
534:     public function __isset($name)
535:     {
536:         if (false === stripos($name, '_mockery_') && method_exists(get_parent_class($this), '__isset')) {
537:             return parent::__isset($name);
538:         }
539:     }
540: 
541:     public function mockery_getExpectations()
542:     {
543:         return $this->_mockery_expectations;
544:     }
545: 
546:     /**
547:      * Calls a parent class method and returns the result. Used in a passthru
548:      * expectation where a real return value is required while still taking
549:      * advantage of expectation matching and call count verification.
550:      *
551:      * @param string $name
552:      * @param array $args
553:      * @return mixed
554:      */
555:     public function mockery_callSubjectMethod($name, array $args)
556:     {
557:         return call_user_func_array('parent::' . $name, $args);
558:     }
559: 
560:     /**
561:      * @return string[]
562:      */
563:     public function mockery_getMockableMethods()
564:     {
565:         return $this->_mockery_mockableMethods;
566:     }
567: 
568:     /**
569:      * @return bool
570:      */
571:     public function mockery_isAnonymous()
572:     {
573:         $rfc = new \ReflectionClass($this);
574:         return false === $rfc->getParentClass();
575:     }
576: 
577:     public function __wakeup()
578:     {
579:         /**
580:          * This does not add __wakeup method support. It's a blind method and any
581:          * expected __wakeup work will NOT be performed. It merely cuts off
582:          * annoying errors where a __wakeup exists but is not essential when
583:          * mocking
584:          */
585:     }
586: 
587:     public function mockery_getMethod($name)
588:     {
589:         foreach ($this->mockery_getMethods() as $method) {
590:             if ($method->getName() == $name) {
591:                 return $method;
592:             }
593:         }
594: 
595:         return null;
596:     }
597: 
598:     public function shouldHaveReceived($method, $args = null)
599:     {
600:         $expectation = new \Mockery\VerificationExpectation($this, $method);
601:         if (null !== $args) {
602:             $expectation->withArgs($args);
603:         }
604:         $expectation->atLeast()->once();
605:         $director = new \Mockery\VerificationDirector($this->_mockery_getReceivedMethodCalls(), $expectation);
606:         $director->verify();
607:         return $director;
608:     }
609: 
610:     public function shouldNotHaveReceived($method, $args = null)
611:     {
612:         $expectation = new \Mockery\VerificationExpectation($this, $method);
613:         if (null !== $args) {
614:             $expectation->withArgs($args);
615:         }
616:         $expectation->never();
617:         $director = new \Mockery\VerificationDirector($this->_mockery_getReceivedMethodCalls(), $expectation);
618:         $director->verify();
619:         return null;
620:     }
621: 
622:     protected static function _mockery_handleStaticMethodCall($method, array $args)
623:     {
624:         try {
625:             $associatedRealObject = \Mockery::fetchMock(__CLASS__);
626:             return $associatedRealObject->__call($method, $args);
627:         } catch (\BadMethodCallException $e) {
628:             throw new \BadMethodCallException(
629:                 'Static method ' . $associatedRealObject->mockery_getName() . '::' . $method
630:                 . '() does not exist on this mock object'
631:             );
632:         }
633:     }
634: 
635:     protected function _mockery_getReceivedMethodCalls()
636:     {
637:         return $this->_mockery_receivedMethodCalls ?: $this->_mockery_receivedMethodCalls = new \Mockery\ReceivedMethodCalls();
638:     }
639: 
640:     protected function _mockery_handleMethodCall($method, array $args)
641:     {
642:         $this->_mockery_getReceivedMethodCalls()->push(new \Mockery\MethodCall($method, $args));
643: 
644:         $rm = $this->mockery_getMethod($method);
645:         if ($rm && $rm->isProtected() && !$this->_mockery_allowMockingProtectedMethods) {
646:             if ($rm->isAbstract()) {
647:                 return;
648:             }
649: 
650:             try {
651:                 $prototype = $rm->getPrototype();
652:                 if ($prototype->isAbstract()) {
653:                     return;
654:                 }
655:             } catch (\ReflectionException $re) {
656:                 // noop - there is no hasPrototype method
657:             }
658: 
659:             return call_user_func_array("parent::$method", $args);
660:         }
661: 
662:         if (isset($this->_mockery_expectations[$method])
663:         && !$this->_mockery_disableExpectationMatching) {
664:             $handler = $this->_mockery_expectations[$method];
665: 
666:             try {
667:                 return $handler->call($args);
668:             } catch (\Mockery\Exception\NoMatchingExpectationException $e) {
669:                 if (!$this->_mockery_ignoreMissing && !$this->_mockery_deferMissing) {
670:                     throw $e;
671:                 }
672:             }
673:         }
674: 
675:         if (!is_null($this->_mockery_partial) && method_exists($this->_mockery_partial, $method)) {
676:             return call_user_func_array(array($this->_mockery_partial, $method), $args);
677:         } elseif ($this->_mockery_deferMissing && is_callable("parent::$method")) {
678:             return call_user_func_array("parent::$method", $args);
679:         } elseif ($method == '__toString') {
680:             // __toString is special because we force its addition to the class API regardless of the
681:             // original implementation.  Thus, we should always return a string rather than honor
682:             // _mockery_ignoreMissing and break the API with an error.
683:             return sprintf("%s#%s", __CLASS__, spl_object_hash($this));
684:         } elseif ($this->_mockery_ignoreMissing) {
685:             if ($this->_mockery_defaultReturnValue instanceof \Mockery\Undefined)
686:                 return call_user_func_array(array($this->_mockery_defaultReturnValue, $method), $args);
687:             else
688:                 return $this->_mockery_defaultReturnValue;
689:         }
690:         throw new \BadMethodCallException(
691:             'Method ' . __CLASS__ . '::' . $method . '() does not exist on this mock object'
692:         );
693:     }
694: 
695:     protected function mockery_getMethods()
696:     {
697:         if (static::$_mockery_methods) {
698:             return static::$_mockery_methods;
699:         }
700: 
701:         $methods = array();
702: 
703:         if (isset($this->_mockery_partial)) {
704:             $reflected = new \ReflectionObject($this->_mockery_partial);
705:             $methods = $reflected->getMethods();
706:         } else {
707:             $reflected = new \ReflectionClass($this);
708:             foreach ($reflected->getMethods() as $method) {
709:                 try {
710:                     $methods[] = $method->getPrototype();
711:                 } catch (\ReflectionException $re) {
712:                     /**
713:                      * For some reason, private methods don't have a prototype
714:                      */
715:                     if ($method->isPrivate()) {
716:                         $methods[] = $method;
717:                     }
718:                 }
719:             }
720:         }
721: 
722:         return static::$_mockery_methods = $methods;
723:     }
724: 
725:     /**
726:      * @return array
727:      */
728:     private function getNonPublicMethods()
729:     {
730:         return array_map(
731:             function ($method) {
732:                 return $method->getName();
733:             },
734:             array_filter($this->mockery_getMethods(), function ($method) {
735:                 return !$method->isPublic();
736:             })
737:         );
738:     }
739: 
740: }
741: 
Omnipay Fat Zebra / Paystream Gateway Module API Documentation API documentation generated by ApiGen