Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function isComparableWith(Type $type) : bool
return true;
}

if ($type instanceof DateType) {
return true;
}

return false;
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/PHP/Type/Logical/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function isComparableWith(Type $type) : bool
return true;
}

if ($type instanceof DateTimeType) {
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Flow\ETL\Tests\Unit\PHP\Type\Logical;

use function Flow\ETL\DSL\{type_date, type_datetime, type_int, type_null};
use Flow\ETL\Tests\FlowTestCase;

final class DateTypeTest extends FlowTestCase
{
public function test_equals() : void
{
self::assertTrue(
type_date()->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()
);
}
}