Skip to content

Commit

Permalink
added more integer range vs. int constants tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab authored and staabm committed Oct 3, 2022
1 parent 8657382 commit dc6a384
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Expand Up @@ -475,5 +475,32 @@ public function testBug6356b(): void
],
]);
}

public function testIntegerRangesAndConstants(): void
{
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/int-ranges-and-constants.php'], [
[
'Property IntegerRangesAndConstants\HelloWorld::$i (0|1|3) does not accept int<0, 3>.',
17,
],
[
'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|2|3|string.',
42,
],
[
'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|2|3|bool.',
43,
],
[
'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|3|bool.',
44,
],
[
'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|3|4.',
45,
],
]);
}

}
47 changes: 47 additions & 0 deletions tests/PHPStan/Rules/Properties/data/int-ranges-and-constants.php
@@ -0,0 +1,47 @@
<?php

namespace IntegerRangesAndConstants;

class HelloWorld
{
/** @var 0|1|3 */
public $i = 0;
/** @var 0|1|2|3|string */
public $j = 0;
/** @var 0|1|bool|2|3 */
public $k = 0;
/** @var 0|1|2|3|4|5 */
public $l;

public function test(): void {
$this->i = random_int(0, 3);
$this->j = random_int(0, 3);
$this->k = random_int(0, 3);
$this->l = random_int(0, 3);
}

/**
* @var int<0,3>
*/
public $x = 0;

/**
* @param 0| $a
* @param 0|1 $b
* @param 0|1|3 $c
* @param 0|1|2|3|string $j
* @param 0|1|bool|2|3 $k
* @param 0|1|bool|3 $l
* @param 0|1|3|4 $m
*/
public function test2($a, $b, $c, $j, $k, $l, $m): void {
$this->x = $a;
$this->x = $b;
$this->x = $c;

$this->x = $j;
$this->x = $k;
$this->x = $l;
$this->x = $m;
}
}

0 comments on commit dc6a384

Please sign in to comment.