IncrementInteger and preg_match_all #1559
-
Hi there, infection If an existing (much more complex) regex I use like this (very simplified example, no errors checks etc.): function foo($a) {
if (preg_match_all("/(\d)/", $a, $m)) {
return $m[0];
}
return [];
}
foo("1234"); var_dump of
My problem: the --- return $m[0];
+++ return $m[1]; But how can I "fix" this, i.e I don't see what test could cover this. Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi, on your example, If it doesn't matter which integer value is returned, then probably you can do the following:
|
Beta Was this translation helpful? Give feedback.
-
If you won't use the parentheses as in |
Beta Was this translation helpful? Give feedback.
Hi, on your example,
$m[0]
returns1
while$m[1]
returns2
, so we can write a test that checks exact value.If it doesn't matter which integer value is returned, then probably you can do the following:
return $m[0]
withcurrent($m)
.IncrementInteger
mutator in this case won't be appliedIncrementInteger
mutator in this method or even line of code. See how: https://infection.github.io/guide/how-to.html#How-to-disable-Mutators-and-profiles