Skip to content

Commit

Permalink
tests: added RemoteStream to be able test non-local URLs offline (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
milo authored and dg committed Jun 17, 2016
1 parent 4abe9ba commit 8303fc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/Utils/FileSystem.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ Assert::exception(function () {


test(function () { // copy
Assert::false(stream_is_local('remote://example.com'));

FileSystem::write(TEMP_DIR . '/3/file', 'Hello');

FileSystem::copy(TEMP_DIR . '/3/file', TEMP_DIR . '/3/x/file');
Assert::same('Hello', FileSystem::read(TEMP_DIR . '/3/x/file'));

FileSystem::copy('http://example.com', TEMP_DIR . '/3/x/y/file');
FileSystem::copy('remote://example.com', TEMP_DIR . '/3/x/y/file');
Assert::true(is_file(TEMP_DIR . '/3/x/y/file'));

FileSystem::write(TEMP_DIR . '/5/newfile', 'World');
Expand All @@ -56,7 +58,7 @@ test(function () { // copy
Assert::same('Hello', FileSystem::read(TEMP_DIR . '/3/x/file'));

Assert::exception(function () {
FileSystem::copy('http://example.com', TEMP_DIR . '/3/x/file', FALSE);
FileSystem::copy('remote://example.com', TEMP_DIR . '/3/x/file', FALSE);
}, Nette\InvalidStateException::class, "File or directory '%a%' already exists.");
Assert::same('Hello', FileSystem::read(TEMP_DIR . '/3/x/file'));

Expand Down Expand Up @@ -135,4 +137,5 @@ test(function () { // isAbsolute
Assert::true(FileSystem::isAbsolute('d:\file'));
Assert::true(FileSystem::isAbsolute('D:\file'));
Assert::true(FileSystem::isAbsolute('http://file'));
Assert::true(FileSystem::isAbsolute('remote://file'));
});
9 changes: 9 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ function test(\Closure $function)
before();
$function();
}


class RemoteStream /* extends \streamWrapper */
{
public function stream_open() { return TRUE; }
public function url_stat() { return FALSE; }
}

stream_wrapper_register('remote', RemoteStream::class, STREAM_IS_URL);

0 comments on commit 8303fc2

Please sign in to comment.