From 5d7b8ee5579f322e37f246da8843f96b9ce84e17 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 16 Oct 2023 16:25:16 -0300 Subject: [PATCH] chore: remove obsolete caster class --- src/Model/Casts/Caster.php | 43 --------- .../Exceptions/InvalidArgumentException.php | 16 ---- .../Casts/Exceptions/InvalidCastException.php | 17 ---- src/Model/HasAttributesTrait.php | 3 - tests/Unit/Model/Casts/CasterTest.php | 90 ------------------- 5 files changed, 169 deletions(-) delete mode 100644 src/Model/Casts/Caster.php delete mode 100644 src/Model/Casts/Exceptions/InvalidArgumentException.php delete mode 100644 src/Model/Casts/Exceptions/InvalidCastException.php delete mode 100644 tests/Unit/Model/Casts/CasterTest.php diff --git a/src/Model/Casts/Caster.php b/src/Model/Casts/Caster.php deleted file mode 100644 index 699ce302..00000000 --- a/src/Model/Casts/Caster.php +++ /dev/null @@ -1,43 +0,0 @@ -assertNull($revoked_at); - $this->assertInstanceOf(DateTime::class, $expires_at); - $this->assertInstanceOf(DateTimeImmutable::class, $birthdate); - $this->assertInstanceOf(DateTime::class, $validated_at); - $this->assertInstanceOf(DateTimeImmutable::class, $created_at); - } - - /** - * @dataProvider getInvalidArgumentScenarios - */ - public function testShouldThrowExceptionWhenGivenInvalidArgumentForCastToDateTime( - mixed $argument, - string $expectedMessage - ): void - { - // Expectations - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage($expectedMessage); - - // Actions - Caster::castToDateTime('datetime', $argument); - } - - public function testShouldThrowExceptionWhenGivenInvalidCastArgumentForCastToDateTime(): void - { - // Expectations - $this->expectException(InvalidCastException::class); - $this->expectExceptionMessage("Cast value should be a valid one, like datetime,immutable_datetime. But 'invalid' was given"); - - // Actions - Caster::castToDateTime('invalid', true); - } - - public function testCastToMongoUTCDateTime(): void - { - // Set - $dateInDateTime = DateTime::createFromFormat('d/m/Y H:i:s', '08/10/2025 12:30:45'); - - // Actions - $expires_at = DateTimeCast::set($dateInDateTime); - $nulled_at = DateTimeCast::set(null); - - // Assertions - $this->assertInstanceOf(UTCDateTime::class, $expires_at); - $this->assertNull($nulled_at); - } - - public function getInvalidArgumentScenarios(): array - { - return [ - 'when given an invalid object argument' => [ - 'argument' => new DateTime(), - 'expectedMessage' => 'Argument value should be of type ?UTCDateTime, DateTime given', - ], - 'when given in invalid primitive argument' => [ - 'argument' => false, - 'expectedMessage' => 'Argument value should be of type ?UTCDateTime, boolean given', - ], - ]; - } -}