TestHelpers.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Knuckles\Scribe\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. /** @var Kernel $kernel */
  15. $kernel = $this->app[Kernel::class];
  16. $kernel->call($command, $parameters);
  17. return $kernel->output();
  18. }
  19. private function assertFilesHaveSameContent($pathToExpected, $pathToActual)
  20. {
  21. $actual = $this->getFileContents($pathToActual);
  22. $expected = $this->getFileContents($pathToExpected);
  23. $this->assertSame($expected, $actual);
  24. }
  25. /**
  26. * Get the contents of a file in a cross-platform-compatible way.
  27. *
  28. * @param $path
  29. *
  30. * @return string
  31. */
  32. private function getFileContents($path)
  33. {
  34. return str_replace("\r\n", "\n", file_get_contents($path));
  35. }
  36. /**
  37. * Assert that a string contains another string, ignoring all whitespace.
  38. *
  39. * @param $needle
  40. * @param $haystack
  41. */
  42. private function assertContainsIgnoringWhitespace($needle, $haystack)
  43. {
  44. $haystack = preg_replace('/\s/', '', $haystack);
  45. $needle = preg_replace('/\s/', '', $needle);
  46. $this->assertStringContainsString($needle, $haystack);
  47. }
  48. }