Skip to content

Commit 99bb21e

Browse files
committed
Merge branch '1.3.x' into 1.4.x
2 parents ac8ea99 + 70ecacc commit 99bb21e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use ReflectionObject;
2424
use function array_key_exists;
2525
use function count;
26+
use function in_array;
2627
use function strlen;
2728
use function strpos;
2829
use function substr;
@@ -33,6 +34,12 @@ class AssertTypeSpecifyingExtensionHelper
3334
/** @var Closure[] */
3435
private static $resolvers;
3536

37+
/**
38+
* Those can specify types correctly, but would produce always-true issue
39+
* @var string[]
40+
*/
41+
private static $resolversCausingAlwaysTrue = ['ContainsOnlyInstancesOf', 'ContainsEquals', 'Contains'];
42+
3643
/**
3744
* @param Arg[] $args
3845
*/
@@ -87,10 +94,14 @@ public static function specifyTypes(
8794
if ($expression === null) {
8895
return new SpecifiedTypes([], []);
8996
}
97+
98+
$bypassAlwaysTrueIssue = in_array(self::trimName($name), self::$resolversCausingAlwaysTrue, true);
99+
90100
return $typeSpecifier->specifyTypesInCondition(
91101
$scope,
92102
$expression,
93-
TypeSpecifierContext::createTruthy()
103+
TypeSpecifierContext::createTruthy(),
104+
$bypassAlwaysTrueIssue ? new Expr\BinaryOp\BooleanAnd($expression, new Expr\Variable('nonsense')) : null
94105
);
95106
}
96107

tests/Rules/PHPUnit/data/assert-same.php

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public function testOther()
6565
$foo->assertSame();
6666
}
6767

68+
public function testAssertContains()
69+
{
70+
$this->assertContains('not in the list', new \ArrayObject([1]));
71+
$this->assertContainsEquals('not in the list', new \ArrayObject([1]));
72+
$this->assertNotContains('not in the list', new \ArrayObject([1]));
73+
}
74+
6875
public function testStaticMethodReturnWithSameTypeIsNotReported()
6976
{
7077
$this->assertSame(self::createSomething('foo'), self::createSomething('foo'));

0 commit comments

Comments
 (0)