From 4bc50e3e42d42798b266026827909b28b1ba8258 Mon Sep 17 00:00:00 2001 From: Romain Canon Date: Mon, 29 Aug 2022 14:50:19 +0200 Subject: [PATCH] misc: add singleton usage of `ClassStringType` --- src/Type/Types/ClassStringType.php | 3 +++ tests/Unit/Type/Types/ClassStringTypeTest.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Type/Types/ClassStringType.php b/src/Type/Types/ClassStringType.php index 9b4db37..b592871 100644 --- a/src/Type/Types/ClassStringType.php +++ b/src/Type/Types/ClassStringType.php @@ -11,6 +11,7 @@ use CuyZ\Valinor\Type\Type; use CuyZ\Valinor\Type\Types\Exception\CannotCastValue; use CuyZ\Valinor\Type\Types\Exception\InvalidClassString; use CuyZ\Valinor\Type\Types\Exception\InvalidUnionOfClassString; +use CuyZ\Valinor\Utility\IsSingleton; use CuyZ\Valinor\Utility\Reflection\Reflection; use function is_object; @@ -20,6 +21,8 @@ use function method_exists; /** @internal */ final class ClassStringType implements StringType, CompositeType { + use IsSingleton; + /** @var ObjectType|UnionType|null */ private ?Type $subType; diff --git a/tests/Unit/Type/Types/ClassStringTypeTest.php b/tests/Unit/Type/Types/ClassStringTypeTest.php index 6b018f0..a5df6da 100644 --- a/tests/Unit/Type/Types/ClassStringTypeTest.php +++ b/tests/Unit/Type/Types/ClassStringTypeTest.php @@ -8,6 +8,7 @@ use CuyZ\Valinor\Tests\Fake\Type\FakeObjectCompositeType; use CuyZ\Valinor\Tests\Fake\Type\FakeObjectType; use CuyZ\Valinor\Tests\Fake\Type\FakeType; use CuyZ\Valinor\Tests\Fixture\Object\StringableObject; +use CuyZ\Valinor\Tests\Traits\TestIsSingleton; use CuyZ\Valinor\Type\Types\Exception\InvalidUnionOfClassString; use CuyZ\Valinor\Type\Types\NativeStringType; use CuyZ\Valinor\Type\Types\ClassStringType; @@ -24,6 +25,8 @@ use stdClass; final class ClassStringTypeTest extends TestCase { + use TestIsSingleton; + public function test_string_subtype_can_be_retrieved(): void { $subType = new FakeObjectType();