Skip to content

Commit

Permalink
Add injection of solutions in Exception constructor (#119)
Browse files Browse the repository at this point in the history
* Rapid add solutions in constructor

* Apply fixes from StyleCI

* fixes

* Apply fixes from StyleCI

* style fix

Co-authored-by: DarkSide <[email protected]>
Co-authored-by: Imants Horsts <[email protected]>
  • Loading branch information
3 people authored Apr 2, 2020
1 parent 0157d7d commit 882cf1c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public function __construct(
// message contain additional parameters
$this->params = $message;
$message = array_shift($this->params);
if (isset($this->params['solutions'])) {
foreach ((array) $this->params['solutions'] as $solution) {
$this->addSolution($solution);
}
unset($this->params['solutions']);
}
}

parent::__construct($message, $code ?? 0, $previous);
Expand Down
23 changes: 23 additions & 0 deletions tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ public function testSolution(): void
$this->assertRegExp('/One Solution/', $ret);
}

public function testSolution2(): void
{
$m = new Exception([
'Exception with solution',
'solutions' => '1st Solution',
]);

$ret = $m->getColorfulText();
$this->assertRegExp('/1st Solution/', $ret);

$m = new Exception([
'Exception with solution',
'solutions' => [
'1st Solution',
'2nd Solution',
],
]);

$ret = $m->getColorfulText();
$this->assertRegExp('/1st Solution/', $ret);
$this->assertRegExp('/2nd Solution/', $ret);
}

public function testCustomName(): void
{
$m = new ExceptionCustomName(
Expand Down

0 comments on commit 882cf1c

Please sign in to comment.