Skip to content

Commit 9f0cb90

Browse files
committed
Now throw exception when can not get permission value
1 parent fa614c2 commit 9f0cb90

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

src/Adapter/Local/AbstractLocal.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
namespace Platine\Filesystem\Adapter\Local;
4949

5050
use Platine\Filesystem\Adapter\AdapterInterface;
51+
use Platine\Filesystem\Adapter\Local\Exception\FilesystemException;
5152
use Platine\Filesystem\FilesystemInterface;
5253
use Platine\Stdlib\Helper\Path;
5354

55+
5456
/**
5557
* Class AbstractLocal
5658
* @package Platine\Filesystem\Adapter\Local
@@ -191,7 +193,10 @@ public function getPermission(): string
191193
{
192194
$permission = fileperms($this->path);
193195
if ($permission === false) {
194-
return '';
196+
throw new FilesystemException(sprintf(
197+
'Can not get permission for file [%s]',
198+
$this->path
199+
));
195200
}
196201
return substr(base_convert((string) $permission, 10, 8), -4);
197202
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* Platine Filesystem
5+
*
6+
* Platine Filesystem is file system abstraction layer extendable by adapters
7+
*
8+
* This content is released under the MIT License (MIT)
9+
*
10+
* Copyright (c) 2020 Platine Filesystem
11+
* Copyright (c) 2019 Alex Sivka
12+
*
13+
* Permission is hereby granted, free of charge, to any person obtaining a copy
14+
* of this software and associated documentation files (the "Software"), to deal
15+
* in the Software without restriction, including without limitation the rights
16+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
* copies of the Software, and to permit persons to whom the Software is
18+
* furnished to do so, subject to the following conditions:
19+
*
20+
* The above copyright notice and this permission notice shall be included in all
21+
* copies or substantial portions of the Software.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
* SOFTWARE.
30+
*/
31+
32+
declare(strict_types=1);
33+
34+
namespace Platine\Filesystem\Adapter\Local\Exception;
35+
36+
use Exception;
37+
38+
/**
39+
* Class FilesystemException
40+
* @package Platine\Filesystem\Adapter\Local\Exception
41+
*/
42+
class FilesystemException extends Exception
43+
{
44+
}

src/Adapter/Local/Exception/NotFoundException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@
3333

3434
namespace Platine\Filesystem\Adapter\Local\Exception;
3535

36-
use Exception;
37-
3836
/**
3937
* Class NotFoundException
4038
* @package Platine\Filesystem\Adapter\Local\Exception
4139
*/
42-
class NotFoundException extends Exception
40+
class NotFoundException extends FilesystemException
4341
{
4442
}

tests/Adapter/Local/FileTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
namespace Platine\Test\Filesystem\Adapter\Local;
66

77
use org\bovigo\vfs\vfsStream;
8+
use Platine\Dev\PlatineTestCase;
89
use Platine\Filesystem\Adapter\AdapterInterface;
10+
use Platine\Filesystem\Adapter\Local\Exception\FilesystemException;
911
use Platine\Filesystem\Adapter\Local\File;
1012
use Platine\Filesystem\Adapter\Local\LocalAdapter;
1113
use Platine\Filesystem\FileInterface;
12-
use Platine\Dev\PlatineTestCase;
1314

1415
/**
1516
* File class tests
@@ -171,7 +172,8 @@ public function testGetPermissionFunctionfilePermsReturnFalse(): void
171172
);
172173

173174
$t = new File($file->url(), $adapter);
174-
$this->assertEmpty($t->getPermission());
175+
$this->expectException(FilesystemException::class);
176+
$t->getPermission();
175177
}
176178

177179
public function testGetMimeUsingHelperToGetMimetype(): void

0 commit comments

Comments
 (0)