-
-
Notifications
You must be signed in to change notification settings - Fork 921
Use database type conversion in Filters (test postgres+mysql) #1480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems very weird that Doctrine isn't in charge of that
@@ -185,7 +191,7 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf | |||
)); | |||
} | |||
|
|||
$queryBuilder->setParameter($valueParameter, new \DateTime($value)); | |||
$queryBuilder->setParameter($valueParameter, $type->convertToDatabaseValue(new \DateTime($value), $queryBuilder->getEntityManager()->getConnection()->getDatabasePlatform())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if $type
is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the condition before but removed it. Indeed Type::getType
will throw if not found (in getDateType
).
What I can do:
- test for
hasType
- Use what we had before when
null
Though, this method will only be called when the Type
is available in the DOCTRINE_DATE_TYPES
constant. Therefore, it's not really useful because it'll never be null
(those are all defined by default).
Scenario: Get collection filtered by date that is not a datetime | ||
Given there is "30" dummydate objects with dummyDate | ||
When I send a "GET" request to "/dummy_dates?dummyDate[after]=2015-04-28" | ||
Then the response status code should be 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't test anything in here if you don't test the content of the response. Therefore, I don't understand what is this test trying to prove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I run this test on my database without the patch it fails to status code 500
. This is just to ensure a non-regression.
And it's totally useless on sqlite
haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it affects MySQL or Postgres? it it is the case, maybe should we also run the Behat test suite with such DBMS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as they have two types for dates (ie date vs datetime) yes. And yes I think we should.
I came across this when using a date
on an index (it's weird to keep time on an index imo).
Indeed it surprised me as well but according to what I quoted from the docs the behavior is correct no? |
tests/Fixtures/app/config/config.yml
Outdated
driver: 'pdo_sqlite' | ||
path: '%kernel.cache_dir%/db.sqlite' | ||
charset: 'UTF8' | ||
default_connection: '%default_connection%' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made an attempt with %env(DEFAULT_CONNECTION)%
which would've been cleaner IMO but because this is an alias it doesn't work, see symfony/symfony#21609
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use different environments with multiple config files instead (config_test.yml
, config_test_mysql.yml
, config_test_pgsql
)? Then you just have to set the APP_ENV
environment variable in your Travis config instead of doing cp
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this mean that I'd have to copy the whole configuration file 3 times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop:
config_test.yaml
: the whole configuration +
doctrine:
dbal:
driver: 'pdo_sqlite'
path: '%kernel.cache_dir%/db.sqlite'
charset: 'UTF8'
config_test_mysql.yaml
:
imports:
- { resource: config_test.yaml }
doctrine:
dbal:
driver: pdo_mysql
path: ~
dbname: 'api_platform_test'
user: 'travis'
password: ''
host: 'localhost'
etc.
f6c0f7b
to
9e7d479
Compare
c5aaf1b
to
9528880
Compare
c8262c6
to
620d25d
Compare
e503023
to
dba1cea
Compare
76297af
to
b5780eb
Compare
4bf9863
to
5bf30c4
Compare
ff46042
to
a586b2e
Compare
All green :D. ping @sroze @dunglas @meyerbaptiste would love some review on this. I've simplified the pull request:
We could argue that there is a BC break where Let me know your thoughts! |
ad52ada
to
c76edc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments, then 👍 for me.
imports: | ||
- { resource: config_test.yml } | ||
|
||
doctrine: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should use environment variables to allow to run test locally (same for Postgres).
tests/Fixtures/app/console
Outdated
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); | ||
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; | ||
$env = $input->getParameterOption(array('--env', '-e'), $_SERVER['APP_ENV'] ?? null ?: 'test'); | ||
$debug = ($_SERVER['SYMFONY_DEBUG'] ?? null) !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$_SERVER['SYMFONY_DEBUG'] ?? 0
?
tests/Fixtures/app/console
Outdated
@@ -13,8 +13,8 @@ use Symfony\Component\Console\Input\ArgvInput; | |||
use Symfony\Component\Debug\Debug; | |||
|
|||
$input = new ArgvInput(); | |||
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); | |||
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; | |||
$env = $input->getParameterOption(array('--env', '-e'), $_SERVER['APP_ENV'] ?? null ?: 'test'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$_SERVER['SYMFONY_DEBUG'] ?? 'test'
?
Test multiple dbms
c76edc0
to
c25b81b
Compare
$environment = $this->getEnvironment(); | ||
|
||
// patch for behat not supporting %env(APP_ENV)% in older versions | ||
if ($appEnv = $_SERVER['APP_ENV'] ?? null && $appEnv !== $environment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not it be if (($appEnv = $_SERVER['APP_ENV'] ?? null) && $appEnv !== $environment) {
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, fixed by #1524.
Use database type conversion in Filters (test postgres+mysql)
Stated in Advanced field value conversion using custom mapping types:
We won't see any difference in sqlite for example (know why here) but I'm definitely seeing one in Oracle where the date parameter has the wrong format and therefore leads to a bad query. Maybe we should use this also in numeric filters.
/edit:
I wouldn't think this would be so hard haha. Few bugs discovered:
9.3
) will throw (fixed but changes behavior as they're ignored)LIKE
filters are case insensitive whereas postgres is case sensitive. This renders a few tests useless on sqlite.features/numeric_filters
we DO NOT test the numeric filter but only the search filter... (renamed)id
andassociations
) maybe this should've been calledtext_filter
. For example we can't say that an identifier is always namedid
assumption made here (fixed by using metadata)tags.feature
fail on postgresql?fos_user.feature
fail? My guess is bad table name?Debug instructions: