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
Compare revisions
b1eb1be14c564b86e219bc46a15e63fe739650f3 to bfa335211b14d8783dde428fb0a78b56884606c8
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
packages/doctrine-http-filter
Select target project
No results found
bfa335211b14d8783dde428fb0a78b56884606c8
Select Git revision
Branches
develop
master
Tags
v0.1.0
Swap
Target
packages/doctrine-http-filter
Select target project
packages/doctrine-http-filter
1 result
b1eb1be14c564b86e219bc46a15e63fe739650f3
Select Git revision
Branches
develop
master
Tags
v0.1.0
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
fix: Изменен фильтр Date
· 42a9cbae
Адлан Шамавов
authored
1 week ago
42a9cbae
tests: Доработаны тесты для дат
· bfa33521
Адлан Шамавов
authored
1 week ago
bfa33521
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Filter/Date.php
+3
-2
3 additions, 2 deletions
src/Filter/Date.php
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
31 additions
and
15 deletions
src/Filter/Date.php
View file @
bfa33521
...
...
@@ -20,10 +20,11 @@ final class Date extends HttpFilter
}
$queryBuilder
->
where
(
'SUBSTRING('
.
$this
->
getColumn
()
.
'
, 0, 11) = :'
.
$this
->
getParameterKey
()
,
$this
->
getColumn
()
.
'
BETWEEN :dateStart AND :dateEnd'
,
);
$queryBuilder
->
setParameter
(
$this
->
getParameterKey
(),
$this
->
getHttpValue
());
$queryBuilder
->
setParameter
(
'dateStart'
,
$this
->
getHttpValue
()
.
' 00:00:00'
);
$queryBuilder
->
setParameter
(
'dateEnd'
,
$this
->
getHttpValue
()
.
' 23:59:59'
);
return
$queryBuilder
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/FilterByDateRangeTest.php
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
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.