ToolsTestTrait.php 911 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Tools\TestSuite\Traits;
  3. /**
  4. * Utility methods for easier testing in CakePHP & PHPUnit
  5. */
  6. trait ToolsTestTrait {
  7. /**
  8. * OsFix method
  9. *
  10. * @param string $string
  11. * @return string
  12. */
  13. protected static function _osFix($string) {
  14. return str_replace(array("\r\n", "\r"), "\n", $string);
  15. }
  16. /**
  17. * Outputs debug information during a test run.
  18. * This is a convenience output handler since debug() itself is not desired
  19. * for tests in general.
  20. *
  21. * Force flushing the output
  22. *
  23. * @param mixed $data
  24. * @param bool $force Should the output be flushed (forced)
  25. * @return void
  26. */
  27. protected static function debug($data) {
  28. $output = !empty($_SERVER['argv']) && (in_array('-v', $_SERVER['argv'], true) || in_array('-vv', $_SERVER['argv'], true));
  29. if (!$output) {
  30. return;
  31. }
  32. $showFrom = in_array('-vv', $_SERVER['argv'], true);
  33. debug($data, null, $showFrom);
  34. }
  35. }