Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Doctrine HTTP Filter
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Packages
Doctrine HTTP Filter
Commits
bfa33521
Commit
bfa33521
authored
1 week ago
by
Адлан Шамавов
Browse files
Options
Downloads
Patches
Plain Diff
tests: Доработаны тесты для дат
parent
42a9cbae
No related branches found
No related tags found
1 merge request
!1
Фильтры Like, ILike, Range, In, Date, DateRange
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/FilterByDateRangeTest.php
+18
-7
18 additions, 7 deletions
tests/FilterByDateRangeTest.php
tests/FilterByDateTest.php
+10
-6
10 additions, 6 deletions
tests/FilterByDateTest.php
with
28 additions
and
13 deletions
tests/FilterByDateRangeTest.php
+
18
−
7
View file @
bfa33521
...
...
@@ -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'
=>
$firstDate
WithDay
->
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'
=>
$firstDate
WithDays
->
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
(
'P1
00
Y'
))
->
format
(
'Y-m-d'
),
'to'
=>
$secondDate
->
add
(
new
DateInterval
(
'P1
00
Y'
))
->
format
(
'Y-m-d'
),
],
],
]))
...
...
This diff is collapsed.
Click to expand it.
tests/FilterByDateTest.php
+
10
−
6
View file @
bfa33521
...
...
@@ -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
(
'P1
00
Y'
))
->
format
(
'Y-m-d'
),
],
]))
->
getQuery
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment