CacheTableCommandTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Illuminate\Tests\Cache;
  3. use Illuminate\Cache\Console\CacheTableCommand;
  4. use Illuminate\Database\Migrations\MigrationCreator;
  5. use Illuminate\Filesystem\Filesystem;
  6. use Illuminate\Foundation\Application;
  7. use Illuminate\Support\Composer;
  8. use Mockery as m;
  9. use PHPUnit\Framework\TestCase;
  10. use Symfony\Component\Console\Input\ArrayInput;
  11. use Symfony\Component\Console\Output\NullOutput;
  12. class CacheTableCommandTest extends TestCase
  13. {
  14. protected function tearDown(): void
  15. {
  16. m::close();
  17. }
  18. public function testCreateMakesMigration()
  19. {
  20. $command = new CacheTableCommandTestStub(
  21. $files = m::mock(Filesystem::class),
  22. $composer = m::mock(Composer::class)
  23. );
  24. $creator = m::mock(MigrationCreator::class)->shouldIgnoreMissing();
  25. $app = new Application;
  26. $app->useDatabasePath(__DIR__);
  27. $app['migration.creator'] = $creator;
  28. $command->setLaravel($app);
  29. $path = __DIR__.'/migrations';
  30. $creator->shouldReceive('create')->once()->with('create_cache_table', $path)->andReturn($path);
  31. $files->shouldReceive('get')->once()->andReturn('foo');
  32. $files->shouldReceive('put')->once()->with($path, 'foo');
  33. $composer->shouldReceive('dumpAutoloads')->once();
  34. $this->runCommand($command);
  35. }
  36. protected function runCommand($command, $input = [])
  37. {
  38. return $command->run(new ArrayInput($input), new NullOutput);
  39. }
  40. }
  41. class CacheTableCommandTestStub extends CacheTableCommand
  42. {
  43. public function call($command, array $arguments = [])
  44. {
  45. return 0;
  46. }
  47. }