Skip to content

Commit 9bdc258

Browse files
herndlmondrejmirtes
authored andcommitted
Extract comparison tests
1 parent 0aa685e commit 9bdc258

File tree

3 files changed

+67
-35
lines changed

3 files changed

+67
-35
lines changed

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function dataFileAsserts(): iterable
1414
{
1515
yield from $this->gatherAssertTypes(__DIR__ . '/data/array.php');
1616
yield from $this->gatherAssertTypes(__DIR__ . '/data/collection.php');
17+
yield from $this->gatherAssertTypes(__DIR__ . '/data/comparison.php');
1718
yield from $this->gatherAssertTypes(__DIR__ . '/data/data.php');
1819
yield from $this->gatherAssertTypes(__DIR__ . '/data/string.php');
1920
yield from $this->gatherAssertTypes(__DIR__ . '/data/type.php');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PHPStan\Type\WebMozartAssert;
4+
5+
use Webmozart\Assert\Assert;
6+
7+
class ComparisonTest
8+
{
9+
public function true($a): void
10+
{
11+
Assert::true($a);
12+
\PHPStan\Testing\assertType('true', $a);
13+
}
14+
15+
public function false($a): void
16+
{
17+
Assert::false($a);
18+
\PHPStan\Testing\assertType('false', $a);
19+
}
20+
21+
public function notFalse(int $a): void
22+
{
23+
/** @var int|false $a */
24+
Assert::notFalse($a);
25+
\PHPStan\Testing\assertType('int', $a);
26+
}
27+
28+
public function null($a): void
29+
{
30+
Assert::null($a);
31+
\PHPStan\Testing\assertType('null', $a);
32+
}
33+
34+
public function notNull(?int $a): void
35+
{
36+
Assert::notNull($a);
37+
\PHPStan\Testing\assertType('int', $a);
38+
}
39+
40+
public function same($a): void
41+
{
42+
Assert::same($a, 1);
43+
\PHPStan\Testing\assertType('1', $a);
44+
}
45+
46+
/**
47+
* @param -1|1 $a
48+
*/
49+
public function notSame($a): void
50+
{
51+
Assert::notSame($a, 1);
52+
\PHPStan\Testing\assertType('-1', $a);
53+
}
54+
55+
public function inArray($a): void
56+
{
57+
Assert::inArray($a, ['foo', 'bar']);
58+
\PHPStan\Testing\assertType('\'bar\'|\'foo\'', $a);
59+
}
60+
61+
public function oneOf($a): void
62+
{
63+
Assert::oneOf($a, [1, 2]);
64+
\PHPStan\Testing\assertType('1|2', $a);
65+
}
66+
}

tests/Type/WebMozartAssert/data/data.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
2020
Assert::allInteger($d);
2121
\PHPStan\Testing\assertType('iterable<int>', $d);
2222

23-
Assert::true($r);
24-
\PHPStan\Testing\assertType('true', $r);
25-
26-
Assert::false($s);
27-
\PHPStan\Testing\assertType('false', $s);
28-
29-
Assert::null($t);
30-
\PHPStan\Testing\assertType('null', $t);
31-
32-
Assert::notNull($u);
33-
\PHPStan\Testing\assertType('int', $u);
34-
3523
/** @var (Foo|Bar)[] $v */
3624
$v = doFoo();
3725
Assert::allNotInstanceOf($v, Bar::class);
@@ -42,19 +30,6 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
4230
Assert::allNotNull($w);
4331
\PHPStan\Testing\assertType('array<int>', $w);
4432

45-
Assert::same($x, 1);
46-
\PHPStan\Testing\assertType('1', $x);
47-
48-
if (doFoo()) {
49-
$y = 1;
50-
} else {
51-
$y = -1;
52-
}
53-
54-
\PHPStan\Testing\assertType('-1|1', $y);
55-
Assert::notSame($y, 1);
56-
\PHPStan\Testing\assertType('-1', $y);
57-
5833
$z = [1, 2, 3];
5934
if (doFoo()) {
6035
$z = [-1, -2, -3];
@@ -72,10 +47,6 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
7247
Assert::implementsInterface($ae, Baz::class);
7348
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\Baz', $ae);
7449

75-
/** @var int|false $af */
76-
Assert::notFalse($af);
77-
\PHPStan\Testing\assertType('int', $af);
78-
7950
/** @var array{foo?: string, bar?: string} $things */
8051
$things = doFoo();
8152
Assert::keyExists($things, 'foo');
@@ -102,15 +73,9 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
10273
$ak = array_pop($aj);
10374
\PHPStan\Testing\assertType('int', $ak);
10475

105-
Assert::inArray($al, ['foo', 'bar']);
106-
\PHPStan\Testing\assertType('\'bar\'|\'foo\'', $al);
107-
10876
Assert::nullOrInArray($am, ['foo', 'bar']);
10977
\PHPStan\Testing\assertType('\'bar\'|\'foo\'|null', $am);
11078

111-
Assert::oneOf($an, [1, 2]);
112-
\PHPStan\Testing\assertType('1|2', $an);
113-
11479
/** @var object $ao */
11580
Assert::methodExists($ao, 'foo');
11681
\PHPStan\Testing\assertType('object&hasMethod(foo)', $ao);

0 commit comments

Comments
 (0)