Skip to content
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

Add DateInterval type parameter #6734

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": "^7.1",
"ext-pdo": "*",
"doctrine/collections": "^1.4",
"doctrine/dbal": ">=2.5-dev,<2.7-dev",
"doctrine/dbal": "^2.6",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we allow >=2.7-dev intentionally here or is it just accidental?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set it up intentionally for look at tests and they were passed, so I think it's ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was accidental =) It should indeed be >=2.6-dev,<2.7-dev or even >=2.6-dev,<2.8-dev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With how carefully we're checking BC, does it even matter? Might as well use the semver operator here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true... @Majkl578 @Ocramius anything against that?

"doctrine/instantiator": "~1.1",
"doctrine/common": "^2.7.1",
"doctrine/cache": "~1.6",
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Query/ParameterTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public static function inferType($value)
return Type::DATETIME;
}

if ($value instanceof \DateInterval) {
return Type::DATEINTERVAL;
}

if (is_array($value)) {
return is_int(current($value))
? Connection::PARAM_INT_ARRAY
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ class ParameterTypeInfererTest extends OrmTestCase

public function providerParameterTypeInferer()
{
$data = [
$data = [
[1, Type::INTEGER],
["bar", PDO::PARAM_STR],
["1", PDO::PARAM_STR],
[new \DateTime, Type::DATETIME],
[new \DateInterval('P1D'), Type::DATEINTERVAL],
[[2], Connection::PARAM_INT_ARRAY],
[["foo"], Connection::PARAM_STR_ARRAY],
[["1","2"], Connection::PARAM_STR_ARRAY],
[[], Connection::PARAM_STR_ARRAY],
[true, Type::BOOLEAN],
];
];

if (PHP_VERSION_ID >= 50500) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but we can simplify this since we require PHP 7.1+

$data[] = [new \DateTimeImmutable(), Type::DATETIME];
Expand Down