diff --git a/composer.json b/composer.json index e4cb1d5..f371edf 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 3ce768b..b26b9af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d866e0a498e774b0ab2773613f30be83", + "content-hash": "c9430dd10915befe8e47e37dbf197824", "packages": [ { "name": "cakephp/chronos", - "version": "2.3.2", + "version": "2.4.0", "source": { "type": "git", "url": "https://github.com/cakephp/chronos.git", - "reference": "a21b7b633f483c4cf525d200219d200f551ee38b" + "reference": "9c7e438cba4eed1796ec19ad3874defa9eb9aeac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/chronos/zipball/a21b7b633f483c4cf525d200219d200f551ee38b", - "reference": "a21b7b633f483c4cf525d200219d200f551ee38b", + "url": "https://api.github.com/repos/cakephp/chronos/zipball/9c7e438cba4eed1796ec19ad3874defa9eb9aeac", + "reference": "9c7e438cba4eed1796ec19ad3874defa9eb9aeac", "shasum": "" }, "require": { @@ -62,7 +62,7 @@ "issues": "https://github.com/cakephp/chronos/issues", "source": "https://github.com/cakephp/chronos" }, - "time": "2022-11-08T02:17:04+00:00" + "time": "2023-08-06T22:54:27+00:00" }, { "name": "dflydev/fig-cookies", diff --git a/src/Api/Scalar/DateType.php b/src/Api/Scalar/DateType.php index ab29fcf..f53615d 100644 --- a/src/Api/Scalar/DateType.php +++ b/src/Api/Scalar/DateType.php @@ -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; @@ -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'); } @@ -34,13 +34,13 @@ 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; } @@ -48,7 +48,7 @@ public function parseValue(mixed $value): 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: diff --git a/src/DBAL/Types/DateType.php b/src/DBAL/Types/DateType.php index 2d043c2..968eecb 100644 --- a/src/DBAL/Types/DateType.php +++ b/src/DBAL/Types/DateType.php @@ -4,7 +4,7 @@ namespace Ecodev\Felix\DBAL\Types; -use Cake\Chronos\Date; +use Cake\Chronos\ChronosDate; use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -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; } diff --git a/tests/Api/Scalar/DateTypeTest.php b/tests/Api/Scalar/DateTypeTest.php index 5c61a34..060c39a 100644 --- a/tests/Api/Scalar/DateTypeTest.php +++ b/tests/Api/Scalar/DateTypeTest.php @@ -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; @@ -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); } @@ -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')); } @@ -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')); } diff --git a/tests/Model/Traits/HasPasswordTest.php b/tests/Model/Traits/HasPasswordTest.php index 7c833f3..faa39d3 100644 --- a/tests/Model/Traits/HasPasswordTest.php +++ b/tests/Model/Traits/HasPasswordTest.php @@ -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');