From f1f4fe724a4fbf1a1c473f975aa821d31b71e095 Mon Sep 17 00:00:00 2001 From: Dennis Haupt Date: Tue, 9 May 2023 15:03:46 +0200 Subject: [PATCH] Adding a new scalar `BigInt` --- README.md | 4 +--- src/BigInt.php | 16 ++++++++++++++++ tests/BigIntTest.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/BigInt.php create mode 100644 tests/BigIntTest.php diff --git a/README.md b/README.md index a35e4bd..97272b7 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,8 @@ class HexValue extends Regex { /** * The description that is used for schema introspection. - * - * @var string */ - public $description = <<<'DESCRIPTION' + public ?string $description = <<<'DESCRIPTION' A hexadecimal color is specified with: `#RRGGBB`, where `RR` (red), `GG` (green) and `BB` (blue) are hexadecimal integers between `00` and `FF` specifying the intensity of the color. DESCRIPTION; diff --git a/src/BigInt.php b/src/BigInt.php new file mode 100644 index 0000000..dfa0c47 --- /dev/null +++ b/src/BigInt.php @@ -0,0 +1,16 @@ +expectExceptionObject(new InvariantViolation('The given value "foo" did not match the regex /\d+/.')); + $bigInt->serialize('foo'); + } + + public function testSerializePassesWhenBigIntIsValid(): void + { + $serializedResult = (new BigInt())->serialize(10000000000000); + + self::assertSame("10000000000000", $serializedResult); + } + + public function testSerializePassesWhenBigIntIsValidAsString(): void + { + $serializedResult = (new BigInt())->serialize("10000000000000"); + + self::assertSame("10000000000000", $serializedResult); + } + + public function testParseBigIntIsValid(): void + { + $parsedResult = (new BigInt())->parseValue(10000000000000); + + self::assertSame("10000000000000", $parsedResult); + } +}