Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
class DoWhileLoopConstantConditionRuleTest extends RuleTestCase
{

private bool $treatPhpDocTypesAsCertain = true;

protected function getRule(): Rule
{
return new DoWhileLoopConstantConditionRule(
Expand All @@ -21,20 +19,15 @@ protected function getRule(): Rule
self::createReflectionProvider(),
$this->getTypeSpecifier(),
[],
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
true,
);
}

protected function shouldTreatPhpDocTypesAsCertain(): bool
{
return $this->treatPhpDocTypesAsCertain;
}

public function testRule(): void
{
$this->analyse([__DIR__ . '/data/do-while-loop.php'], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
class LogicalXorConstantConditionRuleTest extends RuleTestCase
{

private bool $treatPhpDocTypesAsCertain;

private bool $reportAlwaysTrueInLastCondition = false;

protected function getRule(): TRule
Expand All @@ -23,11 +21,11 @@ protected function getRule(): TRule
self::createReflectionProvider(),
$this->getTypeSpecifier(),
[],
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
$this->reportAlwaysTrueInLastCondition,
true,
);
Expand All @@ -36,7 +34,6 @@ protected function getRule(): TRule
public function testRule(): void
{
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/logical-xor.php'], [
[
'Left side of xor is always true.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
class WhileLoopAlwaysFalseConditionRuleTest extends RuleTestCase
{

private bool $treatPhpDocTypesAsCertain = true;

protected function getRule(): Rule
{
return new WhileLoopAlwaysFalseConditionRule(
Expand All @@ -21,20 +19,15 @@ protected function getRule(): Rule
self::createReflectionProvider(),
$this->getTypeSpecifier(),
[],
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
true,
);
}

protected function shouldTreatPhpDocTypesAsCertain(): bool
{
return $this->treatPhpDocTypesAsCertain;
}

public function testRule(): void
{
$this->analyse([__DIR__ . '/data/while-loop-false.php'], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
class WhileLoopAlwaysTrueConditionRuleTest extends RuleTestCase
{

private bool $treatPhpDocTypesAsCertain = true;

protected function getRule(): Rule
{
return new WhileLoopAlwaysTrueConditionRule(
Expand All @@ -21,20 +19,15 @@ protected function getRule(): Rule
self::createReflectionProvider(),
$this->getTypeSpecifier(),
[],
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
true,
);
}

protected function shouldTreatPhpDocTypesAsCertain(): bool
{
return $this->treatPhpDocTypesAsCertain;
}

public function testRule(): void
{
$this->analyse([__DIR__ . '/data/while-loop-true.php'], [
Expand Down
4 changes: 1 addition & 3 deletions tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
class ArrayValuesRuleTest extends RuleTestCase
{

private bool $treatPhpDocTypesAsCertain = true;

protected function getRule(): Rule
{
return new ArrayValuesRule(
self::createReflectionProvider(),
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
true,
);
}
Expand Down
35 changes: 1 addition & 34 deletions tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,23 @@
class NullCoalesceRuleTest extends RuleTestCase
{

private bool $treatPhpDocTypesAsCertain;

protected function getRule(): Rule
{
return new NullCoalesceRule(new IssetCheck(
new PropertyDescriptor(),
new PropertyReflectionFinder(),
true,
$this->treatPhpDocTypesAsCertain,
$this->shouldTreatPhpDocTypesAsCertain(),
));
}

protected function shouldTreatPhpDocTypesAsCertain(): bool
{
return $this->treatPhpDocTypesAsCertain;
}

public function shouldNarrowMethodScopeFromConstructor(): bool
{
return true;
}

public function testCoalesceRule(): void
{
$this->treatPhpDocTypesAsCertain = true;
$errors = [
[
'Property CoalesceRule\FooCoalesce::$string (string) on left side of ?? is not nullable.',
Expand Down Expand Up @@ -146,7 +138,6 @@ public function testCoalesceRule(): void

public function testCoalesceAssignRule(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/null-coalesce-assign.php'], [
[
'Property CoalesceAssignRule\FooCoalesce::$string (string) on left side of ??= is not nullable.',
Expand Down Expand Up @@ -209,13 +200,11 @@ public function testCoalesceAssignRule(): void

public function testNullsafe(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/null-coalesce-nullsafe.php'], []);
}

public function testVariableCertaintyInNullCoalesce(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/variable-certainty-null.php'], [
[
'Variable $scalar on left side of ?? always exists and is not nullable.',
Expand All @@ -234,7 +223,6 @@ public function testVariableCertaintyInNullCoalesce(): void

public function testVariableCertaintyInNullCoalesceAssign(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/variable-certainty-null-assign.php'], [
[
'Variable $scalar on left side of ??= always exists and is not nullable.',
Expand All @@ -253,7 +241,6 @@ public function testVariableCertaintyInNullCoalesceAssign(): void

public function testNullCoalesceInGlobalScope(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/null-coalesce-global-scope.php'], [
[
'Variable $bar on left side of ?? always exists and is not nullable.',
Expand All @@ -264,15 +251,12 @@ public function testNullCoalesceInGlobalScope(): void

public function testBug5933(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-5933.php'], []);
}

#[RequiresPhp('>= 8.0')]
public function testBug7109(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/../Properties/data/bug-7109.php'], [
[
'Using nullsafe property access "?->aaa" on left side of ?? is unnecessary. Use -> instead.',
Expand All @@ -299,8 +283,6 @@ public function testBug7109(): void

public function testBug7190(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/../Properties/data/bug-7190.php'], [
[
'Offset int on array<int, int> on left side of ?? always exists and is not nullable.',
Expand All @@ -311,8 +293,6 @@ public function testBug7190(): void

public function testBug7318(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/../Properties/data/bug-7318.php'], [
[
"Offset 'unique' on array{unique: bool} on left side of ?? always exists and is not nullable.",
Expand All @@ -323,50 +303,37 @@ public function testBug7318(): void

public function testBug7968(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-7968.php'], []);
}

public function testBug8084(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-8084.php'], []);
}

public function testBug10577(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-10577.php'], []);
}

public function testBug11708(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-11708.php'], []);
}

public function testBug10610(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-10610.php'], []);
}

#[RequiresPhp('>= 8.4')]
public function testBug12553(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-12553.php'], []);
}

public function testIssetAfterRememberedConstructor(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/isset-after-remembered-constructor.php'], [
[
'Property IssetOrCoalesceOnNonNullableInitializedProperty\User::$string on left side of ?? is not nullable nor uninitialized.',
Expand Down
Loading