-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
262 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Processor/Mutator/Exception/InvalidElementIndexException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Remorhaz\JSON\Path\Processor\Mutator\Exception; | ||
|
||
use Throwable; | ||
use UnexpectedValueException; | ||
|
||
final class InvalidElementIndexException extends UnexpectedValueException implements ExceptionInterface | ||
{ | ||
public function __construct( | ||
private readonly ?string $index, | ||
?Throwable $previous = null, | ||
) { | ||
$indexText = isset($this->index) ? "'$this->index'" : 'NULL'; | ||
parent::__construct( | ||
message: "Element index is not an integer: $indexText", | ||
previous: $previous, | ||
); | ||
} | ||
|
||
public function getIndex(): ?string | ||
{ | ||
return $this->index; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/Processor/Mutator/Exception/InvalidElementIndexExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Remorhaz\JSON\Path\Test\Processor\Mutator\Exception; | ||
|
||
use Exception; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use Remorhaz\JSON\Path\Processor\Mutator\Exception\InvalidElementIndexException; | ||
|
||
#[CoversClass(InvalidElementIndexException::class)] | ||
class InvalidElementIndexExceptionTest extends TestCase | ||
{ | ||
public function testGetMessage_ConstructedWithString_ReturnsMatchingResult(): void | ||
{ | ||
$exception = new InvalidElementIndexException('a'); | ||
self::assertSame( | ||
'Element index is not an integer: \'a\'', | ||
$exception->getMessage(), | ||
); | ||
} | ||
|
||
public function testGetMessage_ConstructedWithNull_ReturnsMatchingResult(): void | ||
{ | ||
$exception = new InvalidElementIndexException(null); | ||
self::assertSame( | ||
'Element index is not an integer: NULL', | ||
$exception->getMessage(), | ||
); | ||
} | ||
|
||
public function testGetIndex_Constructed_ReturnsMatchingResult(): void | ||
{ | ||
$exception = new InvalidElementIndexException('a'); | ||
self::assertSame('a', $exception->getIndex()); | ||
} | ||
|
||
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void | ||
{ | ||
$exception = new InvalidElementIndexException('a'); | ||
self::assertNull($exception->getPrevious()); | ||
} | ||
|
||
public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): void | ||
{ | ||
$previous = new Exception(); | ||
$exception = new InvalidElementIndexException('a', $previous); | ||
self::assertSame($previous, $exception->getPrevious()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters