Repository navigation
EE-293: Declare the optional parameters as explicit nullable types #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mSprunskas
merged 11 commits into
paysera:master
from
vinayak-iyer-paysera:EE-293-explicit-nullable-types
Sep 30, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0d615c6
EE-293 Declare the optional parameters as explicit nullable types
vinayak-iyer-paysera 4402614
EE-293 Test the exception getters and nested lists
vinayak-iyer-paysera 2ae8d33
EE-293 Build the exceptions inside the test
vinayak-iyer-paysera b88bead
EE-293 Name the array element types in the exception test
vinayak-iyer-paysera 0a47cf8
EE-293 Load every class under src/ in the loading test
vinayak-iyer-paysera 924fe17
EE-293 Test explicit null for the optional parameters
vinayak-iyer-paysera f413b5f
EE-293 Test only the parameters this release changes
vinayak-iyer-paysera 9a29ee9
EE-293 Merge master with the CI workflow
vinayak-iyer-paysera 4ba091b
EE-293 Import Exception instead of naming it globally
vinayak-iyer-paysera 9bb187f
EE-293 Test a previous exception and a custom message
vinayak-iyer-paysera 58a0624
EE-293 Fail the tests on deprecations through the PHPUnit configuration
vinayak-iyer-paysera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Paysera\Component\ObjectWrapper\Tests\Exception; | ||
|
|
||
| use Exception; | ||
| use Paysera\Component\ObjectWrapper\Exception\InvalidItemException; | ||
| use Paysera\Component\ObjectWrapper\Exception\InvalidItemTypeException; | ||
| use Paysera\Component\ObjectWrapper\Exception\MissingItemException; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class InvalidItemExceptionTest extends TestCase | ||
| { | ||
| /** | ||
| * @dataProvider exceptionProvider | ||
| * @param array<string, mixed> $expected | ||
| */ | ||
| public function testExceptionDescribesTheItem(callable $createException, array $expected): void | ||
| { | ||
| $exception = $createException(); | ||
|
|
||
| $this->assertSame($expected, [ | ||
| 'class' => get_class($exception), | ||
| 'message' => $exception->getMessage(), | ||
| 'key' => $exception->getKey(), | ||
| 'expectedType' => $exception instanceof InvalidItemTypeException ? $exception->getExpectedType() : null, | ||
| 'givenType' => $exception instanceof InvalidItemTypeException ? $exception->getGivenType() : null, | ||
| 'previous' => $exception->getPrevious(), | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, array{callable, array<string, mixed>}> | ||
| */ | ||
| public static function exceptionProvider(): array | ||
| { | ||
| $previous = new Exception('x'); | ||
|
|
||
| return [ | ||
| 'invalid item with null message and previous' => [ | ||
| static function () { | ||
| return new InvalidItemException('a.b', null, null); | ||
| }, | ||
| self::expected(InvalidItemException::class, 'Invalid key "a.b"', 'a.b'), | ||
| ], | ||
| 'invalid item type with a null previous exception' => [ | ||
| static function () { | ||
| return new InvalidItemTypeException('string', 'integer', 'a.b', null); | ||
| }, | ||
| self::expected( | ||
| InvalidItemTypeException::class, | ||
| 'Expected string but got integer for key "a.b"', | ||
| 'a.b', | ||
| 'string', | ||
| 'integer' | ||
| ), | ||
| ], | ||
| 'missing item with a null previous exception' => [ | ||
| static function () { | ||
| return new MissingItemException('a.b', null); | ||
| }, | ||
| self::expected(MissingItemException::class, 'Missing required key "a.b"', 'a.b'), | ||
| ], | ||
| 'invalid item with a custom message' => [ | ||
| static function () { | ||
| return new InvalidItemException('a.b', 'Custom message'); | ||
| }, | ||
| self::expected(InvalidItemException::class, 'Custom message', 'a.b'), | ||
| ], | ||
| 'invalid item with a previous exception' => [ | ||
| static function () use ($previous) { | ||
| return new InvalidItemException('a.b', null, $previous); | ||
| }, | ||
| self::expected(InvalidItemException::class, 'Invalid key "a.b"', 'a.b', null, null, $previous), | ||
| ], | ||
| 'invalid item type with a previous exception' => [ | ||
| static function () use ($previous) { | ||
| return new InvalidItemTypeException('string', 'integer', 'a.b', $previous); | ||
| }, | ||
| self::expected( | ||
| InvalidItemTypeException::class, | ||
| 'Expected string but got integer for key "a.b"', | ||
| 'a.b', | ||
| 'string', | ||
| 'integer', | ||
| $previous | ||
| ), | ||
| ], | ||
| 'missing item with a previous exception' => [ | ||
| static function () use ($previous) { | ||
| return new MissingItemException('a.b', $previous); | ||
| }, | ||
| self::expected(MissingItemException::class, 'Missing required key "a.b"', 'a.b', null, null, $previous), | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, mixed> | ||
| */ | ||
| private static function expected( | ||
| string $class, | ||
| string $message, | ||
| string $key, | ||
| ?string $expectedType = null, | ||
| ?string $givenType = null, | ||
| ?Exception $previous = null | ||
| ): array { | ||
| return [ | ||
| 'class' => $class, | ||
| 'message' => $message, | ||
| 'key' => $key, | ||
| 'expectedType' => $expectedType, | ||
| 'givenType' => $givenType, | ||
| 'previous' => $previous, | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.