Skip to content

Commit 5e399ea

Browse files
committed
Test BcMath\Number unary operations
1 parent 72f877f commit 5e399ea

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

tests/PHPStan/Rules/Operators/InvalidIncDecOperationRuleTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,27 @@ public function testIncNonNumericString(): void
234234
$this->analyse([__DIR__ . '/data/inc-non-numeric-string.php'], $errors);
235235
}
236236

237+
#[RequiresPhp('>= 8.5')]
238+
public function testBcMathNumber(): void
239+
{
240+
$this->analyse([__DIR__ . '/data/inc-dec-bcmath-number.php'], [
241+
[
242+
'Cannot use ++ on BcMath\Number.',
243+
9,
244+
],
245+
[
246+
'Cannot use ++ on BcMath\Number.',
247+
10,
248+
],
249+
[
250+
'Cannot use -- on BcMath\Number.',
251+
11,
252+
],
253+
[
254+
'Cannot use -- on BcMath\Number.',
255+
12,
256+
],
257+
]);
258+
}
259+
237260
}

tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,23 @@ public function testUnion(): void
169169
]);
170170
}
171171

172+
#[RequiresPhp('>= 8.5')]
173+
public function testBcMathNumber(): void
174+
{
175+
$this->analyse([__DIR__ . '/data/unary-bcmath-number.php'], [
176+
[
177+
'Unary operation "+" on BcMath\Number results in an error.',
178+
9,
179+
],
180+
[
181+
'Unary operation "-" on BcMath\Number results in an error.',
182+
10,
183+
],
184+
[
185+
'Unary operation "~" on BcMath\Number results in an error.',
186+
11,
187+
],
188+
]);
189+
}
190+
172191
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace IncDecBcMathNumber;
4+
5+
use BcMath\Number;
6+
7+
function test(Number $x): void
8+
{
9+
++$x;
10+
$x++;
11+
$x--;
12+
--$x;
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace BcMathNumberUnaryOperators;
4+
5+
use BcMath\Number;
6+
7+
function test(Number $x): void
8+
{
9+
+$x;
10+
-$x;
11+
~$x;
12+
}

0 commit comments

Comments
 (0)