From 9342407bef741d58c6d8efd71afe29d99ba7df35 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Thu, 11 Apr 2024 00:01:40 +0100 Subject: [PATCH] fixed tests according to the recent factory changes --- database/factories/JikanMediaModelFactory.php | 2 ++ tests/Integration/AnimeSearchEndpointTest.php | 6 +++--- tests/Integration/MangaSearchEndpointTest.php | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/database/factories/JikanMediaModelFactory.php b/database/factories/JikanMediaModelFactory.php index 9b41962..78aa748 100644 --- a/database/factories/JikanMediaModelFactory.php +++ b/database/factories/JikanMediaModelFactory.php @@ -62,6 +62,8 @@ abstract class JikanMediaModelFactory extends JikanModelFactory implements Media return $this->state($this->serializeStateDefinition($this->getStateOverrides($additionalParams, $doOpposite))); } + // we want to generate overrides for each manufactured item, so all of them will call the faker for values, + // and they should have their own values, increasing the randomness of the generated data /** @noinspection PhpParamsInspection */ return $this->state(new Sequence(fn(Sequence $_) => $this->serializeStateDefinition($this->getStateOverrides($additionalParams, $doOpposite)))); } diff --git a/tests/Integration/AnimeSearchEndpointTest.php b/tests/Integration/AnimeSearchEndpointTest.php index eb0314c..7184146 100644 --- a/tests/Integration/AnimeSearchEndpointTest.php +++ b/tests/Integration/AnimeSearchEndpointTest.php @@ -261,16 +261,16 @@ class AnimeSearchEndpointTest extends TestCase */ public function testSearchByEndDate($params) { - $overrides = $this->generateFiveSpecificAndTenRandomElementsInDb($params); + $this->generateFiveSpecificAndTenRandomElementsInDb($params); $content = $this->getJsonResponse($params); $actualEndDate = Carbon::parse(data_get($content, "data.0.aired.to")); - $paramEndDate = Carbon::parse($overrides["aired"]["to"]); + $paramEndDate = Carbon::parse($params['end_date']); $this->seeStatusCode(200); $this->assertPaginationData(5); - $this->assertLessThanOrEqual(0, $actualEndDate->diff($paramEndDate)->days); + $this->assertGreaterThanOrEqual(1, $actualEndDate->diff($paramEndDate)->days); // we created 5 elements according to parameters, so we expect 5 of them. $this->assertCount(5, $content["data"]); } diff --git a/tests/Integration/MangaSearchEndpointTest.php b/tests/Integration/MangaSearchEndpointTest.php index 0c5ff4c..fbc9d5b 100644 --- a/tests/Integration/MangaSearchEndpointTest.php +++ b/tests/Integration/MangaSearchEndpointTest.php @@ -243,16 +243,16 @@ class MangaSearchEndpointTest extends TestCase */ public function testSearchByEndDate($params) { - $overrides = $this->generateFiveSpecificAndTenRandomElementsInDb($params); + $this->generateFiveSpecificAndTenRandomElementsInDb($params); $content = $this->getJsonResponse($params); $actualEndDate = Carbon::parse(data_get($content, "data.0.published.to")); - $paramEndDate = Carbon::parse($overrides["published"]["to"]); + $paramEndDate = Carbon::parse($params["end_date"]); $this->seeStatusCode(200); $this->assertPaginationData(5); - $this->assertLessThanOrEqual(0, $actualEndDate->diff($paramEndDate)->days); + $this->assertGreaterThanOrEqual(1, $actualEndDate->diff($paramEndDate)->days); // we created 5 elements according to parameters, so we expect 5 of them. $this->assertCount(5, $content["data"]); }