-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to
Assert::isInstanceOf()
to work with generic and anonymous …
…class strings
- Loading branch information
1 parent
983a1a7
commit 923bd58
Showing
6 changed files
with
94 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
use Webmozart\Assert\Assert; | ||
use function PHPStan\Testing\assertType; | ||
|
||
function assertInstanceOfWithString($value, string $className): void | ||
{ | ||
Assert::isInstanceOf($value, $className); | ||
assertType('object', $value); | ||
} | ||
|
||
/** | ||
* @param class-string $className | ||
*/ | ||
function assertInstanceOfWithClassString($value, string $className): void | ||
{ | ||
Assert::isInstanceOf($value, $className); | ||
assertType('object', $value); | ||
} | ||
|
||
/** | ||
* @param class-string<\Bug183> $className | ||
*/ | ||
function assertInstanceOfWithGenericClassString($value, string $className): void | ||
{ | ||
Assert::isInstanceOf($value, $className); | ||
assertType('Bug183', $value); | ||
} | ||
|
||
/** | ||
* @param class-string<\Bug183Bar<\Bug183>> $className | ||
*/ | ||
function assertInstanceOfWithGenericClassStringReferencingGenericClass($value, string $className): void | ||
{ | ||
Assert::isInstanceOf($value, $className); | ||
assertType('Bug183Bar', $value); | ||
} | ||
|
||
/** | ||
* @param class-string<\Bug183|\Bug183Foo> $className | ||
*/ | ||
function assertInstanceOfWithGenericUnionClassString($value, string $className): void | ||
{ | ||
Assert::isInstanceOf($value, $className); | ||
assertType('Bug183|Bug183Foo', $value); | ||
} | ||
|
||
|
||
interface Bug183 | ||
{ | ||
} | ||
|
||
interface Bug183Foo | ||
{ | ||
} | ||
|
||
/** | ||
* @template T of object | ||
*/ | ||
interface Bug183Bar | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters