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
Family bc*-functions mutators (bcmath support) #658
Comments
A big 👍 for this mutator.
Could you please provide arguments? From my point of view, if developers of a particular project have And Infection should force them to write a test to prove We probably should skip mutating if extension is not loaded, just for better performance: // early return
protected function mutatesNode(Node $node): bool
{
if (!extension_loaded('bcmath')) {
return false;
}
// ...
} or even don't add this mutator to mutator list if the extension is not loaded, to prevent its execution for each traversed node. |
For one because bcmath functions work with strings of numbers, and first return value check will have these mutators busted. Example: var_dump('1' + '2'); \\ int(3)
var_dump(bcadd('1', '2')); \\ string(1) "3" That assuming strict types are enabled. |
We must cast to - $c = bcadd($a, b);
+ $c = (string) ($a + $b); |
This may work, but only before we get into the float territory. Bcmath functions do not exactly work with floats.
Otherwise put, just a single test that actually uses very large numbers will catch our mutations. That's a whole lot of mutations for all those functions busted by a single test. |
But this is the goal of this mutator - to force developers to write such a test (with big numbers or with floats), isn't it? What I mean: We have a method that uses public function add(string $a, string $b): string
{
return bcadd($a, $b);
} Then, such test is useless: assertSame('3', Calculator::add('1', '2')); and mutant won't be killed. And escaped mutant shows that This will force the developer to update such test to: assertSame('1333333333333333333', Calculator::add('11111111111111111111', '2222222222222222222'); if they really want to work with big numbers, or otherwise replace |
Agreed. I wonder if @majkel89 have some other arguments against having this enabled by default. |
I also agree. Mine only concern was performance but no I think it wont be a gig deal if we disable the mutator when the extension is not loaded. |
Similarly to #654 there should be bcmath support
Example
I think this mutator should be enabled on demand and not by default.
There should be one mutator for all bcmath functions
The text was updated successfully, but these errors were encountered: