diff --git a/tests/FilterByDateRangeTest.php b/tests/FilterByDateRangeTest.php index 0ce43203223f155b85aeee0978303e4ed69c489b..1c3bcf499a1e078d47eddcdc58b7a9d9eb4a8d35 100644 --- a/tests/FilterByDateRangeTest.php +++ b/tests/FilterByDateRangeTest.php @@ -40,13 +40,14 @@ class FilterByDateRangeTest extends TestCase $this->em->persist($post2); $this->em->flush(); + $firstDateWithDay = $firstDate->add(new DateInterval('P1D')); $result = $postRepository->createQueryByFilter([ 'createdAt' => DateRange::class, ], new Request([ HttpFilter::REQUEST_FILTER_KEY => [ 'createdAt' => [ 'from' => $firstDate->format('Y-m-d'), - 'to' => $firstDate->add(new DateInterval('P1D'))->format('Y-m-d'), + 'to' => $firstDateWithDay->format('Y-m-d'), ], ], ])) @@ -54,7 +55,10 @@ class FilterByDateRangeTest extends TestCase ->getResult(); $this->assertNotEmpty($result); - $this->assertCount(1, $result); + foreach ($result as $post) { + $this->assertGreaterThanOrEqual($firstDate->setTime(0, 0), $post->createdAt); + $this->assertLessThanOrEqual($firstDateWithDay->setTime(23, 59, 59), $post->createdAt); + } } public function testSuccessFilterDateRangeWithSeveralResults(): void @@ -83,13 +87,14 @@ class FilterByDateRangeTest extends TestCase $this->em->persist($post2); $this->em->flush(); + $firstDateWithDays = $firstDate->add(new DateInterval('P10D')); $result = $postRepository->createQueryByFilter([ 'createdAt' => DateRange::class, ], new Request([ HttpFilter::REQUEST_FILTER_KEY => [ 'createdAt' => [ 'from' => $firstDate->format('Y-m-d'), - 'to' => $firstDate->add(new DateInterval('P10D'))->format('Y-m-d'), + 'to' => $firstDateWithDays->format('Y-m-d'), ], ], ])) @@ -97,7 +102,10 @@ class FilterByDateRangeTest extends TestCase ->getResult(); $this->assertNotEmpty($result); - $this->assertCount(2, $result); + foreach ($result as $post) { + $this->assertGreaterThanOrEqual($firstDate->setTime(0, 0), $post->createdAt); + $this->assertLessThanOrEqual($firstDateWithDays->setTime(23, 59, 59), $post->createdAt); + } } public function testSuccessFilterDateRangeWithBoundaryResults(): void @@ -140,7 +148,10 @@ class FilterByDateRangeTest extends TestCase ->getResult(); $this->assertNotEmpty($result); - $this->assertCount(2, $result); + foreach ($result as $post) { + $this->assertGreaterThanOrEqual($firstDate->setTime(0, 0), $post->createdAt); + $this->assertLessThanOrEqual($secondDate->setTime(23, 59, 59), $post->createdAt); + } } public function testSuccessFilterDateRangeWithoutResults(): void @@ -174,8 +185,8 @@ class FilterByDateRangeTest extends TestCase ], new Request([ HttpFilter::REQUEST_FILTER_KEY => [ 'createdAt' => [ - 'from' => $firstDate->add(new DateInterval('P1Y'))->format('Y-m-d'), - 'to' => $secondDate->add(new DateInterval('P1Y'))->format('Y-m-d'), + 'from' => $firstDate->add(new DateInterval('P100Y'))->format('Y-m-d'), + 'to' => $secondDate->add(new DateInterval('P100Y'))->format('Y-m-d'), ], ], ])) diff --git a/tests/FilterByDateTest.php b/tests/FilterByDateTest.php index 506ecd277c56dfd5f1b76211e17905c836334f08..f28c0e7e668f3591184da81bc69ab68de2b56da6 100644 --- a/tests/FilterByDateTest.php +++ b/tests/FilterByDateTest.php @@ -50,8 +50,9 @@ class FilterByDateTest extends TestCase ->getResult(); $this->assertNotEmpty($result); - $this->assertCount(1, $result); - $this->assertEquals($date, current($result)->createdAt); + foreach ($result as $post) { + $this->assertEquals($date->format('Y-m-d'), $post->createdAt->format('Y-m-d')); + } } public function testSuccessFilterDateWithoutTime(): void @@ -90,8 +91,9 @@ class FilterByDateTest extends TestCase ->getResult(); $this->assertNotEmpty($result); - $this->assertCount(1, $result); - $this->assertEquals($date, current($result)->createdAt); + foreach ($result as $post) { + $this->assertEquals($date->format('Y-m-d'), $post->createdAt->format('Y-m-d')); + } } public function testSuccessFilterDateWithSeveralResults(): void @@ -131,7 +133,9 @@ class FilterByDateTest extends TestCase ->getResult(); $this->assertNotEmpty($result); - $this->assertCount(2, $result); + foreach ($result as $post) { + $this->assertEquals($firstDate->format('Y-m-d'), $post->createdAt->format('Y-m-d')); + } } public function testSuccessFilterDateRangeWithoutResults(): void @@ -163,7 +167,7 @@ class FilterByDateTest extends TestCase 'createdAt' => Date::class, ], new Request([ HttpFilter::REQUEST_FILTER_KEY => [ - 'createdAt' => $firstDate->add(new DateInterval('P1Y'))->format('Y-m-d'), + 'createdAt' => $firstDate->add(new DateInterval('P100Y'))->format('Y-m-d'), ], ])) ->getQuery()