GetWithMetadataTests.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. use League\Flysystem\Plugin\GetWithMetadata;
  3. use PHPUnit\Framework\TestCase;
  4. class GetWithMetadataTests extends TestCase
  5. {
  6. /**
  7. * @var \Prophecy\Prophecy\ObjectProphecy
  8. */
  9. private $prophecy;
  10. /**
  11. * @var FilesystemInterface
  12. */
  13. private $filesystem;
  14. /**
  15. * @before
  16. */
  17. public function setupFilesystem()
  18. {
  19. $this->prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
  20. $this->filesystem = $this->prophecy->reveal();
  21. }
  22. public function testGetMethod()
  23. {
  24. $plugin = new GetWithMetadata();
  25. $this->assertEquals('getWithMetadata', $plugin->getMethod());
  26. }
  27. public function testHandle()
  28. {
  29. $this->prophecy->getMetadata('path.txt')->willReturn([
  30. 'path' => 'path.txt',
  31. 'type' => 'file',
  32. ]);
  33. $this->prophecy->getMimetype('path.txt')->willReturn('text/plain');
  34. $plugin = new GetWithMetadata();
  35. $plugin->setFilesystem($this->filesystem);
  36. $output = $plugin->handle('path.txt', ['mimetype']);
  37. $this->assertEquals([
  38. 'path' => 'path.txt',
  39. 'type' => 'file',
  40. 'mimetype' => 'text/plain',
  41. ], $output);
  42. }
  43. public function testHandleFail()
  44. {
  45. $this->prophecy->getMetadata('path.txt')->willReturn(false);
  46. $plugin = new GetWithMetadata();
  47. $plugin->setFilesystem($this->filesystem);
  48. $output = $plugin->handle('path.txt', ['mimetype']);
  49. $this->assertFalse($output);
  50. }
  51. public function testHandleInvalid()
  52. {
  53. $this->expectException('InvalidArgumentException');
  54. $this->prophecy->getMetadata('path.txt')->willReturn([
  55. 'path' => 'path.txt',
  56. 'type' => 'file',
  57. ]);
  58. $plugin = new GetWithMetadata();
  59. $plugin->setFilesystem($this->filesystem);
  60. $output = $plugin->handle('path.txt', ['invalid']);
  61. }
  62. }