TestHelpers.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Mpociot\ApiDoc\Tests;
  3. use Illuminate\Contracts\Console\Kernel;
  4. trait TestHelpers
  5. {
  6. /**
  7. * @param string $command
  8. * @param array $parameters
  9. *
  10. * @return mixed
  11. */
  12. public function artisan($command, $parameters = [])
  13. {
  14. $this->app[Kernel::class]->call($command, $parameters);
  15. return $this->app[Kernel::class]->output();
  16. }
  17. private function assertFilesHaveSameContent($pathToExpected, $pathToActual)
  18. {
  19. $actual = $this->getFileContents($pathToActual);
  20. $expected = $this->getFileContents($pathToExpected);
  21. $this->assertSame($expected, $actual);
  22. }
  23. /**
  24. * Get the contents of a file in a cross-platform-compatible way.
  25. *
  26. * @param $path
  27. *
  28. * @return string
  29. */
  30. private function getFileContents($path)
  31. {
  32. return str_replace("\r\n", "\n", file_get_contents($path));
  33. }
  34. /**
  35. * Assert that a string contains another string, ignoring all whitespace.
  36. *
  37. * @param $needle
  38. * @param $haystack
  39. */
  40. private function assertContainsIgnoringWhitespace($needle, $haystack)
  41. {
  42. $haystack = preg_replace('/\s/', '', $haystack);
  43. $needle = preg_replace('/\s/', '', $needle);
  44. $this->assertStringContainsString($needle, $haystack);
  45. }
  46. }