Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 13, 2022
1 parent 28923f6 commit d4557a6
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
Expand Up @@ -63,4 +63,14 @@ public function testBug3264(): void
$this->analyse([__DIR__ . '/data/bug-3264.php'], []);
}

public function testBug5656(): void
{
$this->analyse([__DIR__ . '/data/bug-5656.php'], []);
}

public function testBug3867(): void
{
$this->analyse([__DIR__ . '/data/bug-3867.php'], []);
}

}
Expand Up @@ -488,4 +488,15 @@ public function testBug3366(): void
$this->analyse([__DIR__ . '/data/bug-3366.php'], []);
}

public function testBug5362(): void
{
$this->checkAlwaysTrueStrictComparison = true;
$this->analyse([__DIR__ . '/data/bug-5362.php'], [
[
'Strict comparison using === between 0 and 1|2 will always evaluate to false.',
23,
],
]);
}

}
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-3867.php
@@ -0,0 +1,24 @@
<?php

namespace Bug3867;

class Demo
{
public function analyze(): void
{
$try = [
"methodOne",
"methodTwo"
];

do {
$method = array_shift($try);

$result = $this->$method();

if (!empty($result)) {
break;
}
} while (count($try) > 0);
}
}
32 changes: 32 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-5362.php
@@ -0,0 +1,32 @@
<?php

namespace Bug5362;

class Foo
{

function doFoo(int $retry): void {
echo "\nfoo: ".$retry;
throw new \Exception();
}

function doBar()
{
$retry = 2;

do {
try {
$this->doFoo($retry);

break;
} catch (\Exception $e) {
if (0 === $retry) {
throw $e;
}

--$retry;
}
} while ($retry > 0);
}

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

namespace Bug5656;

function okpoValidate(array $values): bool
{
$c = count($values);
if (8 !== $c && 10 !== $c) {
return false;
}

$expected = array_pop($values);

$control = 0;
for ($start = 1; $start <= 3; $start += 2) {
$i = $start;
$control = 0;
foreach ($values as $v) {
if ($i > 10) {
$i = 1;
}
$control += $i * $v;
++$i;
}

$control %= 11;

if (10 !== $control) {
break;
}
}

if (10 === $control) {
$control = 0;
}

return $expected === $control;
}

$values = [0, 1, 0, 6, 0, 6, 2, 3, 1, 5];
okpoValidate($values);

0 comments on commit d4557a6

Please sign in to comment.