TestConsoleOutput.php 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. App::uses('ConsoleOutput', 'Console');
  3. /**
  4. * Use as
  5. *
  6. * App::uses('TestConsoleOutput', 'Tools.TestSuite');
  7. *
  8. * $stdOut = new TestConsoleOutput();
  9. * $this->MyShell = new MyShell($stdOut);
  10. *
  11. * @license http://opensource.org/licenses/mit-license.php MIT
  12. * @author Mark Scherer
  13. */
  14. class TestConsoleOutput extends ConsoleOutput {
  15. /**
  16. * Holds all output messages.
  17. *
  18. * @var array
  19. */
  20. public $output = [];
  21. /**
  22. * Overwrite _write to output the message to debug instead of CLI.
  23. *
  24. * @param string $message
  25. * @return void
  26. */
  27. protected function _write($message) {
  28. if (!empty($_GET['debug']) || !empty($_SERVER['argv']) && (in_array('-v', $_SERVER['argv'], true) || in_array('-vv', $_SERVER['argv'], true))) {
  29. debug($message);
  30. }
  31. $this->output[] = $message;
  32. }
  33. /**
  34. * Helper method to return the debug output as string.
  35. *
  36. * @return string
  37. */
  38. public function output() {
  39. return implode('', $this->output);
  40. }
  41. }