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: 2 additions & 2 deletions src/Behavior/MillisecondTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
public function fromDb($value, $key, $context)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof DateTime) {
return $value;
}

$datetime = DateTime::createFromFormat('U.u', sprintf('%F', $value / 1000.0));

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Binary operation "/" between mixed and 1000.0 results in an error.
$datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));

return $datetime;
Expand Down
4 changes: 2 additions & 2 deletions src/Behavior/UUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

public function fromDb($value, $key, $_)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof UuidInterface) {
return $value;
}

if (! is_string($value)) {
throw new UnexpectedValueException(sprintf("Unexpected value '%s' for key '%s'", $value, $key));

Check failure on line 28 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.

Check failure on line 28 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.

Check failure on line 28 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.

Check failure on line 28 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.
}

try {
Expand All @@ -47,7 +47,7 @@

if (! $value instanceof UuidInterface) {
if (! is_string($value)) {
throw new UnexpectedValueException(sprintf("Unexpected value '%s' for key '%s'", $value, $key));

Check failure on line 50 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.

Check failure on line 50 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.

Check failure on line 50 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.

Check failure on line 50 in src/Behavior/UUID.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Parameter #2 ...$values of function sprintf expects bool|float|int|string|null, mixed given.
}

try {
Expand Down
16 changes: 16 additions & 0 deletions tests/Behavior/UUIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public function testRetrievePropertyReturnsUuidInstance(): void
);
}

public function testRetrievePropertyCanBeAppliedRepeatedly(): void
{
$behavior = $this->behavior();
$uuid = $behavior->retrieveProperty(
RamseyUuid::fromString(static::TEST_UUID_VALUE)->getBytes(),
static::TEST_COLUMN
);

$this->assertSame($uuid, $behavior->retrieveProperty($uuid, static::TEST_COLUMN));

$behavior = $this->behavior(true);
$uuid = $behavior->retrieveProperty(static::TEST_UUID_VALUE, static::TEST_COLUMN);

$this->assertSame($uuid, $behavior->retrieveProperty($uuid, static::TEST_COLUMN));
}

public function testPersistPropertyReturnsNullWhenValueIsNull(): void
{
$this->assertNull($this->behavior()->persistProperty(null, static::TEST_COLUMN));
Expand Down
8 changes: 8 additions & 0 deletions tests/MillisecondTimestampBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public function testFromDbReturnsNullWhenNullIsPassed()
$this->assertNull((new MillisecondTimestamp([]))->fromDb(null, 'key', null));
}

public function testFromDbCanBeAppliedRepeatedly()
{
$behavior = new MillisecondTimestamp([]);
$sometime = $behavior->fromDb(1668002400123, 'key', null);

$this->assertSame($sometime, $behavior->fromDb($sometime, 'key', null));
}

public function testToDbReturnsNullWhenNullIsPassed()
{
$this->assertNull((new MillisecondTimestamp([]))->toDb(null, 'key', null));
Expand Down
Loading