Skip to content

Commit c6d7345

Browse files
NicolasCARPimaennchen
authored andcommitted
Add test for FileNotReadableException (#114)
with virtual filesystem. Also fix two typos in exception messages.
1 parent b092959 commit c6d7345

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"require-dev": {
3131
"phpunit/phpunit": ">= 7.5",
3232
"guzzlehttp/guzzle": ">= 6.3",
33-
"ext-zip": "*"
33+
"ext-zip": "*",
34+
"mikey179/vfsStream": "^1.6"
3435
},
3536
"autoload": {
3637
"psr-4": {

src/Exception/FileNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class FileNotFoundException extends Exception
1717
*/
1818
public function __construct(string $path)
1919
{
20-
parent::__construct("Ths file with the path $path wasn't found.");
20+
parent::__construct("The file with the path $path wasn't found.");
2121
}
2222
}

src/Exception/FileNotReadableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class FileNotReadableException extends Exception
1717
*/
1818
public function __construct(string $path)
1919
{
20-
parent::__construct("Ths file with the path $path isn't readable.");
20+
parent::__construct("The file with the path $path isn't readable.");
2121
}
2222
}

test/ZipStreamTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace ZipStreamTest;
55

6+
use org\bovigo\vfs\vfsStream;
67
use GuzzleHttp\Psr7\Response;
78
use PHPUnit\Framework\TestCase;
89
use ZipStream\File;
@@ -31,10 +32,13 @@ public function testFileNotFoundException(): void
3132

3233
public function testFileNotReadableException(): void
3334
{
34-
// TODO: $this->expectException(\ZipStream\Exception\FileNotReadableException::class);
35-
36-
// TODO: How to test this?
37-
$this->markTestIncomplete('How to test this?');
35+
// create new virtual filesystem
36+
$root = vfsStream::setup('vfs');
37+
// create a virtual file with no permissions
38+
$file = vfsStream::newFile('foo.txt', 0000)->at($root)->setContent('bar');
39+
$zip = new ZipStream();
40+
$this->expectException(\ZipStream\Exception\FileNotReadableException::class);
41+
$zip->addFileFromPath('foo.txt', $file->url());
3842
}
3943

4044
public function testDostime(): void

0 commit comments

Comments
 (0)