ForcedRenamePluginTests.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use League\Flysystem\Plugin\ForcedRename;
  3. use PHPUnit\Framework\TestCase;
  4. class ForcedRenamePluginTests extends TestCase
  5. {
  6. protected $filesystem;
  7. protected $plugin;
  8. public function setUp(): void
  9. {
  10. $this->filesystem = $this->prophesize('League\Flysystem\FilesystemInterface');
  11. $this->plugin = new ForcedRename();
  12. $this->plugin->setFilesystem($this->filesystem->reveal());
  13. }
  14. public function testPluginSuccess()
  15. {
  16. $this->assertSame('forceRename', $this->plugin->getMethod());
  17. $this->filesystem->delete('newpath')->willReturn(true)->shouldBeCalled();
  18. $this->filesystem->rename('path', 'newpath')->willReturn(true)->shouldBeCalled();
  19. $this->assertTrue($this->plugin->handle('path', 'newpath'));
  20. }
  21. public function testPluginDeleteNotExists()
  22. {
  23. $this->filesystem->delete('newpath')
  24. ->willThrow('League\Flysystem\FileNotFoundException', 'newpath')
  25. ->shouldBeCalled();
  26. $this->filesystem->rename('path', 'newpath')->willReturn(true)->shouldBeCalled();
  27. $this->assertTrue($this->plugin->handle('path', 'newpath'));
  28. }
  29. public function testPluginDeleteFail()
  30. {
  31. $this->filesystem->delete('newpath')->willReturn(false)->shouldBeCalled();
  32. $this->assertFalse($this->plugin->handle('path', 'newpath'));
  33. }
  34. }