Skip to content

Commit

Permalink
Update cakephp/chronos
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Aug 28, 2023
1 parent 433ac3e commit 7aeedc5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ext-fileinfo": "*",
"ext-json": "*",
"ext-pdo": "*",
"cakephp/chronos": "^2.3",
"cakephp/chronos": "^2.4",
"doctrine/dbal": "^3.5",
"doctrine/migrations": "^3.5",
"ecodev/graphql-doctrine": "^8.0",
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Api/Scalar/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Ecodev\Felix\Api\Scalar;

use Cake\Chronos\Date;
use Cake\Chronos\ChronosDate;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\StringValueNode;
Expand All @@ -24,7 +24,7 @@ final class DateType extends ScalarType
*/
public function serialize(mixed $value): mixed
{
if ($value instanceof Date) {
if ($value instanceof ChronosDate) {
return $value->format('Y-m-d');
}

Expand All @@ -34,21 +34,21 @@ public function serialize(mixed $value): mixed
/**
* Parses an externally provided value (query variable) to use as an input.
*/
public function parseValue(mixed $value): Date
public function parseValue(mixed $value): ChronosDate
{
if (!is_string($value)) {
throw new UnexpectedValueException('Cannot represent value as Chronos date: ' . Utils::printSafe($value));
}

$date = Date::createFromFormat('Y-m-d+', $value);
$date = ChronosDate::createFromFormat('Y-m-d+', $value);

return $date;
}

/**
* Parses an externally provided literal value to use as an input (e.g. in Query AST).
*/
public function parseLiteral(Node $valueNode, ?array $variables = null): Date
public function parseLiteral(Node $valueNode, ?array $variables = null): ChronosDate
{
// Note: throwing GraphQL\Error\Error vs \UnexpectedValueException to benefit from GraphQL
// error location in query:
Expand Down
8 changes: 4 additions & 4 deletions src/DBAL/Types/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Ecodev\Felix\DBAL\Types;

use Cake\Chronos\Date;
use Cake\Chronos\ChronosDate;
use DateTimeInterface;
use Doctrine\DBAL\Platforms\AbstractPlatform;

Expand All @@ -13,13 +13,13 @@ final class DateType extends \Doctrine\DBAL\Types\DateType
/**
* @param null|DateTimeInterface|int|string $value
*/
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Date
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?ChronosDate
{
if ($value === null || $value instanceof Date) {
if ($value === null || $value instanceof ChronosDate) {
return $value;
}

$val = new Date($value);
$val = new ChronosDate($value);

return $val;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Api/Scalar/DateTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace EcodevTests\Felix\Api\Scalar;

use Cake\Chronos\Date;
use Cake\Chronos\ChronosDate;
use Ecodev\Felix\Api\Scalar\DateType;
use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\StringValueNode;
Expand All @@ -28,7 +28,7 @@ protected function tearDown(): void
public function testSerialize(): void
{
$type = new DateType();
$date = new Date('2010-02-03');
$date = new ChronosDate('2010-02-03');
$actual = $type->serialize($date);
self::assertSame('2010-02-03', $actual);
}
Expand All @@ -40,7 +40,7 @@ public function testParseValue(string $input, string $expected): void
{
$type = new DateType();
$actual = $type->parseValue($input);
self::assertInstanceOf(Date::class, $actual);
self::assertInstanceOf(ChronosDate::class, $actual);
self::assertSame($expected, $actual->format('c'));
}

Expand All @@ -53,7 +53,7 @@ public function testParseLiteral(string $input, string $expected): void
$ast = new StringValueNode(['value' => $input]);

$actual = $type->parseLiteral($ast);
self::assertInstanceOf(Date::class, $actual);
self::assertInstanceOf(ChronosDate::class, $actual);
self::assertSame($expected, $actual->format('c'));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Model/Traits/HasPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testToken(): void
$this->user->setPassword('money');
self::assertFalse($this->user->isTokenValid(), 'after password change token is invalid');

Chronos::setTestNow((new Chronos())->subDay(1));
Chronos::setTestNow((new Chronos())->subDays(1));
$token5 = $this->user->createToken();
Chronos::setTestNow(null);
self::assertEquals(32, mb_strlen($token5), 'must be exactly the length of DB field');
Expand Down

0 comments on commit 7aeedc5

Please sign in to comment.