LimeMockUnorderedBehaviour.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * A behaviour that allows methods to be invoked in the any order.
  4. *
  5. * @package Lime
  6. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. * @version SVN: $Id: LimeMockUnorderedBehaviour.php 23864 2009-11-13 18:06:20Z bschussek $
  8. * @see LimeMockBehaviourInterface
  9. */
  10. class LimeMockUnorderedBehaviour extends LimeMockBehaviour
  11. {
  12. /**
  13. * (non-PHPdoc)
  14. * @see mock/LimeMockBehaviour#invoke($invocation)
  15. */
  16. public function invoke(LimeMockInvocation $invocation)
  17. {
  18. $exceptionStack = new LimeMockInvocationExceptionStack();
  19. foreach ($this->invocations as $invocationExpectation)
  20. {
  21. try
  22. {
  23. if ($invocationExpectation->matches($invocation))
  24. {
  25. return $invocationExpectation->invoke($invocation);
  26. }
  27. }
  28. catch (LimeMockInvocationException $e)
  29. {
  30. // make sure to test all expectations
  31. $exceptionStack->add($e);
  32. }
  33. }
  34. // no invocation matched and at least one exception was thrown
  35. if (!$exceptionStack->isEmpty())
  36. {
  37. throw $exceptionStack;
  38. }
  39. parent::invoke($invocation);
  40. }
  41. }