Skip to content

Commit 86b102c

Browse files
tomaszhancondrejmirtes
authored andcommitted
Adds support for Assert::classExists
1 parent d1644c7 commit 86b102c

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This extension specifies types of values passed to:
5353
* `Assert::same`
5454
* `Assert::notSame`
5555
* `Assert::implementsInterface`
56+
* `Assert::classExists`
5657
* `nullOr*` and `all*` variants of the above methods
5758

5859

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ private static function getExpressionResolvers(): array
377377
]
378378
);
379379
},
380+
'classExists' => function (Scope $scope, Arg $class): \PhpParser\Node\Expr {
381+
return new \PhpParser\Node\Expr\FuncCall(
382+
new \PhpParser\Node\Name('class_exists'),
383+
[$class]
384+
);
385+
},
380386
];
381387
}
382388

tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public function testExtension(): void
168168
'Variable $things is: array(\'foo\' => string, ?\'bar\' => string)',
169169
131,
170170
],
171+
[
172+
'Variable $ag is: class-string',
173+
134,
174+
],
171175
]);
172176
}
173177

tests/Type/WebMozartAssert/data/data.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Foo
88
{
99

10-
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac, $ad, $ae, $af)
10+
public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac, $ad, $ae, $af, $ag)
1111
{
1212
$a;
1313

@@ -129,6 +129,9 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
129129
$things = doFoo();
130130
Assert::keyExists($things, 'foo');
131131
$things;
132+
133+
Assert::classExists($ag);
134+
$ag;
132135
}
133136

134137
}

0 commit comments

Comments
 (0)