Skip to content

Commit baf0436

Browse files
herndlmondrejmirtes
authored andcommitted
Extract remaining collection tests
1 parent 45b115f commit baf0436

File tree

2 files changed

+69
-33
lines changed

2 files changed

+69
-33
lines changed

tests/Type/WebMozartAssert/data/collection.php

+69-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,67 @@
44

55
use Webmozart\Assert\Assert;
66

7-
class Collection
7+
class CollectionTest
88
{
99

10+
public function allString(array $a): void
11+
{
12+
Assert::allString($a);
13+
\PHPStan\Testing\assertType('array<string>', $a);
14+
}
15+
16+
public function allInteger(array $a, iterable $b, iterable $c): void
17+
{
18+
Assert::allInteger($a);
19+
\PHPStan\Testing\assertType('array<int>', $a);
20+
21+
Assert::allInteger($b);
22+
\PHPStan\Testing\assertType('iterable<int>', $b);
23+
}
24+
25+
public function allInstanceOf(array $a): void
26+
{
27+
Assert::allIsInstanceOf($a, \stdClass::class);
28+
\PHPStan\Testing\assertType('array<stdClass>', $a);
29+
}
30+
31+
/**
32+
* @param (CollectionFoo|CollectionBar)[] $a
33+
*/
34+
public function allNotInstanceOf(array $a): void
35+
{
36+
Assert::allNotInstanceOf($a, CollectionBar::class);
37+
\PHPStan\Testing\assertType('array<PHPStan\Type\WebMozartAssert\CollectionFoo>', $a);
38+
}
39+
40+
/**
41+
* @param (int|null)[] $a
42+
*/
43+
public function allNotNull(array $a): void
44+
{
45+
Assert::allNotNull($a);
46+
\PHPStan\Testing\assertType('array<int>', $a);
47+
}
48+
49+
/**
50+
* @param array{-1|1, -2|2, -3|3} $a
51+
*/
52+
public function allNotSame(array $a): void
53+
{
54+
Assert::allNotSame($a, -1);
55+
\PHPStan\Testing\assertType('array{1, -2|2, -3|3}', $a);
56+
}
57+
58+
public function allSubclassOf(array $a, $b): void
59+
{
60+
Assert::allSubclassOf($a, self::class);
61+
// should array<PHPStan\Type\WebMozartAssert\CollectionTest>
62+
\PHPStan\Testing\assertType('array<*NEVER*>', $a);
63+
64+
Assert::allSubclassOf($b, self::class);
65+
\PHPStan\Testing\assertType('iterable<class-string<PHPStan\Type\WebMozartAssert\CollectionTest>|PHPStan\Type\WebMozartAssert\CollectionTest>', $b);
66+
}
67+
1068
/**
1169
* @param array<array{id?: int}> $a
1270
* @param array<int, array<string, mixed>> $b
@@ -25,3 +83,13 @@ public function allKeyExists(array $a, array $b, array $c): void
2583
}
2684

2785
}
86+
87+
class CollectionFoo
88+
{
89+
90+
}
91+
92+
interface CollectionBar
93+
{
94+
95+
}

tests/Type/WebMozartAssert/data/data.php

-32
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,9 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
1414
Assert::nullOrInteger($b);
1515
\PHPStan\Testing\assertType('int|null', $b);
1616

17-
Assert::allInteger($c);
18-
\PHPStan\Testing\assertType('array<int>', $c);
19-
20-
Assert::allInteger($d);
21-
\PHPStan\Testing\assertType('iterable<int>', $d);
22-
23-
/** @var (Foo|Bar)[] $v */
24-
$v = doFoo();
25-
Assert::allNotInstanceOf($v, Bar::class);
26-
\PHPStan\Testing\assertType('array<PHPStan\Type\WebMozartAssert\Foo>', $v);
27-
28-
/** @var (int|null)[] $w */
29-
$w = doFoo();
30-
Assert::allNotNull($w);
31-
\PHPStan\Testing\assertType('array<int>', $w);
32-
33-
$z = [1, 2, 3];
34-
if (doFoo()) {
35-
$z = [-1, -2, -3];
36-
}
37-
Assert::allNotSame($z, -1);
38-
\PHPStan\Testing\assertType('array{1, -2|2, -3|3}', $z);
39-
4017
Assert::subclassOf($aa, self::class);
4118
\PHPStan\Testing\assertType('class-string<PHPStan\Type\WebMozartAssert\TypeInferenceTest>|PHPStan\Type\WebMozartAssert\TypeInferenceTest', $aa);
4219

43-
Assert::allSubclassOf($ab, self::class);
44-
// should array<PHPStan\Type\WebMozartAssert\Foo>
45-
\PHPStan\Testing\assertType('array<*NEVER*>', $ab);
46-
4720
Assert::implementsInterface($ae, Baz::class);
4821
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\Baz', $ae);
4922

@@ -59,13 +32,8 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
5932
$ah = false;
6033
}
6134

62-
Assert::allIsInstanceOf($ah, \stdClass::class);
63-
\PHPStan\Testing\assertType('array<stdClass>', $ah);
64-
6535
Assert::isList($ai);
6636
\PHPStan\Testing\assertType('array', $ai);
67-
Assert::allString($ai);
68-
\PHPStan\Testing\assertType('array<string>', $ai);
6937

7038
/** @var int[] $aj */
7139
$aj = doFoo();

0 commit comments

Comments
 (0)