-
Notifications
You must be signed in to change notification settings - Fork 73
Mutation for functions #194
Comments
Hi, Out of curiosity I tried to reproduce your problem but it works fine with me (and Humbug mutates the function the same way). Here my test : public function test_deep_clone()
{
$o1 = (object) [];
$o1->foo = 'bar';
$o2 = deep_clone($o1);
self::assertEquals('bar', $o2->foo);
} and the result I got from humbug :
I could investigate more if you'd share your test. |
The problem is that in your example you have a method inside of a class I'm not sure if this check is still needed though. On Fri, 4 Nov 2016 14:04 Fabien Villepinte, notifications@github.com
|
Hi @villfa, thanks for looking into this :) Sorry for not actually double checking if that was still the case in a isolated environment, you can however find the real test on nelmio\alice. To install it:
The function in question is in |
@theofidry I think the problem is related with your humbug configuration. |
@villfa I excluded it to not have a failure, otherwise it gives the failure I described. |
@theofidry Ok, now I get it. |
And would cause an error if that was not the case :/ |
@theofidry I think I found a way to make it work but it's a bit dirty. In the composer configuration replace <?php
if (!getenv('DISABLE_FUNC_LOADING')) {
require_once __DIR__.'/functions.php';
} In Finally modify the tests by starting with this (you can improve this part) : <?php
require_once __DIR__.'/../src/functions.php';
//[...]
class FunctionsTest extends \PHPUnit_Framework_TestCase
//[...] That way it changes the loading order of the files and the mutated function can be loaded before the original. I didn't test it with the exact same environment but I think it will work. |
To be honest a simplier way would switch back to an OOP approach even if it's using a static function, but I kinda wanted to avoid that. I'm not fond of doing OOP blindly everywhere especially for something like that. I think your solution is the only viable one as long as composer doesn't "lazy load" functions :/ |
This is the occasion to bring some attention to the function autoloading RFC. |
We're having the same issue with the Amp test suite right now. Humbug should at least be fixed to exclude it automatically then instead of reporting it as escaped mutant. |
@kelunik you mean if Humbug come across a function (not a method), it skips mutants that could be applied to that function? I think it's reasonable, workaround in the meantime other is as said, add it to the ignored files in your config |
I did that, now it displays all of them as |
According to @MarkRedeman, only methods should be mutated currently, that's clearly not the case. I added a PR that should fix this and only mutate methods, see #201. |
Thanks for the PR! You're right, only methods should be mutated at present. This is certainly down to focusing on classes, and assuming only classes being tested, though that isn't necessarily where we should end things. I'll raise an issue re functions to at minimum document the limitation. |
Closing as a duplicate of #213 |
I have the following piece of code in my codebase:
And I have a test for it. Humbug mutate this function into:
Which should fail (if I change my source code into that, it does fail) but is not.
The text was updated successfully, but these errors were encountered: