LimeMockInvocationExceptionStack.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * Collects a number of LimeMockInvocationException objects.
  13. *
  14. * @package Lime
  15. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  16. * @version SVN: $Id: LimeMockInvocationExceptionStack.php 24352 2009-11-24 19:49:42Z bschussek $
  17. */
  18. class LimeMockInvocationExceptionStack extends LimeMockInvocationException
  19. {
  20. protected
  21. $exceptions = array();
  22. /**
  23. * Ignores the parent constructor.
  24. */
  25. public function __construct() {}
  26. /**
  27. * Adds a new exception to the stack.
  28. *
  29. * The stack message is updated to contain the message of the exception.
  30. *
  31. * @param LimeMockInvocationException $exception
  32. */
  33. public function add(LimeMockInvocationException $exception)
  34. {
  35. $this->exceptions[] = $exception;
  36. if (count($this->exceptions) > 1)
  37. {
  38. $this->message = "One of the following errors occured:\n";
  39. for ($i = 1; $i <= count($this->exceptions); ++$i)
  40. {
  41. $message = LimeTools::indent(wordwrap($this->exceptions[$i-1]->getMessage(), 70), strlen($i)+2);
  42. $this->message .= sprintf("%s) %s\n", $i, trim($message));
  43. }
  44. }
  45. else
  46. {
  47. $this->message = $this->exceptions[0]->getMessage();
  48. }
  49. }
  50. /**
  51. * Returns TRUE when the stack contains no exceptions, FALSE otherwise.
  52. *
  53. * @return boolean
  54. */
  55. public function isEmpty()
  56. {
  57. return count($this->exceptions) == 0;
  58. }
  59. }