diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateTimeType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateTimeType.php index 144c69e22e..df3d2e9d48 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateTimeType.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateTimeType.php @@ -32,6 +32,10 @@ public function isComparableWith(Type $type) : bool return true; } + if ($type instanceof DateType) { + return true; + } + return false; } diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateType.php index 479ca2efb3..66fb8c585b 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateType.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateType.php @@ -32,6 +32,10 @@ public function isComparableWith(Type $type) : bool return true; } + if ($type instanceof DateTimeType) { + return true; + } + return false; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTimeTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTimeTypeTest.php index 7dbba53f6e..ca71957a05 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTimeTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTimeTypeTest.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Logical; -use function Flow\ETL\DSL\{type_datetime, type_int}; +use function Flow\ETL\DSL\{type_date, type_datetime, type_int, type_null}; use Flow\ETL\Tests\FlowTestCase; final class DateTimeTypeTest extends FlowTestCase @@ -19,6 +19,14 @@ public function test_equals() : void ); } + public function test_is_comparable() : void + { + self::assertTrue(type_datetime()->isComparableWith(type_datetime())); + self::assertTrue(type_datetime()->isComparableWith(type_date())); + self::assertTrue(type_datetime()->isComparableWith(type_null())); + self::assertFalse(type_datetime()->isComparableWith(type_int())); + } + public function test_is_valid() : void { self::assertTrue(type_datetime(true)->isValid(null)); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTypeTest.php new file mode 100644 index 0000000000..9cdee75bf1 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/DateTypeTest.php @@ -0,0 +1,66 @@ +isEqual(type_date()) + ); + self::assertFalse( + type_date()->isEqual(type_int()) + ); + } + + public function test_is_comparable() : void + { + self::assertTrue(type_date()->isComparableWith(type_datetime())); + self::assertTrue(type_date()->isComparableWith(type_date())); + self::assertTrue(type_date()->isComparableWith(type_null())); + self::assertFalse(type_date()->isComparableWith(type_int())); + } + + public function test_is_valid() : void + { + self::assertTrue(type_date(true)->isValid(null)); + self::assertFalse(type_date()->isValid(new \DateTimeImmutable())); + self::assertTrue(type_date()->isValid(new \DateTime('2024-12-01'))); + self::assertFalse(type_date()->isValid('2020-01-01')); + self::assertFalse(type_date()->isValid('2020-01-01 00:00:00')); + } + + public function test_merge_non_nullable_with_non_nullable() : void + { + self::assertFalse(type_date()->merge(type_date())->nullable()); + } + + public function test_merge_non_nullable_with_nullable() : void + { + self::assertTrue(type_date()->merge(type_date(true))->nullable()); + self::assertTrue(type_date(true)->merge(type_date(false))->nullable()); + } + + public function test_merge_nullable_with_nullable() : void + { + self::assertTrue(type_date(true)->merge(type_date(true))->nullable()); + } + + public function test_to_string() : void + { + self::assertSame( + 'date', + type_date()->toString() + ); + self::assertSame( + '?date', + type_date(true)->toString() + ); + } +}