TestHelpers.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. protected function generate(array $flags = []): mixed
  20. {
  21. return $this->artisan(
  22. 'scribe:generate', array_merge(['--no-upgrade-check' => true], $flags)
  23. );
  24. }
  25. protected function generateAndExpectConsoleOutput(string ...$expectedOutput): void
  26. {
  27. $output = $this->generate();
  28. foreach ($expectedOutput as $expected) {
  29. $this->assertStringContainsString($expected, $output);
  30. }
  31. }
  32. protected function assertFileContainsString(string $filePath, string $string)
  33. {
  34. $this->assertFileExists($filePath);
  35. $fileContents = file_get_contents($filePath);
  36. $this->assertStringContainsString($string, $fileContents);
  37. }
  38. }