-
-
Notifications
You must be signed in to change notification settings - Fork 101
Improve qb validation #553
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
If we can cover it in a functional test (or switch to using prophecy maybe) then thats fine. Will havecloser look later. Lukas Kahwe Smith notifications@github.com wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
+1 for remove if you are sure all cases are covered by functional tests. |
I will have a look |
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.
Not all nodes have the getField
method, this is why the test failed.
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.
so the tests exposed a bug?
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.
Yeah, that happrens sometimes :P
I made a PR against this PR. The tests were not as bad as I thought and I think that the complexity is fine and they were infact revealing a bug. Only the DynamicField operator has the |
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.
guess this can be reverted now?
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.
Looks that way
btw, the tests can certainly be improved (e.g. prophecy would avoid that nasty callback hack), and it was by chance, not design, that the test caught that bug. But I think that Unit tests are valuable, even if they don't seem to be sometimes. |
i am just not a fan of unit tests with complex mocks. any refactoring requires huge refactorings in the tests which just increases the work and reduced certainty. more over .. those unit tests are simply way too hard to comprehend. if you have to mock more than 2-3 methods imho its not worth it and functional tests are the better choice. |
I suppose its a matter of approach. When I write functional tests they are usually A-B. The aim of unit tests is to cover every pathway. By writing unit tests with code coverage analysis we can uncover bugs that we didn't expect to be there. I guess you can do the same with functional tests, but its not as responsive (re. latatency), the scope of functional tests is far more vague and subject to abuse and you have cross-cutting concerns. I agree that unit tests which are so complicated that they are impossible to maintain are worthless. But this just menas we need to write better unit tests or use better tools. Like I said before I don't think this unit test is impossible to maintain (although some of them might be). It didn't need huge refactoring (it just needed an additional test and a modification of the factory mock), In general the tests could certainly be improved and made more comprehensive and comprehensible. But so far I am quite pleased with the stability of the query builder, I don't think there have been too many bugs, and I think thats thanks to these tests. |
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.
maybe the method name is not ideal, but is this method just for handling order by?
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.
No iirc, its for handling all dynamic operands, e.g. ->field('a.foo')
(i.e. PropertyValueInterface
in PHPCR) or ->length('a.foo')
(PHPCR LengthInterface
).
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.
but why did you assume in the error that the method is being called for an ordering?
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.
in other words. i am still unsure if your changes make sense or just please the unit tests
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.
in my original commit we only checked for nodetype and associations inside the foreach for orderings:
5fa4e2c#diff-0f74c7373c7c111b598f851ef2957d0eR760
I am still not sure where the issue was with that version of the PR
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.
In your version you call ->getField
in the ordering walker. But ->getField
only applies to the OperandDynamicField
node, not to any of the other DynamicOperands (length, lowercase, localname) etc.
The error message should be about not being able to use the nodename (or an association) field as a dynamic operand.
In fact we should probably just simply check to see if the field is mapped to a something which corresponds to a PHPCR property?
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.
yeah .. for ordering it needs to be a "simple name", ie. a property.
for filtering it should additionally not allow node names and associations.
for reference associations i am actually not quite sure if we should not allow equality conditions.
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.
So by having this here we also prevent:
$qb->where()->eq()->field('a.nodenamefield')->literal('foo');
because the user should be doing
$qb->where()->eq()->localname('a')->literal('foo');
I think.
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 have pushed an improvement for this.
Fixed validation
1b13202
to
8fc1db1
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.
tweaked the exception messages in this method
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.
The DynamicOperand could also be the right-hand side of the operation, would this still be called filtering?
"Cannot use nodename property "%s->%s" in a field operand" ?
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.
btw .. why don't we just convert it to the equivalent sql2 function call?
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 mean automatically convert it to a localname operand? I think that would just give people the wrong idea. We could suggest to the developer that they change it in the exception message however.
I guess it might also be possible to add more abstraction, but it would require some thought. The design principle behind this QB was to not making any abstractions as far as possible so as to keep the full power of the PHPCR query system.
@dantleech would appreciate some feedback on this |
@lsmith77 will try and have a look tomorrow morning before the summercamp :) |
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.
Same
6857611
to
9bab892
Compare
@dantleech can you have another look? |
@lsmith77 why did you merge this without commenting on my last comment? I don't agree with the code in this PR in its current state. |
sorry .. I didn't see the comment and you didn't reply to my "have another look" comment. so in the end .. if you can provide a better solution until tomorrow that doesn't do a huge refactoring, then awesome! otherwise at this point I rather get something stable release soon, which means doing an RC in the next 1-2 days. though before we do the next RC I hope we also fix #557 |
Ah, I assumed you would get a notification anyway. Its unfortunate as we could have probably worked out a solution. But as I said I am not happy with this - it only covers the orderBy walker and it duplicates code. If we care about maintaining quality code we should not have incomplete features imo. As I said I would be happy with this if we remove the validation from the orderBy and have only in its proper place. This already improves the situation without compromising the consistency. If you agree I will make a PR. |
like I said, if you can do a PR by tomorrow that doesn't contain a large refactoring of the code, then that is awesome! |
fixes some bugs in the tests, also fixes #541
note
Doctrine\Tests\ODM\PHPCR\Query\Builder\BuilderConverterPhpcrTest::testOrderBy
is failing .. but honestly I don't really think such a test makes sense. It is way too complex to test as it requires so much mocking. IMHO we are better off testing this via the various existing functional test. So I vote for removing that test./cc @dantleech