-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A time in DB uses the `TIME` native MariaDB type, with a precision to the seconds. However, the GraphQL time type is meant to be more human friendly and is only precise to the minute. It also accepts a few formats as input. That should allow the client code to directly forward whatever the human is typing.
- Loading branch information
Showing
5 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EcodevTests\Felix\DBAL\Types; | ||
|
||
use Cake\Chronos\ChronosTime; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Platforms\MySQLPlatform; | ||
use Doctrine\DBAL\Types\ConversionException; | ||
use Ecodev\Felix\DBAL\Types\TimeType; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TimeTypeTest extends TestCase | ||
{ | ||
private TimeType $type; | ||
|
||
private AbstractPlatform $platform; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->type = new TimeType(); | ||
$this->platform = new MySQLPlatform(); | ||
} | ||
|
||
public function testConvertToDatabaseValue(): void | ||
{ | ||
self::assertSame('TIME', $this->type->getSqlDeclaration(['foo'], $this->platform)); | ||
self::assertFalse($this->type->requiresSQLCommentHint($this->platform)); | ||
|
||
$actual = $this->type->convertToDatabaseValue(new ChronosTime('09:33'), $this->platform); | ||
self::assertSame('09:33:00', $actual, 'support Chronos'); | ||
|
||
self::assertNull($this->type->convertToDatabaseValue(null, $this->platform), 'support null values'); | ||
} | ||
|
||
public function testConvertToPHPValue(): void | ||
{ | ||
$actualPhp = $this->type->convertToPHPValue('18:59:23', $this->platform); | ||
self::assertInstanceOf(ChronosTime::class, $actualPhp); | ||
self::assertSame('18:59:23', $actualPhp->__toString(), 'support string'); | ||
|
||
$actualPhp = $this->type->convertToPHPValue(new ChronosTime('18:59:23'), $this->platform); | ||
self::assertInstanceOf(ChronosTime::class, $actualPhp); | ||
self::assertSame('18:59:23', $actualPhp->__toString(), 'support ChronosTime'); | ||
|
||
self::assertNull($this->type->convertToPHPValue(null, $this->platform), 'support null values'); | ||
} | ||
|
||
public function testConvertToPHPValueThrowsWithInvalidValue(): void | ||
{ | ||
$this->expectException(ConversionException::class); | ||
|
||
$this->type->convertToPHPValue(123, $this->platform); | ||
} | ||
|
||
public function testConvertToDatabaseValueThrowsWithInvalidValue(): void | ||
{ | ||
$this->expectException(ConversionException::class); | ||
|
||
$this->type->convertToDatabaseValue(123, $this->platform); | ||
} | ||
} |