Skip to content

Commit 0993e28

Browse files
author
matt
committed
Move overwrite-on-move test to SftpAdapterTest, add test for moving and overwriting directory
1 parent ce78150 commit 0993e28

File tree

2 files changed

+70
-31
lines changed

2 files changed

+70
-31
lines changed

src/AdapterTestUtilities/FilesystemAdapterTestCase.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -643,37 +643,6 @@ public function moving_a_file(): void
643643
});
644644
}
645645

646-
/**
647-
* @test
648-
*/
649-
public function moving_a_file_and_overwriting(): void
650-
{
651-
$this->runScenario(function() {
652-
$adapter = $this->adapter();
653-
$adapter->write(
654-
'source.txt',
655-
'contents to be moved',
656-
new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC])
657-
);
658-
$adapter->write(
659-
'destination.txt',
660-
'contents to be overwritten',
661-
new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC])
662-
);
663-
$adapter->move('source.txt', 'destination.txt', new Config());
664-
$this->assertFalse(
665-
$adapter->fileExists('source.txt'),
666-
'After moving a file should no longer exist in the original location.'
667-
);
668-
$this->assertTrue(
669-
$adapter->fileExists('destination.txt'),
670-
'After moving, a file should be present at the new location.'
671-
);
672-
$this->assertEquals(Visibility::PUBLIC, $adapter->visibility('destination.txt')->visibility());
673-
$this->assertEquals('contents to be moved', $adapter->read('destination.txt'));
674-
});
675-
}
676-
677646
/**
678647
* @test
679648
*/

src/PhpseclibV3/SftpAdapterTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use League\Flysystem\UnableToMoveFile;
1313
use League\Flysystem\UnableToReadFile;
1414
use League\Flysystem\UnableToWriteFile;
15+
use League\Flysystem\Visibility;
1516
use phpseclib3\Net\SFTP;
1617

1718
use function class_exists;
@@ -214,6 +215,75 @@ public function list_contents_directory_does_not_exist(): void
214215
$this->assertCount(0, iterator_to_array($contents));
215216
}
216217

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+
217287
private static function connectionProvider(): ConnectionProvider
218288
{
219289
if ( ! static::$connectionProvider instanceof ConnectionProvider) {

0 commit comments

Comments
 (0)