LimeMockOrderedBehaviour.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. /**
  12. * A behaviour that requires methods to be invoked in the same order as they
  13. * were expected.
  14. *
  15. * @package Lime
  16. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  17. * @version SVN: $Id: LimeMockOrderedBehaviour.php 23701 2009-11-08 21:23:40Z bschussek $
  18. * @see LimeMockBehaviourInterface
  19. */
  20. class LimeMockOrderedBehaviour extends LimeMockBehaviour
  21. {
  22. protected
  23. $cursor = 0;
  24. /**
  25. * (non-PHPdoc)
  26. * @see mock/LimeMockBehaviour#invoke($invocation)
  27. */
  28. public function invoke(LimeMockInvocation $invocation)
  29. {
  30. if (array_key_exists($this->cursor, $this->invocations))
  31. {
  32. $invocationExpectation = $this->invocations[$this->cursor];
  33. if ($invocationExpectation->matches($invocation) && $invocationExpectation->isInvokable())
  34. {
  35. return $invocationExpectation->invoke($invocation);
  36. }
  37. else if ($invocationExpectation->isSatisfied())
  38. {
  39. $this->cursor++;
  40. return $this->invoke($invocation);
  41. }
  42. }
  43. parent::invoke($invocation);
  44. }
  45. }