Skip to content

Commit

Permalink
[#1148] PhpUnitTestsInspector: assertContains - respect PhpUnit versi…
Browse files Browse the repository at this point in the history
…on (via settings)
  • Loading branch information
kalessil committed Apr 26, 2020
1 parent 4a490c9 commit d7cc28f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void visitPhpMethodReference(@NotNull MethodReference reference) {
callbacks.add(() -> AssertInstanceOfStrategy.apply(methodName, reference, holder));
callbacks.add(() -> AssertResourceExistsStrategy.apply(methodName, reference, holder));
callbacks.add(() -> AssertCountStrategy.apply(methodName, reference, holder));
callbacks.add(() -> AssertContainsStrategy.apply(methodName, reference, holder));
callbacks.add(() -> AssertContainsStrategy.apply(methodName, reference, holder, PHP_UNIT_VERSION));
callbacks.add(() -> AssertRegexStrategy.apply(methodName, reference, holder));
/* AssertFileEqualsStrategy and AssertStringEqualsFileStrategy order is important */
callbacks.add(() -> AssertFileEqualsStrategy.apply(methodName, reference, holder));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public boolean atLeast(@NotNull PhpUnitVersion version) {
return this.compareTo(version) >= 0;
}

public boolean below(@NotNull PhpUnitVersion version) {
return this.compareTo(version) < 0;
}

@Override
public String toString() {
return this.version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.jetbrains.php.lang.psi.elements.FunctionReference;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.kalessil.phpStorm.phpInspectionsEA.fixers.PhpUnitAssertFixer;
import com.kalessil.phpStorm.phpInspectionsEA.inspectors.phpUnit.PhpUnitVersion;
import com.kalessil.phpStorm.phpInspectionsEA.utils.OpenapiTypesUtil;
import com.kalessil.phpStorm.phpInspectionsEA.utils.ReportingUtil;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -32,9 +33,9 @@ public class AssertContainsStrategy {

private final static String messagePattern = "'%s(...)' would fit more here.";

static public boolean apply(@NotNull String methodName, @NotNull MethodReference reference, @NotNull ProblemsHolder holder) {
static public boolean apply(@NotNull String methodName, @NotNull MethodReference reference, @NotNull ProblemsHolder holder, @NotNull PhpUnitVersion level) {
boolean result = false;
if (targetMapping.containsKey(methodName)) {
if (level.below(PhpUnitVersion.PHPUNIT90) && targetMapping.containsKey(methodName)) {
final PsiElement[] assertionArguments = reference.getParameters();
if (assertionArguments.length > 0 && OpenapiTypesUtil.isFunctionReference(assertionArguments[0])) {
final FunctionReference candidate = (FunctionReference) assertionArguments[0];
Expand Down

0 comments on commit d7cc28f

Please sign in to comment.