Skip to content
Snippets Groups Projects
Commit bfa33521 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

tests: Доработаны тесты для дат

parent 42a9cbae
No related branches found
No related tags found
1 merge request!1Фильтры Like, ILike, Range, In, Date, DateRange
......@@ -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'),
],
],
]))
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment