Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
date
and datetime
property types
- Loading branch information
1 parent
bed87ae
commit 66a96c1
Showing
13 changed files
with
221 additions
and
49 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
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
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,52 @@ | ||
<?php | ||
|
||
namespace Pulsar\Tests\Driver; | ||
|
||
use DateTimeImmutable; | ||
use Pulsar\Driver\DatabaseDriver; | ||
use Pulsar\Property; | ||
use Pulsar\Tests\Enums\TestEnumInteger; | ||
use Pulsar\Tests\Enums\TestEnumString; | ||
use Pulsar\Type; | ||
use stdClass; | ||
|
||
trait SerializeValueTestTrait | ||
{ | ||
public function testSerializeValueString(): void | ||
{ | ||
$driver = $this->getDriver(); | ||
$this->assertEquals('string', $driver->serializeValue('string', null)); | ||
} | ||
|
||
public function testSerializeValueArray(): void | ||
{ | ||
$driver = $this->getDriver(); | ||
$arr = ['test' => true]; | ||
$this->assertEquals('{"test":true}', $driver->serializeValue($arr, null)); | ||
} | ||
|
||
public function testSerializeValueObject(): void | ||
{ | ||
$driver = $this->getDriver(); | ||
$obj = new stdClass(); | ||
$obj->test = true; | ||
$this->assertEquals('{"test":true}', $driver->serializeValue($obj, null)); | ||
} | ||
|
||
public function testSerializeValueEnum(): void | ||
{ | ||
$driver = $this->getDriver(); | ||
$this->assertEquals('first', $driver->serializeValue(TestEnumString::First, null)); | ||
$this->assertEquals(1, $driver->serializeValue(TestEnumInteger::First, null)); | ||
} | ||
|
||
public function testSerializeValueDateTime(): void | ||
{ | ||
date_default_timezone_set('UTC'); | ||
$driver = $this->getDriver(); | ||
$this->assertEquals('2023-01-08 01:02:03', $driver->serializeValue(new DateTimeImmutable('2023-01-08 01:02:03'), null)); | ||
$this->assertEquals('2023-01-08', $driver->serializeValue(new DateTimeImmutable('2023-01-08'), new Property(type: Type::DATE))); | ||
$this->assertEquals('2023-01-08 01:02:03', $driver->serializeValue(new DateTimeImmutable('2023-01-08 01:02:03'), new Property(type: Type::DATETIME))); | ||
$this->assertEquals('1673139723', $driver->serializeValue(new DateTimeImmutable('2023-01-08 01:02:03'), new Property(date_format: 'U'))); | ||
} | ||
} |
Oops, something went wrong.