-
Notifications
You must be signed in to change notification settings - Fork 12
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
3 changed files
with
59 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MLL\GraphQLScalars; | ||
|
||
class BigInt extends Regex | ||
{ | ||
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; | ||
|
||
public static function regex(): string | ||
{ | ||
return "/\d+/"; | ||
} | ||
} |
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,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MLL\GraphQLScalars\Tests; | ||
|
||
use GraphQL\Error\Error; | ||
use GraphQL\Error\InvariantViolation; | ||
use GraphQL\Language\AST\StringValueNode; | ||
use MLL\GraphQLScalars\BigInt; | ||
use MLL\GraphQLScalars\Email; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class BigIntTest extends TestCase | ||
{ | ||
public function testSerializeThrowsIfBigIntIsInvalid(): void | ||
{ | ||
$bigInt = new BigInt(); | ||
|
||
$this->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); | ||
} | ||
} |