Skip to content

Commit 895cbf2

Browse files
herndlmondrejmirtes
authored andcommitted
Add more tests
1 parent 67f970c commit 895cbf2

File tree

6 files changed

+133
-34
lines changed

6 files changed

+133
-34
lines changed

tests/Type/WebMozartAssert/data/array.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ public function keyExists(array $a): void
2525
\PHPStan\Testing\assertType('array{foo: string, bar?: string}', $a);
2626
}
2727

28-
public function validArrayKey($a, bool $b): void
28+
public function validArrayKey($a, bool $b, $c): void
2929
{
3030
Assert::validArrayKey($a);
3131
\PHPStan\Testing\assertType('int|string', $a);
3232

3333
Assert::validArrayKey($b);
3434
\PHPStan\Testing\assertType('*NEVER*', $b);
35+
36+
Assert::nullOrValidArrayKey($c);
37+
\PHPStan\Testing\assertType('int|string|null', $c);
3538
}
3639

3740
/**
@@ -94,10 +97,13 @@ public function countBetween(array $a, array $b, array $c, array $d): void
9497
\PHPStan\Testing\assertType('*NEVER*', $d);
9598
}
9699

97-
public function isList($a): void
100+
public function isList($a, $b): void
98101
{
99102
Assert::isList($a);
100103
\PHPStan\Testing\assertType('array', $a);
104+
105+
Assert::nullOrIsList($b);
106+
\PHPStan\Testing\assertType('array|null', $b);
101107
}
102108

103109
}

tests/Type/WebMozartAssert/data/collection.php

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public function allString(array $a): void
1313
\PHPStan\Testing\assertType('array<string>', $a);
1414
}
1515

16+
public function allStringNotEmpty(array $a): void
17+
{
18+
Assert::allStringNotEmpty($a);
19+
\PHPStan\Testing\assertType('array<string>', $a); // should be array<non-empty-string>
20+
}
21+
1622
public function allInteger(array $a, iterable $b, iterable $c): void
1723
{
1824
Assert::allInteger($a);

tests/Type/WebMozartAssert/data/comparison.php

+17-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66

77
class ComparisonTest
88
{
9-
public function true($a): void
9+
public function true($a, $b): void
1010
{
1111
Assert::true($a);
1212
\PHPStan\Testing\assertType('true', $a);
13+
14+
Assert::nullOrTrue($b);
15+
\PHPStan\Testing\assertType('true|null', $b);
1316
}
1417

15-
public function false($a): void
18+
public function false($a, $b): void
1619
{
1720
Assert::false($a);
1821
\PHPStan\Testing\assertType('false', $a);
22+
23+
Assert::nullOrFalse($b);
24+
\PHPStan\Testing\assertType('false|null', $b);
1925
}
2026

21-
public function notFalse(int $a): void
27+
public function notFalse($a, $b): void
2228
{
2329
/** @var int|false $a */
2430
Assert::notFalse($a);
@@ -37,10 +43,13 @@ public function notNull(?int $a): void
3743
\PHPStan\Testing\assertType('int', $a);
3844
}
3945

40-
public function same($a): void
46+
public function same($a, $b): void
4147
{
4248
Assert::same($a, 1);
4349
\PHPStan\Testing\assertType('1', $a);
50+
51+
Assert::nullOrSame($b, 1);
52+
\PHPStan\Testing\assertType('1|null', $b);
4453
}
4554

4655
/**
@@ -61,9 +70,12 @@ public function inArray($a, $b): void
6170
\PHPStan\Testing\assertType('\'bar\'|\'foo\'|null', $b);
6271
}
6372

64-
public function oneOf($a): void
73+
public function oneOf($a, $b): void
6574
{
6675
Assert::oneOf($a, [1, 2]);
6776
\PHPStan\Testing\assertType('1|2', $a);
77+
78+
Assert::nullOrOneOf($b, [1, 2]);
79+
\PHPStan\Testing\assertType('1|2|null', $b);
6880
}
6981
}

tests/Type/WebMozartAssert/data/object.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,40 @@
77
class ObjectTest
88
{
99

10-
public function classExists($a): void
10+
public function classExists($a, $b): void
1111
{
1212
Assert::classExists($a);
1313
\PHPStan\Testing\assertType('class-string', $a);
14+
15+
Assert::nullOrClassExists($b);
16+
\PHPStan\Testing\assertType('class-string|null', $b);
1417
}
1518

16-
public function subclassOf($a): void
19+
public function subclassOf($a, $b): void
1720
{
1821
Assert::subclassOf($a, self::class);
1922
\PHPStan\Testing\assertType('class-string<PHPStan\Type\WebMozartAssert\ObjectTest>|PHPStan\Type\WebMozartAssert\ObjectTest', $a);
23+
24+
Assert::nullOrSubclassOf($b, self::class);
25+
\PHPStan\Testing\assertType('class-string<PHPStan\Type\WebMozartAssert\ObjectTest>|PHPStan\Type\WebMozartAssert\ObjectTest|null', $b);
2026
}
2127

22-
public function interfaceExists($a): void
28+
public function interfaceExists($a, $b): void
2329
{
2430
Assert::interfaceExists($a);
2531
\PHPStan\Testing\assertType('class-string', $a);
32+
33+
Assert::nullOrInterfaceExists($b);
34+
\PHPStan\Testing\assertType('class-string|null', $b);
2635
}
2736

28-
public function implementsInterface($a): void
37+
public function implementsInterface($a, $b): void
2938
{
3039
Assert::implementsInterface($a, ObjectFoo::class);
3140
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\ObjectFoo', $a);
41+
42+
Assert::nullOrImplementsInterface($b, ObjectFoo::class);
43+
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\ObjectFoo|null', $b);
3244
}
3345

3446
public function propertyExists(object $a): void

tests/Type/WebMozartAssert/data/string.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,43 @@
77
class TestStrings
88
{
99

10-
public function length(string $a, string $b): void
10+
public function length(string $a, string $b, string $c): void
1111
{
1212
Assert::length($a, 0);
1313
\PHPStan\Testing\assertType('\'\'', $a);
1414

1515
Assert::length($b, 1);
1616
\PHPStan\Testing\assertType('non-empty-string', $b);
17+
18+
Assert::nullOrLength($c, 1);
19+
\PHPStan\Testing\assertType('non-empty-string', $c); // should be non-empty-string|null
1720
}
1821

19-
public function minLength(string $a, string $b): void
22+
public function minLength(string $a, string $b, string $c): void
2023
{
2124
Assert::minLength($a, 0);
2225
\PHPStan\Testing\assertType('string', $a);
2326

2427
Assert::minLength($b, 1);
2528
\PHPStan\Testing\assertType('non-empty-string', $b);
29+
30+
Assert::nullOrMinLength($c, 1);
31+
\PHPStan\Testing\assertType('non-empty-string', $c); // should be non-empty-string|null
2632
}
2733

28-
public function maxLength(string $a, string $b): void
34+
public function maxLength(string $a, string $b, string $c): void
2935
{
3036
Assert::maxLength($a, 0);
3137
\PHPStan\Testing\assertType('\'\'', $a);
3238

3339
Assert::maxLength($b, 1);
3440
\PHPStan\Testing\assertType('string', $b);
41+
42+
Assert::nullOrMaxLength($c, 1);
43+
\PHPStan\Testing\assertType('string', $c); // should be string|null
3544
}
3645

37-
public function lengthBetween(string $a, string $b, string $c, string $d): void
46+
public function lengthBetween(string $a, string $b, string $c, string $d, string $e): void
3847
{
3948
Assert::lengthBetween($a, 0, 0);
4049
\PHPStan\Testing\assertType('\'\'', $a);
@@ -47,6 +56,9 @@ public function lengthBetween(string $a, string $b, string $c, string $d): void
4756

4857
Assert::lengthBetween($d, 1, 1);
4958
\PHPStan\Testing\assertType('non-empty-string', $d);
59+
60+
Assert::nullOrLengthBetween($e, 1, 1);
61+
\PHPStan\Testing\assertType('non-empty-string', $e); // should be non-empty-string|null
5062
}
5163

5264
}

0 commit comments

Comments
 (0)