Fixes 381 - Allows zero as a parameter for the expression constructor #382
Fixes 381 - Allows zero as a parameter for the expression constructor #382
Conversation
@albertor24 What about |
I thought only |
@albertor24 I was looking on it and it looks like scalars should be allowed there as well. See: zend-db/src/Sql/Expression.php Lines 91 to 95 in 4c68f2c
It's quite old code (2012?) so it's possible that types in phpdocs are wrong... |
0deb850
to
fccfb07
Compare
I updated the code to have the same behaviour as the |
fccfb07
to
b76eadd
Compare
@albertor24 I had a look on it again, and honestly I think the condition there should be as simple as: if ($parameters !== null) {
$this->setParameters($parameters);
} So we don't really care about types in the constructor, as the setter is doing proper checks and throw exception if needed - and - we always pass the value through if provided (different than default I would add also a test, that any other value provided (not a scalar and not an array) we should get exception on instantiation. |
That seems very reasonable. My only concern with that is that it could be considered a breaking change, since without those changes invalid values would have been ignored instead of raising an error. Let me know if that's OK, and I will make all the required changes. Thank you very much for your help! |
What invalid values you have in mind? See this: https://3v4l.org/jVcag
Also an empty array is not a problem - because please note - the default value of Do I miss something? |
Invalid values would be any objects. However, now that you point it out, I agree that most likely won't be used. I will make the required changes in a bit. |
@albertor24 Any object (even empty
so we are not changing functionality :) You can add the test - check if before you change and after, to confirm that is not changed. |
b76eadd
to
abc8db8
Compare
You're totally correct. Thank you very much! |
test/unit/Sql/ExpressionTest.php
Outdated
|
||
public function testConstructorWithFalsyValidParameters() | ||
{ | ||
$falsyParameters = ['0', false, 0, [], 0.0]; |
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 think it will be better to use data provider.
Also you've missed empty string here.
test/unit/Sql/ExpressionTest.php
Outdated
|
||
public function testConstructorWithInvalidParameter() | ||
{ | ||
$this->expectException('Zend\Db\Sql\Exception\InvalidArgumentException'); |
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.
We can use ::class
notation I believe.
5450c91
to
ba72c6b
Compare
Fixed your comments. Thank you for spending the time to review the PR. |
ba72c6b
to
082bbe9
Compare
082bbe9
to
5119680
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.
@albertor24 LGTM 👍
Thanks, @albertor24! |
Fixes 381 - Allows zero as a parameter for the expression constructor
Correctly sets Sql Expression Parameter when passing '0' as the second parameter in the constructor.