Skip to content

Commit 627bcd0

Browse files
committed
Reuse test scenarios from FtpIntegrationTests
1 parent 2a188da commit 627bcd0

File tree

2 files changed

+92
-59
lines changed

2 files changed

+92
-59
lines changed

tests/WebDAVIntegration.php

-59
This file was deleted.

tests/WebDAVIntegrationTests.php

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
use League\Flysystem\Filesystem;
4+
use League\Flysystem\Plugin\ListPaths;
5+
use League\Flysystem\WebDAV\WebDAVAdapter;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class WebDAVIntegrationTests extends TestCase
9+
{
10+
/** @var Filesystem */
11+
protected $filesystem;
12+
13+
protected function setUp()
14+
{
15+
$client = new Sabre\DAV\Client([
16+
'baseUri' => 'http://localhost',
17+
'userName' => 'alice',
18+
'password' => 'secret1234',
19+
]);
20+
21+
$this->filesystem = new Filesystem(new WebDAVAdapter($client));
22+
$this->filesystem->addPlugin(new ListPaths());
23+
24+
foreach ($this->filesystem->listContents('', true) as $item) {
25+
if ($item['path'] === '') {
26+
continue;
27+
}
28+
29+
if ($item['type'] === 'dir') {
30+
$this->filesystem->deleteDir($item['path']);
31+
} else {
32+
$this->filesystem->delete($item['path']);
33+
}
34+
}
35+
}
36+
37+
/**
38+
* @test
39+
*/
40+
public function writing_reading_deleting()
41+
{
42+
$filesystem = $this->filesystem;
43+
$this->assertTrue($filesystem->put('path.txt', 'file contents'));
44+
$this->assertEquals('file contents', $filesystem->read('path.txt'));
45+
$this->assertTrue($filesystem->delete('path.txt'));
46+
}
47+
48+
49+
/**
50+
* @test
51+
*/
52+
public function creating_a_directory()
53+
{
54+
$this->filesystem->createDir('dirname/directory');
55+
$metadata = $this->filesystem->getMetadata('dirname/directory');
56+
self::assertEquals('dir', $metadata['type']);
57+
$this->filesystem->deleteDir('dirname');
58+
}
59+
60+
/**
61+
* @test
62+
*/
63+
public function writing_in_a_directory_and_deleting_the_directory()
64+
{
65+
$filesystem = $this->filesystem;
66+
$this->assertTrue($filesystem->write('deeply/nested/path.txt', 'contents'));
67+
$this->assertTrue($filesystem->has('deeply/nested'));
68+
$this->assertTrue($filesystem->has('deeply'));
69+
$this->assertTrue($filesystem->has('deeply/nested/path.txt'));
70+
$this->assertTrue($filesystem->deleteDir('deeply/nested'));
71+
$this->assertFalse($filesystem->has('deeply/nested'));
72+
$this->assertFalse($filesystem->has('deeply/nested/path.txt'));
73+
$this->assertTrue($filesystem->has('deeply'));
74+
$this->assertTrue($filesystem->deleteDir('deeply'));
75+
$this->assertFalse($filesystem->has('deeply'));
76+
}
77+
78+
/**
79+
* @test
80+
*/
81+
public function listing_files_of_a_directory()
82+
{
83+
$filesystem = $this->filesystem;
84+
$filesystem->write('dirname/a.txt', 'contents');
85+
$filesystem->write('dirname/b/b.txt', 'contents');
86+
$filesystem->write('dirname/c.txt', 'contents');
87+
$files = $filesystem->listPaths('', true);
88+
$expected = ['dirname', 'dirname/a.txt', 'dirname/b', 'dirname/b/b.txt', 'dirname/c.txt'];
89+
$filesystem->deleteDir('dirname');
90+
$this->assertEquals($expected, $files);
91+
}
92+
}

0 commit comments

Comments
 (0)