ListWithTests.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace League\Flysystem\Adapter;
  3. use InvalidArgumentException;
  4. use League\Flysystem\Filesystem;
  5. use League\Flysystem\Plugin\ListWith;
  6. use PHPUnit\Framework\TestCase;
  7. class ListWithTests extends TestCase
  8. {
  9. /**
  10. * @var Filesystem
  11. */
  12. private $filesystem;
  13. protected function setUp(): void
  14. {
  15. $this->filesystem = new Filesystem(new Local(__DIR__.'/../test_files/list_with'));
  16. }
  17. protected function tearDown(): void
  18. {
  19. $fs = new Filesystem(new Local(__DIR__.'/../test_files/'));
  20. $fs->deleteDir('list_with');
  21. }
  22. public function testHandle()
  23. {
  24. $this->filesystem->write('path.txt', 'contents');
  25. $plugin = new ListWith();
  26. $plugin->setFilesystem($this->filesystem);
  27. $this->assertEquals('listWith', $plugin->getMethod());
  28. $listing = $plugin->handle(['mimetype'], '', true);
  29. $this->assertContainsOnly('array', $listing, true);
  30. $first = reset($listing);
  31. $this->assertArrayHasKey('mimetype', $first);
  32. }
  33. public function testInvalidInput()
  34. {
  35. $this->filesystem->write('path.txt', 'contents');
  36. $this->expectException(InvalidArgumentException::class);
  37. $plugin = new ListWith();
  38. $plugin->setFilesystem($this->filesystem);
  39. $plugin->handle(['invalid'], '', true);
  40. }
  41. }