Skip to content

Commit

Permalink
Change NotWritableException to extend RuntimeException
Browse files Browse the repository at this point in the history
This commit changes NotWritableException to extend RuntimeException instead of LogicException. Additionally, it updates the Aspect class to check if the provided directory is writable and throws a NotWritableException if it is not. A test case is also added to validate this new behavior.
  • Loading branch information
koriym committed Nov 4, 2024
1 parent 9598e5b commit 2eb9885
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Aspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace Ray\Aop;

use Ray\Aop\Exception\NotWritableException;
use ReflectionClass;
use ReflectionMethod;
use RuntimeException;

use function file_exists;
use function is_writable;
use function sys_get_temp_dir;

/**
Expand Down Expand Up @@ -46,9 +49,11 @@ public function __construct(?string $tmpDir = null)
{
if ($tmpDir === null) {
$tmp = sys_get_temp_dir();
$this->tmpDir = $tmp !== '' ? $tmp : '/tmp';
$tmpDir = $tmp !== '' ? $tmp : '/tmp';
}

return;
if (! file_exists($tmpDir) || ! is_writable($tmpDir)) {
throw new NotWritableException("{$tmpDir} is not writable.");
}

$this->tmpDir = $tmpDir;
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/NotWritableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Ray\Aop\Exception;

use LogicException;
use RuntimeException;

class NotWritableException extends LogicException implements ExceptionInterface
class NotWritableException extends RuntimeException implements ExceptionInterface
{
}
7 changes: 7 additions & 0 deletions tests/Aspect/AspectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Ray\Aop\Annotation\FakeClassMarker;
use Ray\Aop\Annotation\FakeMarker;
use Ray\Aop\Aspect\Fake\src\FakeMyClass;
use Ray\Aop\Exception\NotWritableException;
use Ray\Aop\Matcher\AnyMatcher;
use Ray\Aop\Matcher\StartsWithMatcher;

Expand All @@ -29,6 +30,12 @@ public function testTmpDir(): void
$this->assertInstanceOf(Aspect::class, new Aspect(dirname(__DIR__) . '/tmp'));
}

public function testTmpDirNotWritable(): void
{
$this->expectException(NotWritableException::class);
new Aspect('/__INVALID_DIR__');
}

public function testNewInstance(): void
{
$this->aspect->bind(
Expand Down

0 comments on commit 2eb9885

Please sign in to comment.