Skip to content

Commit 1944d09

Browse files
committed
refactor time with time class into Test class.
1 parent 518590b commit 1944d09

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

system/Test/Fabricator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Test;
1313

1414
use CodeIgniter\Exceptions\FrameworkException;
15+
use CodeIgniter\I18n\Time;
1516
use CodeIgniter\Model;
1617
use Faker\Factory;
1718
use Faker\Generator;
@@ -503,7 +504,7 @@ protected function createMock(?int $count = null)
503504
break;
504505

505506
default:
506-
$datetime = time();
507+
$datetime = Time::now()->getTimestamp();
507508
}
508509

509510
// Determine which fields we will need

system/Test/Mock/MockCache.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Closure;
1515
use CodeIgniter\Cache\CacheInterface;
1616
use CodeIgniter\Cache\Handlers\BaseHandler;
17+
use CodeIgniter\I18n\Time;
1718
use PHPUnit\Framework\Assert;
1819

1920
class MockCache extends BaseHandler implements CacheInterface
@@ -100,7 +101,7 @@ public function save(string $key, $value, int $ttl = 60, bool $raw = false)
100101
$key = static::validateKey($key, $this->prefix);
101102

102103
$this->cache[$key] = $value;
103-
$this->expirations[$key] = $ttl > 0 ? time() + $ttl : null;
104+
$this->expirations[$key] = $ttl > 0 ? Time::now()->getTimestamp() + $ttl : null;
104105

105106
return true;
106107
}
@@ -221,7 +222,7 @@ public function getMetaData(string $key)
221222
}
222223

223224
// Count expired items as a miss
224-
if (is_int($this->expirations[$key]) && $this->expirations[$key] > time()) {
225+
if (is_int($this->expirations[$key]) && $this->expirations[$key] > Time::now()->getTimestamp()) {
225226
return null;
226227
}
227228

system/Test/Mock/MockSession.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Test\Mock;
1313

1414
use CodeIgniter\Cookie\Cookie;
15+
use CodeIgniter\I18n\Time;
1516
use CodeIgniter\Session\Session;
1617

1718
/**
@@ -56,7 +57,7 @@ protected function startSession()
5657
*/
5758
protected function setCookie()
5859
{
59-
$expiration = $this->sessionExpiration === 0 ? 0 : time() + $this->sessionExpiration;
60+
$expiration = $this->sessionExpiration === 0 ? 0 : Time::now()->getTimestamp() + $this->sessionExpiration;
6061
$this->cookie = $this->cookie->withValue(session_id())->withExpires($expiration);
6162

6263
$this->cookies[] = $this->cookie;
@@ -65,6 +66,6 @@ protected function setCookie()
6566
public function regenerate(bool $destroy = false)
6667
{
6768
$this->didRegenerate = true;
68-
$_SESSION['__ci_last_regenerate'] = time();
69+
$_SESSION['__ci_last_regenerate'] = Time::now()->getTimestamp();
6970
}
7071
}

system/Test/TestResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\HTTP\RedirectResponse;
1515
use CodeIgniter\HTTP\RequestInterface;
1616
use CodeIgniter\HTTP\ResponseInterface;
17+
use CodeIgniter\I18n\Time;
1718
use Config\Services;
1819
use Exception;
1920
use PHPUnit\Framework\Constraint\IsEqual;
@@ -339,7 +340,7 @@ public function assertCookieMissing(string $key)
339340
public function assertCookieExpired(string $key, string $prefix = '')
340341
{
341342
$this->assertTrue($this->response->hasCookie($key, null, $prefix));
342-
$this->assertGreaterThan(time(), $this->response->getCookie($key, $prefix)->getExpiresTimestamp());
343+
$this->assertGreaterThan(Time::now()->getTimestamp(), $this->response->getCookie($key, $prefix)->getExpiresTimestamp());
343344
}
344345

345346
// --------------------------------------------------------------------

0 commit comments

Comments
 (0)