mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
fixed buggy tests
This commit is contained in:
parent
f5f42b14d4
commit
8948dc1053
@ -65,7 +65,7 @@ final class CachedData implements ArrayAccess
|
|||||||
|
|
||||||
$expiry = $this->expiry();
|
$expiry = $this->expiry();
|
||||||
|
|
||||||
return time() > $expiry;
|
return Carbon::now()->unix() > $expiry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
|
@ -51,7 +51,7 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
public function testIfFindListReturnsNotExpiredItems()
|
public function testIfFindListReturnsNotExpiredItems()
|
||||||
{
|
{
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
// the cached data in the database
|
// the cached data in the database
|
||||||
// this should be an array of arrays as builder->get() returns multiple items
|
// this should be an array of arrays as builder->get() returns multiple items
|
||||||
@ -76,14 +76,14 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
public function testIfFindListUpdatesCacheIfItemsExpired()
|
public function testIfFindListUpdatesCacheIfItemsExpired()
|
||||||
{
|
{
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
|
|
||||||
// the cached data in the database
|
// the cached data in the database
|
||||||
// this should be an array of arrays as builder->get() returns multiple items
|
// this should be an array of arrays as builder->get() returns multiple items
|
||||||
$dummyResults = collect([[
|
$dummyResults = collect([[
|
||||||
"request_hash" => $testRequestHash,
|
"request_hash" => $testRequestHash,
|
||||||
"modifiedAt" => new UTCDateTime($now->sub("2 days")->getPreciseTimestamp(3)),
|
"modifiedAt" => new UTCDateTime($now->copy()->subDays(2)->getPreciseTimestamp(3)),
|
||||||
"results" => [
|
"results" => [
|
||||||
["dummy" => "dummy1"],
|
["dummy" => "dummy1"],
|
||||||
["dummy" => "dummy2"]
|
["dummy" => "dummy2"]
|
||||||
@ -128,7 +128,7 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
public function testIfFindListUpdatesCacheIfCacheIsEmpty()
|
public function testIfFindListUpdatesCacheIfCacheIsEmpty()
|
||||||
{
|
{
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
|
|
||||||
// the data returned by the scraper
|
// the data returned by the scraper
|
||||||
@ -175,7 +175,7 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$malId = 1;
|
$malId = 1;
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
$mockModel = Anime::factory()->makeOne([
|
$mockModel = Anime::factory()->makeOne([
|
||||||
"mal_id" => $malId,
|
"mal_id" => $malId,
|
||||||
@ -197,7 +197,7 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$malId = 1;
|
$malId = 1;
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
$mockModel = Anime::factory()->makeOne([
|
$mockModel = Anime::factory()->makeOne([
|
||||||
"mal_id" => $malId,
|
"mal_id" => $malId,
|
||||||
@ -224,11 +224,11 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$malId = 1;
|
$malId = 1;
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
$mockModel = Anime::factory()->makeOne([
|
$mockModel = Anime::factory()->makeOne([
|
||||||
"mal_id" => $malId,
|
"mal_id" => $malId,
|
||||||
"modifiedAt" => new UTCDateTime($now->sub("3 days")->getPreciseTimestamp(3)),
|
"modifiedAt" => new UTCDateTime($now->copy()->sub("3 days")->getPreciseTimestamp(3)),
|
||||||
"createdAt" => new UTCDateTime($now->sub("3 days")->getPreciseTimestamp(3))
|
"createdAt" => new UTCDateTime($now->copy()->sub("3 days")->getPreciseTimestamp(3))
|
||||||
]);
|
]);
|
||||||
$now = Carbon::now();
|
$now = Carbon::now();
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
@ -264,7 +264,7 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$username = "kompot";
|
$username = "kompot";
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
$mockModel = Profile::factory()->makeOne([
|
$mockModel = Profile::factory()->makeOne([
|
||||||
"username" => $username,
|
"username" => $username,
|
||||||
@ -287,7 +287,7 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$username = "kompot";
|
$username = "kompot";
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
$mockModel = Profile::factory()->makeOne([
|
$mockModel = Profile::factory()->makeOne([
|
||||||
"username" => $username,
|
"username" => $username,
|
||||||
@ -319,12 +319,12 @@ final class DefaultCachedScraperServiceTest extends TestCase
|
|||||||
$malId = 1;
|
$malId = 1;
|
||||||
$username = "kompot";
|
$username = "kompot";
|
||||||
$testRequestHash = $this->requestHash();
|
$testRequestHash = $this->requestHash();
|
||||||
$now = Carbon::now();
|
$now = Carbon::createFromDate(2022, 1, 11, "UTC")->addHours(8)->addMinutes(12);
|
||||||
$mockModel = Profile::factory()->makeOne([
|
$mockModel = Profile::factory()->makeOne([
|
||||||
"mal_id" => $malId,
|
"mal_id" => $malId,
|
||||||
"username" => $username,
|
"username" => $username,
|
||||||
"modifiedAt" => new UTCDateTime($now->sub("3 days")->getPreciseTimestamp(3)),
|
"modifiedAt" => new UTCDateTime($now->copy()->sub("3 days")->getPreciseTimestamp(3)),
|
||||||
"createdAt" => new UTCDateTime($now->sub("3 days")->getPreciseTimestamp(3))
|
"createdAt" => new UTCDateTime($now->copy()->sub("3 days")->getPreciseTimestamp(3))
|
||||||
]);
|
]);
|
||||||
$now = Carbon::now();
|
$now = Carbon::now();
|
||||||
Carbon::setTestNow($now);
|
Carbon::setTestNow($now);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user