diff --git a/src/Psl/Type/Internal/LiteralScalarType.php b/src/Psl/Type/Internal/LiteralScalarType.php index d90a3448..6f64c66f 100644 --- a/src/Psl/Type/Internal/LiteralScalarType.php +++ b/src/Psl/Type/Internal/LiteralScalarType.php @@ -41,14 +41,16 @@ public function matches(mixed $value): bool */ public function coerce(mixed $value): string|int|float|bool { - if ($value === $this->value) { + $expectedScalarValue = $this->value; + if ($value === $expectedScalarValue) { /** @var T $value */ return $value; } - if (Type\string()->matches($this->value)) { - $coerced_value = Type\string()->coerce($value); - if ($this->value === $coerced_value) { + $stringType = Type\string(); + if ($stringType->matches($this->value)) { + $coerced_value = $stringType->coerce($value); + if ($expectedScalarValue === $coerced_value) { /** @var T $coerced_value */ return $coerced_value; } @@ -56,9 +58,10 @@ public function coerce(mixed $value): string|int|float|bool throw CoercionException::withValue($value, $this->toString()); } - if (Type\int()->matches($this->value)) { - $coerced_value = Type\int()->coerce($value); - if ($this->value === $coerced_value) { + $intType = Type\int(); + if ($intType->matches($this->value)) { + $coerced_value = $intType->coerce($value); + if ($expectedScalarValue === $coerced_value) { /** @var T $coerced_value */ return $coerced_value; } @@ -66,9 +69,10 @@ public function coerce(mixed $value): string|int|float|bool throw CoercionException::withValue($value, $this->toString()); } - if (Type\float()->matches($this->value)) { - $coerced_value = Type\float()->coerce($value); - if ($this->value === $coerced_value) { + $floatType = Type\float(); + if ($floatType->matches($this->value)) { + $coerced_value = $floatType->coerce($value); + if ($expectedScalarValue === $coerced_value) { /** @var T $coerced_value */ return $coerced_value; } @@ -77,7 +81,7 @@ public function coerce(mixed $value): string|int|float|bool } /** @var bool $literal_value */ - $literal_value = $this->value; + $literal_value = $expectedScalarValue; $coerced_value = Type\bool()->coerce($value); if ($literal_value === $coerced_value) { /** @var T $coerced_value */ diff --git a/src/Psl/Type/array_key.php b/src/Psl/Type/array_key.php index f2e32948..b11a3013 100644 --- a/src/Psl/Type/array_key.php +++ b/src/Psl/Type/array_key.php @@ -9,5 +9,8 @@ */ function array_key(): TypeInterface { - return new Internal\ArrayKeyType(); + /** @var Internal\ArrayKeyType $instance */ + static $instance = new Internal\ArrayKeyType(); + + return $instance; } diff --git a/src/Psl/Type/bool.php b/src/Psl/Type/bool.php index 1051d588..7e9266df 100644 --- a/src/Psl/Type/bool.php +++ b/src/Psl/Type/bool.php @@ -9,5 +9,8 @@ */ function bool(): TypeInterface { - return new Internal\BoolType(); + /** @var Internal\BoolType $instance */ + static $instance = new Internal\BoolType(); + + return $instance; } diff --git a/src/Psl/Type/f32.php b/src/Psl/Type/f32.php index 93a0890e..3965b958 100644 --- a/src/Psl/Type/f32.php +++ b/src/Psl/Type/f32.php @@ -11,5 +11,8 @@ */ function f32(): TypeInterface { - return new Internal\F32Type(); + /** @var Internal\F32Type $instance */ + static $instance = new Internal\F32Type(); + + return $instance; } diff --git a/src/Psl/Type/f64.php b/src/Psl/Type/f64.php index fcbe021d..86e5cd38 100644 --- a/src/Psl/Type/f64.php +++ b/src/Psl/Type/f64.php @@ -11,5 +11,8 @@ */ function f64(): TypeInterface { - return new Internal\F64Type(); + /** @var Internal\F64Type $instance */ + static $instance = new Internal\F64Type(); + + return $instance; } diff --git a/src/Psl/Type/float.php b/src/Psl/Type/float.php index 275e7139..05500938 100644 --- a/src/Psl/Type/float.php +++ b/src/Psl/Type/float.php @@ -9,5 +9,8 @@ */ function float(): TypeInterface { - return new Internal\FloatType(); + /** @var Internal\FloatType $instance */ + static $instance = new Internal\FloatType(); + + return $instance; } diff --git a/src/Psl/Type/i16.php b/src/Psl/Type/i16.php index 6a879e02..f6c4a490 100644 --- a/src/Psl/Type/i16.php +++ b/src/Psl/Type/i16.php @@ -11,5 +11,8 @@ */ function i16(): TypeInterface { - return new Internal\I16Type(); + /** @var Internal\I16Type $instance */ + static $instance = new Internal\I16Type(); + + return $instance; } diff --git a/src/Psl/Type/i32.php b/src/Psl/Type/i32.php index bb8d050e..5c47897d 100644 --- a/src/Psl/Type/i32.php +++ b/src/Psl/Type/i32.php @@ -11,5 +11,8 @@ */ function i32(): TypeInterface { - return new Internal\I32Type(); + /** @var Internal\I32Type $instance */ + static $instance = new Internal\I32Type(); + + return $instance; } diff --git a/src/Psl/Type/i64.php b/src/Psl/Type/i64.php index aff40727..26982eb1 100644 --- a/src/Psl/Type/i64.php +++ b/src/Psl/Type/i64.php @@ -11,5 +11,8 @@ */ function i64(): TypeInterface { - return new Internal\I64Type(); + /** @var Internal\I64Type $instance */ + static $instance = new Internal\I64Type(); + + return $instance; } diff --git a/src/Psl/Type/i8.php b/src/Psl/Type/i8.php index 1603e580..1b35e0f6 100644 --- a/src/Psl/Type/i8.php +++ b/src/Psl/Type/i8.php @@ -11,5 +11,8 @@ */ function i8(): TypeInterface { - return new Internal\I8Type(); + /** @var Internal\I8Type $instance */ + static $instance = new Internal\I8Type(); + + return $instance; } diff --git a/src/Psl/Type/int.php b/src/Psl/Type/int.php index cfe9e03c..949a03d3 100644 --- a/src/Psl/Type/int.php +++ b/src/Psl/Type/int.php @@ -9,5 +9,8 @@ */ function int(): TypeInterface { - return new Internal\IntType(); + /** @var Internal\IntType $instance */ + static $instance = new Internal\IntType(); + + return $instance; } diff --git a/src/Psl/Type/mixed.php b/src/Psl/Type/mixed.php index c7ce83c5..3d966c44 100644 --- a/src/Psl/Type/mixed.php +++ b/src/Psl/Type/mixed.php @@ -9,5 +9,8 @@ */ function mixed(): TypeInterface { - return new Internal\MixedType(); + /** @var Internal\MixedType $instance */ + static $instance = new Internal\MixedType(); + + return $instance; } diff --git a/src/Psl/Type/non_empty_string.php b/src/Psl/Type/non_empty_string.php index 18f97233..5864ac25 100644 --- a/src/Psl/Type/non_empty_string.php +++ b/src/Psl/Type/non_empty_string.php @@ -9,5 +9,8 @@ */ function non_empty_string(): TypeInterface { - return new Internal\NonEmptyStringType(); + /** @var Internal\NonEmptyStringType $instance */ + static $instance = new Internal\NonEmptyStringType(); + + return $instance; } diff --git a/src/Psl/Type/nonnull.php b/src/Psl/Type/nonnull.php index 8f2c5d62..f79ec2d5 100644 --- a/src/Psl/Type/nonnull.php +++ b/src/Psl/Type/nonnull.php @@ -11,5 +11,8 @@ */ function nonnull(): TypeInterface { - return new Internal\NonNullType(); + /** @var Internal\NonNullType $instance */ + static $instance = new Internal\NonNullType(); + + return $instance; } diff --git a/src/Psl/Type/null.php b/src/Psl/Type/null.php index 9376bc5d..d64d63fc 100644 --- a/src/Psl/Type/null.php +++ b/src/Psl/Type/null.php @@ -9,5 +9,8 @@ */ function null(): TypeInterface { - return new Internal\NullType(); + /** @var Internal\NullType $instance */ + static $instance = new Internal\NullType(); + + return $instance; } diff --git a/src/Psl/Type/num.php b/src/Psl/Type/num.php index 9fd101a9..d9118b2c 100644 --- a/src/Psl/Type/num.php +++ b/src/Psl/Type/num.php @@ -9,5 +9,8 @@ */ function num(): TypeInterface { - return new Internal\NumType(); + /** @var Internal\NumType $instance */ + static $instance = new Internal\NumType(); + + return $instance; } diff --git a/src/Psl/Type/numeric_string.php b/src/Psl/Type/numeric_string.php index 85c26746..e02c3d2f 100644 --- a/src/Psl/Type/numeric_string.php +++ b/src/Psl/Type/numeric_string.php @@ -9,5 +9,8 @@ */ function numeric_string(): TypeInterface { - return new Internal\NumericStringType(); + /** @var Internal\NumericStringType $instance */ + static $instance = new Internal\NumericStringType(); + + return $instance; } diff --git a/src/Psl/Type/object.php b/src/Psl/Type/object.php index 1f12ae65..5ede48f4 100644 --- a/src/Psl/Type/object.php +++ b/src/Psl/Type/object.php @@ -9,5 +9,8 @@ */ function object(): TypeInterface { - return new Internal\ObjectType(); + /** @var Internal\ObjectType $instance */ + static $instance = new Internal\ObjectType(); + + return $instance; } diff --git a/src/Psl/Type/positive_int.php b/src/Psl/Type/positive_int.php index 93275697..d92473b8 100644 --- a/src/Psl/Type/positive_int.php +++ b/src/Psl/Type/positive_int.php @@ -11,5 +11,8 @@ */ function positive_int(): TypeInterface { - return new Internal\PositiveIntType(); + /** @var Internal\PositiveIntType $instance */ + static $instance = new Internal\PositiveIntType(); + + return $instance; } diff --git a/src/Psl/Type/scalar.php b/src/Psl/Type/scalar.php index 2990f484..3b4d2e42 100644 --- a/src/Psl/Type/scalar.php +++ b/src/Psl/Type/scalar.php @@ -9,5 +9,8 @@ */ function scalar(): TypeInterface { - return new Internal\ScalarType(); + /** @var Internal\ScalarType $instance */ + static $instance = new Internal\ScalarType(); + + return $instance; } diff --git a/src/Psl/Type/string.php b/src/Psl/Type/string.php index 617c54b9..5071debb 100644 --- a/src/Psl/Type/string.php +++ b/src/Psl/Type/string.php @@ -9,5 +9,8 @@ */ function string(): TypeInterface { - return new Internal\StringType(); + /** @var Internal\StringType $instance */ + static $instance = new Internal\StringType(); + + return $instance; } diff --git a/src/Psl/Type/u16.php b/src/Psl/Type/u16.php index 350a3d6b..53afa82c 100644 --- a/src/Psl/Type/u16.php +++ b/src/Psl/Type/u16.php @@ -11,5 +11,8 @@ */ function u16(): TypeInterface { - return new Internal\U16Type(); + /** @var Internal\U16Type $instance */ + static $instance = new Internal\U16Type(); + + return $instance; } diff --git a/src/Psl/Type/u32.php b/src/Psl/Type/u32.php index e524ad2e..a3b9e1dc 100644 --- a/src/Psl/Type/u32.php +++ b/src/Psl/Type/u32.php @@ -11,5 +11,8 @@ */ function u32(): TypeInterface { - return new Internal\U32Type(); + /** @var Internal\U32Type $instance */ + static $instance = new Internal\U32Type(); + + return $instance; } diff --git a/src/Psl/Type/u8.php b/src/Psl/Type/u8.php index 02f5a517..f1eee385 100644 --- a/src/Psl/Type/u8.php +++ b/src/Psl/Type/u8.php @@ -11,5 +11,8 @@ */ function u8(): TypeInterface { - return new Internal\U8Type(); + /** @var Internal\U8Type $instance */ + static $instance = new Internal\U8Type(); + + return $instance; } diff --git a/src/Psl/Type/uint.php b/src/Psl/Type/uint.php index c9899e3e..70838a64 100644 --- a/src/Psl/Type/uint.php +++ b/src/Psl/Type/uint.php @@ -11,5 +11,8 @@ */ function uint(): TypeInterface { - return new Internal\UIntType(); + /** @var Internal\UIntType $instance */ + static $instance = new Internal\UIntType(); + + return $instance; } diff --git a/tests/benchmark/Type/ShapeTypeBench.php b/tests/benchmark/Type/ShapeTypeBench.php index e7fb3846..88fd79ca 100644 --- a/tests/benchmark/Type/ShapeTypeBench.php +++ b/tests/benchmark/Type/ShapeTypeBench.php @@ -98,6 +98,58 @@ public function provideHappyPathCoercion(): array 'war' => null, ]), ], + 'real-life-type-usage' => [ + 'type' => Type\shape([ + 'name' => Type\string(), + 'articles' => Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + 'likes' => Type\int(), + 'comments' => Type\optional(Type\vec(Type\shape([ + 'user' => Type\string(), + 'comment' => Type\string() + ]))), + ])), + 'dictionary' => Type\dict(Type\string(), Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + ]))), + 'pagination' => Type\optional(Type\shape([ + 'currentPage' => Type\uint(), + 'totalPages' => Type\uint(), + 'perPage' => Type\uint(), + 'totalRows' => Type\uint(), + ])) + ]), + 'value' => [ + 'name' => 'ok', + 'articles' => [ + [ + 'title' => 'ok', + 'content' => 'ok', + 'likes' => 1, + 'comments' => [ + [ + 'user' => 'ok', + 'comment' => 'ok' + ], + [ + 'user' => 'ok', + 'comment' => 'ok', + ] + ] + ] + ], + 'dictionary' => [ + 'key' => [ + [ + 'title' => 'ok', + 'content' => 'ok', + ] + ] + ] + ] + ] ]; } @@ -146,6 +198,58 @@ public function provideHappyPathAssertion(): array 'war' => null, ], ], + 'real-life-type-usage' => [ + 'type' => Type\shape([ + 'name' => Type\string(), + 'articles' => Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + 'likes' => Type\int(), + 'comments' => Type\optional(Type\vec(Type\shape([ + 'user' => Type\string(), + 'comment' => Type\string() + ]))), + ])), + 'dictionary' => Type\dict(Type\string(), Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + ]))), + 'pagination' => Type\optional(Type\shape([ + 'currentPage' => Type\uint(), + 'totalPages' => Type\uint(), + 'perPage' => Type\uint(), + 'totalRows' => Type\uint(), + ])) + ]), + 'value' => [ + 'name' => 'ok', + 'articles' => [ + [ + 'title' => 'ok', + 'content' => 'ok', + 'likes' => 1, + 'comments' => [ + [ + 'user' => 'ok', + 'comment' => 'ok' + ], + [ + 'user' => 'ok', + 'comment' => 'ok', + ] + ] + ] + ], + 'dictionary' => [ + 'key' => [ + [ + 'title' => 'ok', + 'content' => 'ok', + ] + ] + ] + ] + ] ]; } diff --git a/tests/unit/Type/ArrayKeyTypeTest.php b/tests/unit/Type/ArrayKeyTypeTest.php index 76baf4c4..9b5d60c8 100644 --- a/tests/unit/Type/ArrayKeyTypeTest.php +++ b/tests/unit/Type/ArrayKeyTypeTest.php @@ -40,4 +40,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'array-key']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\array_key(), Type\array_key()); + } } diff --git a/tests/unit/Type/BoolTypeTest.php b/tests/unit/Type/BoolTypeTest.php index 4bbddc0a..5ccdebb0 100644 --- a/tests/unit/Type/BoolTypeTest.php +++ b/tests/unit/Type/BoolTypeTest.php @@ -36,4 +36,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'bool']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\bool(), Type\bool()); + } } diff --git a/tests/unit/Type/F32TypeTest.php b/tests/unit/Type/F32TypeTest.php index 2b554e6b..2c2399a6 100644 --- a/tests/unit/Type/F32TypeTest.php +++ b/tests/unit/Type/F32TypeTest.php @@ -67,4 +67,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'f32']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\f32(), Type\f32()); + } } diff --git a/tests/unit/Type/F64TypeTest.php b/tests/unit/Type/F64TypeTest.php index b8a6890c..206cc898 100644 --- a/tests/unit/Type/F64TypeTest.php +++ b/tests/unit/Type/F64TypeTest.php @@ -73,4 +73,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'f64']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\f64(), Type\f64()); + } } diff --git a/tests/unit/Type/FloatTypeTest.php b/tests/unit/Type/FloatTypeTest.php index 620fa7cc..3df2d5f3 100644 --- a/tests/unit/Type/FloatTypeTest.php +++ b/tests/unit/Type/FloatTypeTest.php @@ -69,4 +69,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'float']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\float(), Type\float()); + } } diff --git a/tests/unit/Type/I16TypeTest.php b/tests/unit/Type/I16TypeTest.php index 11f9b4b9..ece9188a 100644 --- a/tests/unit/Type/I16TypeTest.php +++ b/tests/unit/Type/I16TypeTest.php @@ -64,4 +64,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'i16']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\i16(), Type\i16()); + } } diff --git a/tests/unit/Type/I32TypeTest.php b/tests/unit/Type/I32TypeTest.php index 09769225..f5536c8c 100644 --- a/tests/unit/Type/I32TypeTest.php +++ b/tests/unit/Type/I32TypeTest.php @@ -64,4 +64,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'i32']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\i32(), Type\i32()); + } } diff --git a/tests/unit/Type/I64TypeTest.php b/tests/unit/Type/I64TypeTest.php index 88a5b1d8..17934899 100644 --- a/tests/unit/Type/I64TypeTest.php +++ b/tests/unit/Type/I64TypeTest.php @@ -64,4 +64,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'i64']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\i64(), Type\i64()); + } } diff --git a/tests/unit/Type/I8TypeTest.php b/tests/unit/Type/I8TypeTest.php index 36a43acc..33d2e5d0 100644 --- a/tests/unit/Type/I8TypeTest.php +++ b/tests/unit/Type/I8TypeTest.php @@ -61,4 +61,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'i8']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\i8(), Type\i8()); + } } diff --git a/tests/unit/Type/IntTypeTest.php b/tests/unit/Type/IntTypeTest.php index faee65b1..7e5d70d2 100644 --- a/tests/unit/Type/IntTypeTest.php +++ b/tests/unit/Type/IntTypeTest.php @@ -60,4 +60,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'int']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\int(), Type\int()); + } } diff --git a/tests/unit/Type/MixedTypeTest.php b/tests/unit/Type/MixedTypeTest.php index 5f156e7e..95cb3ca8 100644 --- a/tests/unit/Type/MixedTypeTest.php +++ b/tests/unit/Type/MixedTypeTest.php @@ -88,4 +88,9 @@ public function testInvalidMatches($value): void { $this->addToAssertionCount(1); } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\mixed(), Type\mixed()); + } } diff --git a/tests/unit/Type/NonEmptyStringTypeTest.php b/tests/unit/Type/NonEmptyStringTypeTest.php index 9b5188c2..1fe75297 100644 --- a/tests/unit/Type/NonEmptyStringTypeTest.php +++ b/tests/unit/Type/NonEmptyStringTypeTest.php @@ -49,4 +49,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'non-empty-string']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\non_empty_string(), Type\non_empty_string()); + } } diff --git a/tests/unit/Type/NonNullTypeTest.php b/tests/unit/Type/NonNullTypeTest.php index d47c5dd7..7f846513 100644 --- a/tests/unit/Type/NonNullTypeTest.php +++ b/tests/unit/Type/NonNullTypeTest.php @@ -38,4 +38,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'nonnull']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\nonnull(), Type\nonnull()); + } } diff --git a/tests/unit/Type/NullTypeTest.php b/tests/unit/Type/NullTypeTest.php index d1a15b2b..d4c14c60 100644 --- a/tests/unit/Type/NullTypeTest.php +++ b/tests/unit/Type/NullTypeTest.php @@ -38,4 +38,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'null']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\null(), Type\null()); + } } diff --git a/tests/unit/Type/NumTypeTest.php b/tests/unit/Type/NumTypeTest.php index 47b06165..92c6bf32 100644 --- a/tests/unit/Type/NumTypeTest.php +++ b/tests/unit/Type/NumTypeTest.php @@ -80,4 +80,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'num']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\num(), Type\num()); + } } diff --git a/tests/unit/Type/NumericStringTypeTest.php b/tests/unit/Type/NumericStringTypeTest.php index 4aec73b5..f486c7be 100644 --- a/tests/unit/Type/NumericStringTypeTest.php +++ b/tests/unit/Type/NumericStringTypeTest.php @@ -49,4 +49,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'numeric-string']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\numeric_string(), Type\numeric_string()); + } } diff --git a/tests/unit/Type/ObjectTypeTest.php b/tests/unit/Type/ObjectTypeTest.php index 46b3056a..b92fc84f 100644 --- a/tests/unit/Type/ObjectTypeTest.php +++ b/tests/unit/Type/ObjectTypeTest.php @@ -37,4 +37,9 @@ public function getToStringExamples(): iterable { yield [Type\object(), 'object']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\object(), Type\object()); + } } diff --git a/tests/unit/Type/PositiveIntTypeTest.php b/tests/unit/Type/PositiveIntTypeTest.php index 6fc300e7..e7e1b427 100644 --- a/tests/unit/Type/PositiveIntTypeTest.php +++ b/tests/unit/Type/PositiveIntTypeTest.php @@ -67,4 +67,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'positive-int']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\positive_int(), Type\positive_int()); + } } diff --git a/tests/unit/Type/StringTypeTest.php b/tests/unit/Type/StringTypeTest.php index 23629324..e32ad28a 100644 --- a/tests/unit/Type/StringTypeTest.php +++ b/tests/unit/Type/StringTypeTest.php @@ -42,4 +42,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'string']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\string(), Type\string()); + } } diff --git a/tests/unit/Type/U16TypeTest.php b/tests/unit/Type/U16TypeTest.php index 7eef10d5..835906f4 100644 --- a/tests/unit/Type/U16TypeTest.php +++ b/tests/unit/Type/U16TypeTest.php @@ -64,4 +64,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'u16']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\u16(), Type\u16()); + } } diff --git a/tests/unit/Type/U32TypeTest.php b/tests/unit/Type/U32TypeTest.php index 1af02abe..17224892 100644 --- a/tests/unit/Type/U32TypeTest.php +++ b/tests/unit/Type/U32TypeTest.php @@ -64,4 +64,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'u32']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\u32(), Type\u32()); + } } diff --git a/tests/unit/Type/U8TypeTest.php b/tests/unit/Type/U8TypeTest.php index f8182013..4395d25a 100644 --- a/tests/unit/Type/U8TypeTest.php +++ b/tests/unit/Type/U8TypeTest.php @@ -66,4 +66,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'u8']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\u8(), Type\u8()); + } } diff --git a/tests/unit/Type/UIntTypeTest.php b/tests/unit/Type/UIntTypeTest.php index 9b65df5d..cd764690 100644 --- a/tests/unit/Type/UIntTypeTest.php +++ b/tests/unit/Type/UIntTypeTest.php @@ -60,4 +60,9 @@ public function getToStringExamples(): iterable { yield [$this->getType(), 'uint']; } + + public function testItIsAMemoizedType(): void + { + static::assertSame(Type\uint(), Type\uint()); + } }