Skip to content

Commit 0aa685e

Browse files
herndlmondrejmirtes
authored andcommitted
Move type assertion tests into TypeTest
1 parent 8015d41 commit 0aa685e

File tree

2 files changed

+99
-53
lines changed

2 files changed

+99
-53
lines changed

tests/Type/WebMozartAssert/data/data.php

-50
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
1111
{
1212
\PHPStan\Testing\assertType('mixed', $a);
1313

14-
Assert::integer($a);
15-
\PHPStan\Testing\assertType('int', $a);
16-
1714
Assert::nullOrInteger($b);
1815
\PHPStan\Testing\assertType('int|null', $b);
1916

@@ -23,47 +20,6 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
2320
Assert::allInteger($d);
2421
\PHPStan\Testing\assertType('iterable<int>', $d);
2522

26-
Assert::string($e);
27-
\PHPStan\Testing\assertType('string', $e);
28-
29-
Assert::float($f);
30-
\PHPStan\Testing\assertType('float', $f);
31-
32-
Assert::numeric($g);
33-
\PHPStan\Testing\assertType('float|int|numeric-string', $g);
34-
35-
Assert::boolean($h);
36-
\PHPStan\Testing\assertType('bool', $h);
37-
38-
Assert::scalar($i);
39-
\PHPStan\Testing\assertType('bool|float|int|string', $i);
40-
41-
Assert::object($j);
42-
\PHPStan\Testing\assertType('object', $j);
43-
44-
Assert::resource($k);
45-
\PHPStan\Testing\assertType('resource', $k);
46-
47-
Assert::isCallable($l);
48-
\PHPStan\Testing\assertType('callable(): mixed', $l);
49-
50-
Assert::isArray($m);
51-
\PHPStan\Testing\assertType('array', $m);
52-
53-
Assert::isIterable($n);
54-
\PHPStan\Testing\assertType('array|Traversable', $n);
55-
56-
Assert::isCountable($o);
57-
\PHPStan\Testing\assertType('array|Countable', $o);
58-
59-
Assert::isInstanceOf($p, self::class);
60-
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\TypeInferenceTest', $p);
61-
62-
/** @var Foo|Bar $q */
63-
$q = doFoo();
64-
Assert::notInstanceOf($q, Bar::class);
65-
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\Foo', $q);
66-
6723
Assert::true($r);
6824
\PHPStan\Testing\assertType('true', $r);
6925

@@ -113,12 +69,6 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
11369
// should array<PHPStan\Type\WebMozartAssert\Foo>
11470
\PHPStan\Testing\assertType('array<*NEVER*>', $ab);
11571

116-
Assert::stringNotEmpty($ac);
117-
\PHPStan\Testing\assertType('non-empty-string', $ac);
118-
119-
Assert::integerish($ad);
120-
\PHPStan\Testing\assertType('float|int|numeric-string', $ad);
121-
12272
Assert::implementsInterface($ae, Baz::class);
12373
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\Baz', $ae);
12474

tests/Type/WebMozartAssert/data/type.php

+99-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,30 @@
66

77
class TypeTest
88
{
9-
/**
10-
* @param mixed $a
11-
*/
9+
public function string($a): void
10+
{
11+
Assert::string($a);
12+
\PHPStan\Testing\assertType('string', $a);
13+
}
14+
15+
public function stringNotEmpty($a): void
16+
{
17+
Assert::stringNotEmpty($a);
18+
\PHPStan\Testing\assertType('non-empty-string', $a);
19+
}
20+
21+
public function integer($a): void
22+
{
23+
Assert::integer($a);
24+
\PHPStan\Testing\assertType('int', $a);
25+
}
26+
27+
public function integerish($a): void
28+
{
29+
Assert::integerish($a);
30+
\PHPStan\Testing\assertType('float|int|numeric-string', $a);
31+
}
32+
1233
public function positiveInteger($a): void
1334
{
1435
Assert::positiveInteger($a);
@@ -19,6 +40,18 @@ public function positiveInteger($a): void
1940
\PHPStan\Testing\assertType('*NEVER*', $b);
2041
}
2142

43+
public function float($a): void
44+
{
45+
Assert::float($a);
46+
\PHPStan\Testing\assertType('float', $a);
47+
}
48+
49+
public function numeric($a): void
50+
{
51+
Assert::numeric($a);
52+
\PHPStan\Testing\assertType('float|int|numeric-string', $a);
53+
}
54+
2255
public function natural($a): void
2356
{
2457
Assert::natural($a);
@@ -28,4 +61,67 @@ public function natural($a): void
2861
Assert::natural($b);
2962
\PHPStan\Testing\assertType('*NEVER*', $b);
3063
}
64+
65+
public function boolean($a): void
66+
{
67+
Assert::boolean($a);
68+
\PHPStan\Testing\assertType('bool', $a);
69+
}
70+
71+
public function scalar($a): void
72+
{
73+
Assert::scalar($a);
74+
\PHPStan\Testing\assertType('bool|float|int|string', $a);
75+
}
76+
77+
public function object($a): void
78+
{
79+
Assert::object($a);
80+
\PHPStan\Testing\assertType('object', $a);
81+
}
82+
83+
public function resource($a): void
84+
{
85+
Assert::resource($a);
86+
\PHPStan\Testing\assertType('resource', $a);
87+
}
88+
89+
public function isCallable($a): void
90+
{
91+
Assert::isCallable($a);
92+
\PHPStan\Testing\assertType('callable(): mixed', $a);
93+
}
94+
95+
public function isArray($a): void
96+
{
97+
Assert::isArray($a);
98+
\PHPStan\Testing\assertType('array', $a);
99+
}
100+
101+
public function isIterable($a): void
102+
{
103+
Assert::isIterable($a);
104+
\PHPStan\Testing\assertType('array|Traversable', $a);
105+
}
106+
107+
public function isCountable($a): void
108+
{
109+
Assert::isCountable($a);
110+
\PHPStan\Testing\assertType('array|Countable', $a);
111+
}
112+
113+
public function isInstanceOf($a): void
114+
{
115+
Assert::isInstanceOf($a, self::class);
116+
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\TypeTest', $a);
117+
}
118+
119+
/**
120+
* @param Foo|Bar $a
121+
*/
122+
public function notInstanceOf($a): void
123+
{
124+
Assert::notInstanceOf($a, Bar::class);
125+
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\Foo', $a);
126+
}
31127
}

0 commit comments

Comments
 (0)