Skip to content

Commit

Permalink
Regression tests for NumberComparisonOperatorsConstantConditionRule
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 20, 2023
1 parent bf778f8 commit 5e5d1b5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Expand Up @@ -195,4 +195,16 @@ public function testTreatPhpDocTypesAsCertain(bool $treatPhpDocTypesAsCertain, a
$this->analyse([__DIR__ . '/data/number-comparison-treat.php'], $expectedErrors);
}

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

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

}
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-6776.php
@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);

namespace Bug6776;

class HelloWorld
{
/**
* @param positive-int|null $date
*/
public function sayHello(?int $date): void
{
if($date !== null && $date < 1){
throw new \InvalidArgumentException();
}
}
}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-7075.php
@@ -0,0 +1,18 @@
<?php

namespace Bug7075;

/** @param int<0, 100> $b */
function foo(int $b): void {
if ($b > 100) throw new \Exception("bad");
print "ok";
}

/**
* @param int<1,max> $number
*/
function foo2(int $number): void {
if ($number < 1) {
throw new \Exception('Number cannot be less than 1');
}
}

0 comments on commit 5e5d1b5

Please sign in to comment.