-
Notifications
You must be signed in to change notification settings - Fork 131
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
Adds method_exists check to Model->__call() avoiding recursion issues for non-existent methods #75
Conversation
… for non-existent methods. Issue #74
You'll need to get a newer version of PHPUnit to run the tests. They require 3.7+. I use the phar file downloadable from the PHPUnit site as it is much easier than mucking around with the packages in Linux repositories or from PEAR. |
Same thing with 3.7:
When I hit the error producing line 327 of idiorm.php, I get the following evaluation in debug:
which causes this call to fail:
It seems a null db is passed in at step 11 as part of the tearDown function, but said db is required to not be null at a later point. In case it is relevant, the machine is running Ubuntu 13.04, with PHP 5.4.9-4. |
That is really weird. I am running the tests locally just fine and Travis-CI is also running the tests successfully. simon@Treffynnon:~/paris [master] $ php ../phpunit.phar
PHPUnit 3.7.24 by Sebastian Bergmann.
Configuration read from /home/simon/paris/phpunit.xml
.....................................................
Time: 78 ms, Memory: 4.50Mb
OK (53 tests, 61 assertions) |
Bizarre. Must be something funky with my setup. I'll log on to my home mac os x install and try it from there! |
And from my mac it works fine! Has to be an env problem - I'll just have to do the work from the mac!
|
I tried adding the following test to ParisTest.php, but when this is present I get a segmentation fault.
Clearly I am looking for false as the return value from the non-existent method call. Any suggestions? |
…n invalid method on Model
I think I've got the regression test working correctly, though I do get a segmentation fault rather than an assertion error when i remove the bug fix from the code and retest. |
I would suggest that it should throw an exception rather than return false: throw new Exception("Method $name() does not exist in class " . get_class($this)); |
…nction call to the class, updates regression test to expect the same
The reason why the original test was not working is because you are not getting an instance of So this pull request needs to be accompanied with change/pull request in Idiorm itself as well. |
Yeah, I realised that in the end :) The protection can exist independently in the Model class, though we obviously need to place it in any class that uses this type of functionality. Is it just the ORM class that needs the fix or will I find it elsewhere? I'll sort out the code and send a pull request this evening. Is everything in order with this patch now? |
Yes, looks good. Although I would like to have the original regression test included again as well. It should just be |
Ok, I'll add a test for idiorm when I fix ORM, and will restore the previous regression test to the Paris test suite when the idiorm work is done. |
Do we need a custom exception class to satisfy the old version of PHPUnit being used for PHP 5.2 testing by Travis? See sebastianbergmann/phpunit#454 for further details. |
Aside from that one file mentioned above this looks good. Thanks! |
Sorry, it was an unintended PHPStorm project file that shouldn't have been checked in. |
I think you just need to trigger fatal error, just like PHP without __call does. |
I don't like throwing uncatchable fatal errors from within a library as I feel this is something that should be an implementers decision. They can ignore it, allow the exception to halt proceedings or handle the exception in another way. |
I also get infinite recursions when trying to access nullable DB fields from Twig, via When using find_array() I can access the NULL field from Twig as expected. |
Hey @treffynnon . What is the fate of this pull request? Will it be merged? Is there anything that is still missing? |
@Cal127 it is earmarked for the 1.5.0 release milestone which is currently scheduled for the end of January. I have recently assigned all outstanding pull requests to a milestone. |
Thanks |
Merged in develop |
Re: Issue #74
I'll try to find some time to add a regression test for this.