LimeMockReplayState.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Lime test 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. * The state of the mock during replay mode.
  13. *
  14. * In this state, invoked methods are verified automatically. If a method
  15. * was expected to be called, the configured return value of the method is
  16. * returned. If it was not expected, an exception is thrown instead.
  17. *
  18. * @package Lime
  19. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  20. * @version SVN: $Id: LimeMockReplayState.php 23880 2009-11-14 10:14:34Z bschussek $
  21. */
  22. class LimeMockReplayState implements LimeMockStateInterface
  23. {
  24. protected
  25. $behaviour = null;
  26. /**
  27. * Constructor.
  28. *
  29. * @param LimeMockBehaviourInterface $behaviour The behaviour on which this
  30. * state operates.
  31. */
  32. public function __construct(LimeMockBehaviourInterface $behaviour)
  33. {
  34. $this->behaviour = $behaviour;
  35. }
  36. /**
  37. * (non-PHPdoc)
  38. * @see mock/LimeMockStateInterface#invoke($class, $method, $parameters)
  39. */
  40. public function invoke(LimeMockMethod $method, array $parameters = null)
  41. {
  42. return $this->behaviour->invoke(new LimeMockInvocation($method, is_null($parameters) ? array() : $parameters));
  43. }
  44. /**
  45. * (non-PHPdoc)
  46. * @see mock/LimeMockStateInterface#isInvokable($method)
  47. */
  48. public function isInvokable(LimeMockMethod $method)
  49. {
  50. return $this->behaviour->isInvokable($method);
  51. }
  52. /**
  53. * (non-PHPdoc)
  54. * @see mock/LimeMockStateInterface#setExpectNothing()
  55. */
  56. public function setExpectNothing()
  57. {
  58. throw new BadMethodCallException('setExpectNothing() must be called before replay()');
  59. }
  60. /**
  61. * (non-PHPdoc)
  62. * @see mock/LimeMockStateInterface#verify()
  63. */
  64. public function verify()
  65. {
  66. return $this->behaviour->verify();
  67. }
  68. }