LimeAssertionFailedException.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. class LimeAssertionFailedException extends Exception
  12. {
  13. private
  14. $actual = '',
  15. $expected = '';
  16. public function __construct($actual, $expected)
  17. {
  18. parent::__construct(sprintf('Got: %s, Expected: %s', $actual, $expected));
  19. $this->actual = (string)$actual;
  20. $this->expected = (string)$expected;
  21. }
  22. public function getActual($indentation = 0)
  23. {
  24. if ($indentation > 0)
  25. {
  26. return $this->indent($this->actual, $indentation);
  27. }
  28. else
  29. {
  30. return $this->actual;
  31. }
  32. }
  33. public function getExpected($indentation = 0)
  34. {
  35. if ($indentation > 0)
  36. {
  37. return $this->indent($this->expected, $indentation);
  38. }
  39. else
  40. {
  41. return $this->expected;
  42. }
  43. }
  44. protected function indent($lines, $indentation = 2)
  45. {
  46. $lines = explode("\n", $lines);
  47. foreach ($lines as $key => $line)
  48. {
  49. $lines[$key] = str_repeat(' ', $indentation).$line;
  50. }
  51. return trim(implode("\n", $lines));
  52. }
  53. }