Skip to content

Commit b52a44c

Browse files
committed
Run some tests against a real dav server
1 parent b5c3c75 commit b52a44c

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ php:
1515
install:
1616
- travis_retry composer install --no-interaction --prefer-source
1717

18+
before_script:
19+
- docker run -d --name webdav_server -p 80:80 -e USERNAME=alice -e PASSWORD=secret1234 bytemark/webdav
20+
- php wait_for_webdav_service.php
21+
1822
script:
1923
- bin/phpunit --coverage-text --coverage-clover coverage.xml

tests/WebDAVIntegrationTests.php

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

wait_for_webdav_service.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
$tries = 0;
4+
start:
5+
$tries++;
6+
$success = @fsockopen('localhost', 80);
7+
8+
if ($success) {
9+
fwrite(STDOUT, "Connected successfully.\n");
10+
exit(0);
11+
}
12+
13+
if ($tries > 10) {
14+
fwrite(STDOUT, "Failed to connect.\n");
15+
exit(1);
16+
}
17+
18+
sleep(1);
19+
fwrite(STDOUT, "Waiting for a connection...\n");
20+
goto start;

0 commit comments

Comments
 (0)