-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run some tests against a real dav server
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
use League\Flysystem\Filesystem; | ||
use League\Flysystem\Plugin\ListPaths; | ||
use League\Flysystem\WebDAV\WebDAVAdapter; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class WebDAVIntegrationTests extends TestCase | ||
{ | ||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
|
||
/** @var Filesystem */ | ||
protected $filesystem; | ||
|
||
protected function setUp() | ||
{ | ||
$client = new Sabre\DAV\Client([ | ||
'baseUri' => '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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
$tries = 0; | ||
start: | ||
$tries++; | ||
$success = @fsockopen('localhost', 80); | ||
|
||
if ($success) { | ||
fwrite(STDOUT, "Connected successfully.\n"); | ||
exit(0); | ||
} | ||
|
||
if ($tries > 10) { | ||
fwrite(STDOUT, "Failed to connect.\n"); | ||
exit(1); | ||
} | ||
|
||
sleep(1); | ||
fwrite(STDOUT, "Waiting for a connection...\n"); | ||
goto start; |