|
12 | 12 | use League\Flysystem\UnableToMoveFile; |
13 | 13 | use League\Flysystem\UnableToReadFile; |
14 | 14 | use League\Flysystem\UnableToWriteFile; |
| 15 | +use League\Flysystem\Visibility; |
15 | 16 | use phpseclib3\Net\SFTP; |
16 | 17 |
|
17 | 18 | use function class_exists; |
@@ -214,6 +215,75 @@ public function list_contents_directory_does_not_exist(): void |
214 | 215 | $this->assertCount(0, iterator_to_array($contents)); |
215 | 216 | } |
216 | 217 |
|
| 218 | + /** |
| 219 | + * @test |
| 220 | + * @fixme Move to FilesystemAdapterTestCase once all adapters pass |
| 221 | + */ |
| 222 | + public function moving_a_file_and_overwriting(): void |
| 223 | + { |
| 224 | + $this->runScenario(function() { |
| 225 | + $adapter = $this->adapter(); |
| 226 | + $adapter->write( |
| 227 | + 'source.txt', |
| 228 | + 'contents to be moved', |
| 229 | + new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC]) |
| 230 | + ); |
| 231 | + $adapter->write( |
| 232 | + 'destination.txt', |
| 233 | + 'contents to be overwritten', |
| 234 | + new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC]) |
| 235 | + ); |
| 236 | + $adapter->move('source.txt', 'destination.txt', new Config()); |
| 237 | + $this->assertFalse( |
| 238 | + $adapter->fileExists('source.txt'), |
| 239 | + 'After moving a file should no longer exist in the original location.' |
| 240 | + ); |
| 241 | + $this->assertTrue( |
| 242 | + $adapter->fileExists('destination.txt'), |
| 243 | + 'After moving, a file should be present at the new location.' |
| 244 | + ); |
| 245 | + $this->assertEquals(Visibility::PUBLIC, $adapter->visibility('destination.txt')->visibility()); |
| 246 | + $this->assertEquals('contents to be moved', $adapter->read('destination.txt')); |
| 247 | + }); |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * @test |
| 252 | + * @fixme Move to FilesystemAdapterTestCase once all adapters pass |
| 253 | + */ |
| 254 | + public function moving_a_directory_and_overwriting(): void |
| 255 | + { |
| 256 | + $this->runScenario(function() { |
| 257 | + $adapter = $this->adapter(); |
| 258 | + $config = new Config(); |
| 259 | + |
| 260 | + $adapter->createDirectory('move_and_overwrite_source', $config); |
| 261 | + $adapter->write('move_and_overwrite_source/a', 'a', $config); |
| 262 | + |
| 263 | + $adapter->createDirectory('move_and_overwrite_target', $config); |
| 264 | + $adapter->write('move_and_overwrite_target/b', 'b', $config); |
| 265 | + |
| 266 | + $adapter->move('move_and_overwrite_source', 'move_and_overwrite_target', $config); |
| 267 | + |
| 268 | + $this->assertFalse( |
| 269 | + $adapter->directoryExists('move_and_overwrite_source'), |
| 270 | + 'Source directory should not exist' |
| 271 | + ); |
| 272 | + $this->assertTrue( |
| 273 | + $adapter->directoryExists('move_and_overwrite_target'), |
| 274 | + 'Target directory should exist' |
| 275 | + ); |
| 276 | + $this->assertTrue( |
| 277 | + $adapter->fileExists('move_and_overwrite_target/a'), |
| 278 | + 'Source files not moved' |
| 279 | + ); |
| 280 | + $this->assertFalse( |
| 281 | + $adapter->fileExists('move_and_overwrite_target/b'), |
| 282 | + 'Target files not deleted' |
| 283 | + ); |
| 284 | + }); |
| 285 | + } |
| 286 | + |
217 | 287 | private static function connectionProvider(): ConnectionProvider |
218 | 288 | { |
219 | 289 | if ( ! static::$connectionProvider instanceof ConnectionProvider) { |
|
0 commit comments