Skip to content

Commit 1668b93

Browse files
authored
Merge pull request #1800 from hydephp/update-invalid-configuration-exception-class
[2.x] Update custom exception class to accept previous throwable
2 parents 8250a79 + 21faf46 commit 1668b93

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/framework/src/Framework/Exceptions/InvalidConfigurationException.php

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

55
namespace Hyde\Framework\Exceptions;
66

7+
use Throwable;
78
use Hyde\Facades\Filesystem;
89
use InvalidArgumentException;
910

@@ -13,13 +14,13 @@
1314

1415
class InvalidConfigurationException extends InvalidArgumentException
1516
{
16-
public function __construct(string $message = 'Invalid configuration detected.', ?string $namespace = null, ?string $key = null)
17+
public function __construct(string $message = 'Invalid configuration detected.', ?string $namespace = null, ?string $key = null, ?Throwable $previous = null)
1718
{
1819
if ($namespace && $key) {
1920
[$this->file, $this->line] = $this->findConfigLine($namespace, $key);
2021
}
2122

22-
parent::__construct($message);
23+
parent::__construct($message, previous: $previous);
2324
}
2425

2526
/**

packages/framework/tests/Unit/CustomExceptionsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,13 @@ public function testInvalidConfigurationExceptionWithNamespaceAndKey()
201201
$this->assertStringContainsString('config'.DIRECTORY_SEPARATOR.'hyde.php', $exception->getFile());
202202
$this->assertGreaterThan(0, $exception->getLine());
203203
}
204+
205+
public function testInvalidConfigurationExceptionWithPreviousThrowable()
206+
{
207+
$previous = new Exception('Previous exception.');
208+
$exception = new InvalidConfigurationException('Invalid configuration.', 'hyde', 'name', $previous);
209+
210+
$this->assertSame('Invalid configuration.', $exception->getMessage());
211+
$this->assertSame($previous, $exception->getPrevious());
212+
}
204213
}

0 commit comments

Comments
 (0)