FilesystemTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace think\tests;
  3. use Mockery as m;
  4. use Mockery\MockInterface;
  5. use org\bovigo\vfs\vfsStream;
  6. use org\bovigo\vfs\vfsStreamDirectory;
  7. use PHPUnit\Framework\TestCase;
  8. use think\App;
  9. use think\Config;
  10. use think\Container;
  11. use think\Filesystem;
  12. use think\filesystem\driver\Local;
  13. class FilesystemTest extends TestCase
  14. {
  15. /** @var App|MockInterface */
  16. protected $app;
  17. /** @var Filesystem */
  18. protected $filesystem;
  19. /** @var Config|MockInterface */
  20. protected $config;
  21. /** @var vfsStreamDirectory */
  22. protected $root;
  23. protected function setUp(): void
  24. {
  25. $this->app = m::mock(App::class)->makePartial();
  26. Container::setInstance($this->app);
  27. $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app);
  28. $this->config = m::mock(Config::class);
  29. $this->config->shouldReceive('get')->with('filesystem.default', null)->andReturn('local');
  30. $this->app->shouldReceive('get')->with('config')->andReturn($this->config);
  31. $this->filesystem = new Filesystem($this->app);
  32. $this->root = vfsStream::setup('rootDir');
  33. }
  34. protected function tearDown(): void
  35. {
  36. m::close();
  37. }
  38. public function testDisk()
  39. {
  40. $this->config->shouldReceive('get')->with('filesystem.disks.local', null)->andReturn([
  41. 'type' => 'local',
  42. 'root' => $this->root->url(),
  43. ]);
  44. $this->config->shouldReceive('get')->with('filesystem.disks.foo', null)->andReturn([
  45. 'type' => 'local',
  46. 'root' => $this->root->url(),
  47. ]);
  48. $this->assertInstanceOf(Local::class, $this->filesystem->disk());
  49. $this->assertInstanceOf(Local::class, $this->filesystem->disk('foo'));
  50. }
  51. }