Skip to content

Commit

Permalink
Merge pull request #1800 from hydephp/update-invalid-configuration-ex…
Browse files Browse the repository at this point in the history
…ception-class

[2.x] Update custom exception class to accept previous throwable
  • Loading branch information
caendesilva authored Jul 8, 2024
2 parents 8250a79 + 21faf46 commit 1668b93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Exceptions;

use Throwable;
use Hyde\Facades\Filesystem;
use InvalidArgumentException;

Expand All @@ -13,13 +14,13 @@

class InvalidConfigurationException extends InvalidArgumentException
{
public function __construct(string $message = 'Invalid configuration detected.', ?string $namespace = null, ?string $key = null)
public function __construct(string $message = 'Invalid configuration detected.', ?string $namespace = null, ?string $key = null, ?Throwable $previous = null)
{
if ($namespace && $key) {
[$this->file, $this->line] = $this->findConfigLine($namespace, $key);
}

parent::__construct($message);
parent::__construct($message, previous: $previous);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions packages/framework/tests/Unit/CustomExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,13 @@ public function testInvalidConfigurationExceptionWithNamespaceAndKey()
$this->assertStringContainsString('config'.DIRECTORY_SEPARATOR.'hyde.php', $exception->getFile());
$this->assertGreaterThan(0, $exception->getLine());
}

public function testInvalidConfigurationExceptionWithPreviousThrowable()
{
$previous = new Exception('Previous exception.');
$exception = new InvalidConfigurationException('Invalid configuration.', 'hyde', 'name', $previous);

$this->assertSame('Invalid configuration.', $exception->getMessage());
$this->assertSame($previous, $exception->getPrevious());
}
}

0 comments on commit 1668b93

Please sign in to comment.