Skip to content

Commit 7db7d85

Browse files
herndlmondrejmirtes
authored andcommitted
Extract remaining tests
1 parent baf0436 commit 7db7d85

File tree

6 files changed

+101
-84
lines changed

6 files changed

+101
-84
lines changed

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function dataFileAsserts(): iterable
1515
yield from $this->gatherAssertTypes(__DIR__ . '/data/array.php');
1616
yield from $this->gatherAssertTypes(__DIR__ . '/data/collection.php');
1717
yield from $this->gatherAssertTypes(__DIR__ . '/data/comparison.php');
18-
yield from $this->gatherAssertTypes(__DIR__ . '/data/data.php');
18+
yield from $this->gatherAssertTypes(__DIR__ . '/data/object.php');
1919
yield from $this->gatherAssertTypes(__DIR__ . '/data/string.php');
2020
yield from $this->gatherAssertTypes(__DIR__ . '/data/type.php');
2121
}

tests/Type/WebMozartAssert/data/array.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ public function keyNotExists(array $a): void
1717
}
1818

1919
/**
20-
* @param mixed $a
20+
* @param array{foo?: string, bar?: string} $a
2121
*/
22+
public function keyExists(array $a): void
23+
{
24+
Assert::keyExists($a, 'foo');
25+
\PHPStan\Testing\assertType('array{foo: string, bar?: string}', $a);
26+
}
27+
2228
public function validArrayKey($a, bool $b): void
2329
{
2430
Assert::validArrayKey($a);
@@ -28,4 +34,32 @@ public function validArrayKey($a, bool $b): void
2834
\PHPStan\Testing\assertType('*NEVER*', $b);
2935
}
3036

37+
/**
38+
* @param int[] $a
39+
*/
40+
public function count(array $a): void
41+
{
42+
Assert::count($a, 1);
43+
$a1 = array_pop($a);
44+
$a2 = array_pop($a);
45+
\PHPStan\Testing\assertType('int', $a1);
46+
\PHPStan\Testing\assertType('int|null', $a2);
47+
}
48+
49+
/**
50+
* @param int[] $a
51+
*/
52+
public function minCount(array $a): void
53+
{
54+
Assert::minCount($a, 1);
55+
$a1 = array_pop($a);
56+
\PHPStan\Testing\assertType('int', $a1);
57+
}
58+
59+
public function isList($a): void
60+
{
61+
Assert::isList($a);
62+
\PHPStan\Testing\assertType('array', $a);
63+
}
64+
3165
}

tests/Type/WebMozartAssert/data/comparison.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ public function notSame($a): void
5252
\PHPStan\Testing\assertType('-1', $a);
5353
}
5454

55-
public function inArray($a): void
55+
public function inArray($a, $b): void
5656
{
5757
Assert::inArray($a, ['foo', 'bar']);
5858
\PHPStan\Testing\assertType('\'bar\'|\'foo\'', $a);
59+
60+
Assert::nullOrInArray($b, ['foo', 'bar']);
61+
\PHPStan\Testing\assertType('\'bar\'|\'foo\'|null', $b);
5962
}
6063

6164
public function oneOf($a): void

tests/Type/WebMozartAssert/data/data.php

-80
This file was deleted.
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PHPStan\Type\WebMozartAssert;
4+
5+
use Webmozart\Assert\Assert;
6+
7+
class ObjectTest
8+
{
9+
10+
public function classExists($a): void
11+
{
12+
Assert::classExists($a);
13+
\PHPStan\Testing\assertType('class-string', $a);
14+
}
15+
16+
public function subclassOf($a): void
17+
{
18+
Assert::subclassOf($a, self::class);
19+
\PHPStan\Testing\assertType('class-string<PHPStan\Type\WebMozartAssert\ObjectTest>|PHPStan\Type\WebMozartAssert\ObjectTest', $a);
20+
}
21+
22+
public function interfaceExists($a): void
23+
{
24+
Assert::interfaceExists($a);
25+
\PHPStan\Testing\assertType('class-string', $a);
26+
}
27+
28+
public function implementsInterface($a): void
29+
{
30+
Assert::implementsInterface($a, ObjectFoo::class);
31+
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\ObjectFoo', $a);
32+
}
33+
34+
public function propertyExists(object $a): void
35+
{
36+
Assert::propertyExists($a, 'foo');
37+
\PHPStan\Testing\assertType('object&hasProperty(foo)', $a);
38+
}
39+
40+
public function methodExists(object $a): void
41+
{
42+
Assert::methodExists($a, 'foo');
43+
\PHPStan\Testing\assertType('object&hasMethod(foo)', $a);
44+
}
45+
46+
}
47+
48+
interface ObjectFoo
49+
{
50+
51+
}

tests/Type/WebMozartAssert/data/type.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ public function stringNotEmpty($a): void
1818
\PHPStan\Testing\assertType('non-empty-string', $a);
1919
}
2020

21-
public function integer($a): void
21+
public function integer($a, $b): void
2222
{
2323
Assert::integer($a);
2424
\PHPStan\Testing\assertType('int', $a);
25+
26+
Assert::nullOrInteger($b);
27+
\PHPStan\Testing\assertType('int|null', $b);
2528
}
2629

2730
public function integerish($a): void
@@ -124,4 +127,10 @@ public function notInstanceOf($a): void
124127
Assert::notInstanceOf($a, Bar::class);
125128
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\Foo', $a);
126129
}
130+
131+
public function isArrayAccessible($a): void
132+
{
133+
Assert::isArrayAccessible($a);
134+
\PHPStan\Testing\assertType('array|ArrayAccess', $a);
135+
}
127136
}

0 commit comments

Comments
 (0)