Skip to content

Commit bfa7b29

Browse files
committed
Arithmetic operators - levels tests
1 parent c58d339 commit bfa7b29

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Levels;
4+
5+
class LevelsIntegrationTest extends \PHPStan\Testing\LevelsTestCase
6+
{
7+
8+
/**
9+
* @return string[][]
10+
*/
11+
public function dataTopics(): array
12+
{
13+
return [
14+
['arithmeticOperators'],
15+
];
16+
}
17+
18+
public function getDataPath(): string
19+
{
20+
return __DIR__ . '/data';
21+
}
22+
23+
public function getPhpStanExecutablePath(): string
24+
{
25+
return __DIR__ . '/../../vendor/bin/phpstan';
26+
}
27+
28+
public function getPhpStanConfigPath(): ?string
29+
{
30+
return __DIR__ . '/../../rules.neon';
31+
}
32+
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"message": "Only numeric types are allowed in +, string given on the left side.",
4+
"line": 26,
5+
"ignorable": true
6+
},
7+
{
8+
"message": "Only numeric types are allowed in +, string given on the left side.",
9+
"line": 27,
10+
"ignorable": true
11+
},
12+
{
13+
"message": "Only numeric types are allowed in +, int|string given on the left side.",
14+
"line": 28,
15+
"ignorable": true
16+
},
17+
{
18+
"message": "Only numeric types are allowed in +, int|string given on the left side.",
19+
"line": 29,
20+
"ignorable": true
21+
},
22+
{
23+
"message": "Only numeric types are allowed in +, string given on the left side.",
24+
"line": 43,
25+
"ignorable": true
26+
}
27+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"message": "Binary operation \"+\" between string and int results in an error.",
4+
"line": 26,
5+
"ignorable": true
6+
},
7+
{
8+
"message": "Binary operation \"+\" between stdClass|string and int results in an error.",
9+
"line": 36,
10+
"ignorable": true
11+
}
12+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"message": "Binary operation \"+\" between int|string and int results in an error.",
4+
"line": 28,
5+
"ignorable": true
6+
}
7+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Levels\ArithmeticOperators;
4+
5+
class Foo
6+
{
7+
8+
/**
9+
* @param int $int
10+
* @param string $string
11+
* @param int|string $intOrString
12+
*/
13+
public function doFoo(
14+
int $int,
15+
string $string,
16+
$intOrString
17+
): void
18+
{
19+
$literalNumericString = '123';
20+
$intOrLiteralNumericString = $int;
21+
if (rand(0, 1) === 0) {
22+
$intOrLiteralNumericString = '123';
23+
}
24+
25+
$int + $int;
26+
$string + $int;
27+
$literalNumericString + $int;
28+
$intOrString + $int;
29+
$intOrLiteralNumericString + $int;
30+
31+
$stringOrObject = $string;
32+
if (rand(0, 1) === 0) {
33+
$stringOrObject = new \stdClass();
34+
}
35+
36+
$stringOrObject + $int;
37+
38+
$unionOfLiterals = '123';
39+
if (rand(0, 1) === 0) {
40+
$unionOfLiterals = '456';
41+
}
42+
43+
$unionOfLiterals + $int;
44+
}
45+
46+
}

0 commit comments

Comments
 (0)