-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add check for adding param to method #801
Conversation
test/unit/DetectChanges/BCBreak/MethodBased/MethodParameterAddedTest.php
Show resolved
Hide resolved
use function array_map; | ||
|
||
/** | ||
* Adding a parameter to a method on a non-final class is a BC break |
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.
Let's add the "why" in this comment, and then we can merge :-)
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.
Nice! Updated :)
a212fbf
to
145d257
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.
🚢 thanks @AydinHassan!
@AydinHassan uh-oh, some more tests to add to cover the last introduced mutations Warning: Escaped Mutant for Mutator "LogicalOr":
--- Original
+++ New
@@ @@
{
public function __invoke(ReflectionMethod $fromMethod, ReflectionMethod $toMethod) : Changes
{
- if ($fromMethod->getDeclaringClass()->isFinal() || $fromMethod->isPrivate()) {
+ if ($fromMethod->getDeclaringClass()->isFinal() && $fromMethod->isPrivate()) {
return Changes::empty();
}
$added = array_diff(array_map(static fn(ReflectionParameter $param) => $param->getName(), $toMethod->getParameters()), array_map(static fn(ReflectionParameter $param) => $param->getName(), $fromMethod->getParameters()));
Warning: Escaped Mutant for Mutator "UnwrapArrayDiff":
--- Original
+++ New
@@ @@
if ($fromMethod->getDeclaringClass()->isFinal() || $fromMethod->isPrivate()) {
return Changes::empty();
}
- $added = array_diff(array_map(static fn(ReflectionParameter $param) => $param->getName(), $toMethod->getParameters()), array_map(static fn(ReflectionParameter $param) => $param->getName(), $fromMethod->getParameters()));
+ $added = array_map(static fn(ReflectionParameter $param) => $param->getName(), $toMethod->getParameters());
if ($toMethod->getNumberOfParameters() > $fromMethod->getNumberOfParameters()) {
return Changes::fromList(...array_map(static fn(string $paramName): Change => Change::added(Str\format('Parameter %s was added to Method %s() of class %s', $paramName, $fromMethod->getName(), $fromMethod->getDeclaringClass()->getName())), $added));
}
Warning: Escaped Mutant for Mutator "UnwrapArrayMap":
--- Original
+++ New
@@ @@
if ($fromMethod->getDeclaringClass()->isFinal() || $fromMethod->isPrivate()) {
return Changes::empty();
}
- $added = array_diff(array_map(static fn(ReflectionParameter $param) => $param->getName(), $toMethod->getParameters()), array_map(static fn(ReflectionParameter $param) => $param->getName(), $fromMethod->getParameters()));
+ $added = array_diff(array_map(static fn(ReflectionParameter $param) => $param->getName(), $toMethod->getParameters()), $fromMethod->getParameters());
if ($toMethod->getNumberOfParameters() > $fromMethod->getNumberOfParameters()) {
return Changes::fromList(...array_map(static fn(string $paramName): Change => Change::added(Str\format('Parameter %s was added to Method %s() of class %s', $paramName, $fromMethod->getName(), $fromMethod->getDeclaringClass()->getName())), $added));
}
Warning: Escaped Mutant for Mutator "GreaterThan":
--- Original
+++ New
@@ @@
return Changes::empty();
}
$added = array_diff(array_map(static fn(ReflectionParameter $param) => $param->getName(), $toMethod->getParameters()), array_map(static fn(ReflectionParameter $param) => $param->getName(), $fromMethod->getParameters()));
- if ($toMethod->getNumberOfParameters() > $fromMethod->getNumberOfParameters()) {
+ if ($toMethod->getNumberOfParameters() >= $fromMethod->getNumberOfParameters()) {
return Changes::fromList(...array_map(static fn(string $paramName): Change => Change::added(Str\format('Parameter %s was added to Method %s() of class %s', $paramName, $fromMethod->getName(), $fromMethod->getDeclaringClass()->getName())), $added));
}
return Changes::empty();
}
}
Warning: Dashboard report has not been sent: The current process is a pull request build This can be tested by expanding your data provider:
|
145d257
to
c24bfb5
Compare
@Ocramius I tried adding a few cases which I've just pushed. I also added some other tests that I since deleted but it doesn't seem to fix the escaped mutants. Sorry I don't have any experience with Infection and looks like I am fundamentally missing something. Whatever I change seems to have no effect :D edit: i'm a dumbass missed adding the provider cases edit 2: Ok I managed to kill a few but I'm a bit lost with the edit 3: Fixed the last one by deleting code 🔪 @Ocramius could you so kindly approve the workflow :) |
c24bfb5
to
c9c48e8
Compare
c9c48e8
to
b142ee6
Compare
and now you know how it works :-) |
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.
🚢 excellent!
thanks for the guidance and speed @Ocramius ! 🏎️ |
Heyy,
We recently encountered #750 and I had a quick stab at implementing it, to start the conversation off. I guess we should also support removing. Feedback welcome!
Fixes #750