Skip to content

Commit

Permalink
use Cake\I18n\DateTime instead Cake\I18n\FrozenTime
Browse files Browse the repository at this point in the history
  • Loading branch information
nojimage committed Feb 9, 2024
1 parent ef87ca0 commit b5d04e5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/Authenticator/CookieAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Authentication\UrlChecker\UrlCheckerTrait;
use Cake\Datasource\EntityInterface;
use Cake\Http\Cookie\Cookie;
use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\Utility\Hash;
use InvalidArgumentException;
Expand Down Expand Up @@ -188,7 +188,7 @@ protected function _saveToken(ArrayAccess|array $identity, string $token): Entit
'foreign_id' => $identity[$userTable->getPrimaryKey()],
'series' => static::_generateToken($identity),
'token' => $token,
'expires' => new FrozenTime($this->getConfig('cookie.expire')),
'expires' => new DateTime($this->getConfig('cookie.expire')),
]);

return $tokenTable->saveOrFail($entity);
Expand Down Expand Up @@ -247,10 +247,10 @@ public function clearIdentity(ServerRequestInterface $request, ResponseInterface
* Creates a cookie instance with configured defaults.
*
* @param string $value Cookie value.
* @param \Cake\I18n\FrozenTime|null $expires the Cookie expire
* @param \Cake\I18n\DateTime|null $expires the Cookie expire
* @return \Cake\Http\Cookie\Cookie
*/
protected function _createCookie(string $value, ?FrozenTime $expires = null): Cookie
protected function _createCookie(string $value, ?DateTime $expires = null): Cookie
{
$data = $this->getConfig('cookie');

Expand Down
4 changes: 2 additions & 2 deletions src/Identifier/RememberMeTokenIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Authentication\Identifier\Resolver\ResolverAwareTrait;
use Authentication\Identifier\Resolver\ResolverInterface;
use Cake\Datasource\EntityInterface;
use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use InvalidArgumentException;
use RuntimeException;

Expand Down Expand Up @@ -158,7 +158,7 @@ protected function _verifyToken(EntityInterface $token, string $verifyToken): bo
return false;
}

if (FrozenTime::now()->greaterThan($token['expires'])) {
if (DateTime::now()->greaterThan($token['expires'])) {
$this->_errors[] = 'token expired';

return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Entity/RememberMeToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* RememberMeToken Entity
*
* @property int $id
* @property \Cake\I18n\FrozenTime $created
* @property \Cake\I18n\FrozenTime $modified
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime $modified
* @property string $model
* @property string $foreign_id
* @property string $series
* @property string $token
* @property \Cake\I18n\FrozenTime $expires
* @property \Cake\I18n\DateTime $expires
*/
class RememberMeToken extends Entity
{
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Table/RememberMeTokensTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RememberMe\Model\Table;

use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
Expand Down Expand Up @@ -99,7 +99,7 @@ public function buildRules(RulesChecker $rules): RulesChecker
public function dropExpired(?string $userModel = null, string|int|null $foreignId = null): int
{
$conditions = [
$this->aliasField('expires <') => FrozenTime::now(),
$this->aliasField('expires <') => DateTime::now(),
];
if ($userModel !== null) {
$conditions[$this->aliasField('model')] = $userModel;
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Authenticator/CookieAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Cake\Http\Cookie\CookieInterface;
use Cake\Http\Response;
use Cake\Http\ServerRequestFactory;
use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -39,7 +39,7 @@ public function setUp(): void
*/
public function tearDown(): void
{
FrozenTime::setTestNow();
DateTime::setTestNow();
parent::tearDown();
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public function testAuthenticateInvalidCookie(): void
*/
public function testAuthenticateExpired(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:34');
DateTime::setTestNow('2017-10-01 11:22:34');
$identifiers = new IdentifierCollection([
'RememberMe.RememberMeToken' => [
'resolver' => [
Expand Down Expand Up @@ -199,7 +199,7 @@ public function testAuthenticateExpired(): void
*/
public function testAuthenticateValid(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:33');
DateTime::setTestNow('2017-10-01 11:22:33');
$identifiers = new IdentifierCollection([
'RememberMe.RememberMeToken' => [
'resolver' => [
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Identifier/RememberMeTokenIdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace RememberMe\Test\TestCase\Identifier;

use Authentication\Identifier\Resolver\OrmResolver;
use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cake\ORM\Entity;
use RememberMe\Identifier\RememberMeTokenIdentifier;
use RememberMe\Model\Entity\RememberMeToken;
Expand All @@ -20,7 +20,7 @@ class RememberMeTokenIdentifierTest extends TestCase
*/
public function tearDown(): void
{
FrozenTime::setTestNow();
DateTime::setTestNow();
parent::tearDown();
}

Expand All @@ -29,7 +29,7 @@ public function tearDown(): void
*/
public function testIdentifyValid(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:33');
DateTime::setTestNow('2017-10-01 11:22:33');
$resolver = $this->getMockBuilder(OrmResolver::class)
->disableOriginalConstructor()
->onlyMethods(['find'])
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testIdentifyValid(): void
*/
public function testIdentifyNotMatchSeries(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:33');
DateTime::setTestNow('2017-10-01 11:22:33');
$resolver = $this->getMockBuilder(OrmResolver::class)
->disableOriginalConstructor()
->onlyMethods(['find'])
Expand Down Expand Up @@ -94,7 +94,7 @@ public function testIdentifyNotMatchSeries(): void
*/
public function testIdentifyNotMatchToken(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:33');
DateTime::setTestNow('2017-10-01 11:22:33');
$resolver = $this->getMockBuilder(OrmResolver::class)
->disableOriginalConstructor()
->onlyMethods(['find'])
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testIdentifyNotMatchToken(): void
*/
public function testIdentifyExpired(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:34');
DateTime::setTestNow('2017-10-01 11:22:34');
$resolver = $this->getMockBuilder(OrmResolver::class)
->disableOriginalConstructor()
->onlyMethods(['find'])
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Model/Table/RememberMeTokensTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RememberMe\Test\TestCase\Model\Table;

use Cake\I18n\FrozenTime;
use Cake\I18n\DateTime;
use Cake\TestSuite\TestCase;
use RememberMe\Model\Table\RememberMeTokensTable;

Expand Down Expand Up @@ -85,20 +85,20 @@ public function testBuildRules(): void

public function testDropExpired(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:33');
DateTime::setTestNow('2017-10-01 11:22:33');
$deleteCount = $this->RememberMeTokens->dropExpired();
$this->assertSame(0, $deleteCount, 'not change');
$this->assertCount(6, $this->RememberMeTokens->find()->all(), 'not change');

FrozenTime::setTestNow('2017-10-01 11:22:34');
DateTime::setTestNow('2017-10-01 11:22:34');
$deleteCount = $this->RememberMeTokens->dropExpired();
$this->assertSame(3, $deleteCount);
$this->assertCount(3, $this->RememberMeTokens->find()->all());
}

public function testDropExpiredWithArgs(): void
{
FrozenTime::setTestNow('2017-10-01 11:22:34');
DateTime::setTestNow('2017-10-01 11:22:34');
$deleteCount = $this->RememberMeTokens->dropExpired('Users');
$this->assertSame(0, $deleteCount, 'not matching');
$this->assertCount(6, $this->RememberMeTokens->find()->all(), 'not matching');
Expand Down

0 comments on commit b5d04e5

Please sign in to comment.