From b52a44c2334785f93e954bdc8ddc5fcf111f9bed Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Wed, 10 Jul 2019 23:20:09 +0200 Subject: [PATCH] Run some tests against a real dav server --- .travis.yml | 4 ++ tests/WebDAVIntegrationTests.php | 94 ++++++++++++++++++++++++++++++++ wait_for_webdav_service.php | 20 +++++++ 3 files changed, 118 insertions(+) create mode 100644 tests/WebDAVIntegrationTests.php create mode 100644 wait_for_webdav_service.php diff --git a/.travis.yml b/.travis.yml index 9748397..bfec06d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,9 @@ php: install: - travis_retry composer install --no-interaction --prefer-source +before_script: + - docker run -d --name webdav_server -p 80:80 -e USERNAME=alice -e PASSWORD=secret1234 bytemark/webdav + - php wait_for_webdav_service.php + script: - bin/phpunit --coverage-text --coverage-clover coverage.xml diff --git a/tests/WebDAVIntegrationTests.php b/tests/WebDAVIntegrationTests.php new file mode 100644 index 0000000..35d164e --- /dev/null +++ b/tests/WebDAVIntegrationTests.php @@ -0,0 +1,94 @@ + 'http://localhost', + 'userName' => 'alice', + 'password' => 'secret1234', + ]); + + $this->filesystem = new Filesystem(new WebDAVAdapter($client)); + $this->filesystem->addPlugin(new ListPaths()); + + foreach ($this->filesystem->listContents('', true) as $item) { + if ($item['path'] === '') { + continue; + } + + if ($item['type'] === 'dir') { + $this->filesystem->deleteDir($item['path']); + } else { + $this->filesystem->delete($item['path']); + } + } + } + + /** + * @test + */ + public function writing_reading_deleting() + { + $filesystem = $this->filesystem; + $this->assertTrue($filesystem->put('path.txt', 'file contents')); + $this->assertEquals('file contents', $filesystem->read('path.txt')); + $this->assertTrue($filesystem->delete('path.txt')); + } + + + /** + * @test + */ + public function creating_a_directory() + { + $this->filesystem->createDir('dirname/directory'); + $metadata = $this->filesystem->getMetadata('dirname/directory'); + self::assertEquals('dir', $metadata['type']); + $this->filesystem->deleteDir('dirname'); + } + + /** + * @test + */ + public function writing_in_a_directory_and_deleting_the_directory() + { + $filesystem = $this->filesystem; + $this->assertTrue($filesystem->write('deeply/nested/path.txt', 'contents')); + $this->assertTrue($filesystem->has('deeply/nested')); + $this->assertTrue($filesystem->has('deeply')); + $this->assertTrue($filesystem->has('deeply/nested/path.txt')); + $this->assertTrue($filesystem->deleteDir('deeply/nested')); + $this->assertFalse($filesystem->has('deeply/nested')); + $this->assertFalse($filesystem->has('deeply/nested/path.txt')); + $this->assertTrue($filesystem->has('deeply')); + $this->assertTrue($filesystem->deleteDir('deeply')); + $this->assertFalse($filesystem->has('deeply')); + } + + /** + * @test + */ + public function listing_files_of_a_directory() + { + $filesystem = $this->filesystem; + $filesystem->write('dirname/a.txt', 'contents'); + $filesystem->write('dirname/b/b.txt', 'contents'); + $filesystem->write('dirname/c.txt', 'contents'); + $files = $filesystem->listPaths('', true); + $expected = ['dirname', 'dirname/a.txt', 'dirname/b', 'dirname/b/b.txt', 'dirname/c.txt']; + $filesystem->deleteDir('dirname'); + $this->assertEquals($expected, $files); + } +} diff --git a/wait_for_webdav_service.php b/wait_for_webdav_service.php new file mode 100644 index 0000000..d48b131 --- /dev/null +++ b/wait_for_webdav_service.php @@ -0,0 +1,20 @@ + 10) { + fwrite(STDOUT, "Failed to connect.\n"); + exit(1); +} + +sleep(1); +fwrite(STDOUT, "Waiting for a connection...\n"); +goto start;