Skip to content

Add PHPStan assert PHPDoc annotations from PHPUnit #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion src/Codeception/Util/Shared/InheritedAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ protected function assertDoesNotMatchRegularExpression(string $pattern, string $
* Asserts that a variable is empty.
*
* @param mixed $actual
*
* @phpstan-assert empty $actual
*/
protected function assertEmpty($actual, string $message = '')
{
Expand Down Expand Up @@ -236,6 +238,8 @@ protected function assertEqualsWithDelta($expected, $actual, float $delta, strin
* Asserts that a condition is false.
*
* @param mixed $condition
*
* @phpstan-assert false $condition
*/
protected function assertFalse($condition, string $message = '')
{
Expand Down Expand Up @@ -383,7 +387,12 @@ protected function assertInfinite($actual, string $message = '')
/**
* Asserts that a variable is of a given type.
*
* @template ExpectedType of object
*
* @param mixed $actual
* @param class-string<ExpectedType> $expected
*
* @phpstan-assert =ExpectedType $actual
*/
protected function assertInstanceOf(string $expected, $actual, string $message = '')
{
Expand All @@ -394,6 +403,8 @@ protected function assertInstanceOf(string $expected, $actual, string $message =
* Asserts that a variable is of type array.
*
* @param mixed $actual
*
* @phpstan-assert array $actual
*/
protected function assertIsArray($actual, string $message = '')
{
Expand All @@ -404,6 +415,8 @@ protected function assertIsArray($actual, string $message = '')
* Asserts that a variable is of type bool.
*
* @param mixed $actual
*
* @phpstan-assert bool $actual
*/
protected function assertIsBool($actual, string $message = '')
{
Expand All @@ -414,6 +427,8 @@ protected function assertIsBool($actual, string $message = '')
* Asserts that a variable is of type callable.
*
* @param mixed $actual
*
* @phpstan-assert callable $actual
*/
protected function assertIsCallable($actual, string $message = '')
{
Expand All @@ -424,6 +439,8 @@ protected function assertIsCallable($actual, string $message = '')
* Asserts that a variable is of type resource and is closed.
*
* @param mixed $actual
*
* @phpstan-assert resource $actual
*/
protected function assertIsClosedResource($actual, string $message = '')
{
Expand All @@ -434,6 +451,8 @@ protected function assertIsClosedResource($actual, string $message = '')
* Asserts that a variable is of type float.
*
* @param mixed $actual
*
* @phpstan-assert float $actual
*/
protected function assertIsFloat($actual, string $message = '')
{
Expand All @@ -444,6 +463,8 @@ protected function assertIsFloat($actual, string $message = '')
* Asserts that a variable is of type int.
*
* @param mixed $actual
*
* @phpstan-assert int $actual
*/
protected function assertIsInt($actual, string $message = '')
{
Expand All @@ -454,6 +475,8 @@ protected function assertIsInt($actual, string $message = '')
* Asserts that a variable is of type iterable.
*
* @param mixed $actual
*
* @phpstan-assert iterable $actual
*/
protected function assertIsIterable($actual, string $message = '')
{
Expand All @@ -464,6 +487,8 @@ protected function assertIsIterable($actual, string $message = '')
* Asserts that a variable is not of type array.
*
* @param mixed $actual
*
* @phpstan-assert !array $actual
*/
protected function assertIsNotArray($actual, string $message = '')
{
Expand All @@ -474,6 +499,8 @@ protected function assertIsNotArray($actual, string $message = '')
* Asserts that a variable is not of type bool.
*
* @param mixed $actual
*
* @phpstan-assert !bool $actual
*/
protected function assertIsNotBool($actual, string $message = '')
{
Expand All @@ -484,6 +511,8 @@ protected function assertIsNotBool($actual, string $message = '')
* Asserts that a variable is not of type callable.
*
* @param mixed $actual
*
* @phpstan-assert !callable $actual
*/
protected function assertIsNotCallable($actual, string $message = '')
{
Expand All @@ -494,6 +523,8 @@ protected function assertIsNotCallable($actual, string $message = '')
* Asserts that a variable is not of type resource.
*
* @param mixed $actual
*
* @phpstan-assert !resource $actual
*/
protected function assertIsNotClosedResource($actual, string $message = '')
{
Expand All @@ -504,6 +535,8 @@ protected function assertIsNotClosedResource($actual, string $message = '')
* Asserts that a variable is not of type float.
*
* @param mixed $actual
*
* @phpstan-assert !float $actual
*/
protected function assertIsNotFloat($actual, string $message = '')
{
Expand All @@ -514,6 +547,8 @@ protected function assertIsNotFloat($actual, string $message = '')
* Asserts that a variable is not of type int.
*
* @param mixed $actual
*
* @phpstan-assert !int $actual
*/
protected function assertIsNotInt($actual, string $message = '')
{
Expand All @@ -524,6 +559,8 @@ protected function assertIsNotInt($actual, string $message = '')
* Asserts that a variable is not of type iterable.
*
* @param mixed $actual
*
* @phpstan-assert !iterable $actual
*/
protected function assertIsNotIterable($actual, string $message = '')
{
Expand All @@ -534,6 +571,8 @@ protected function assertIsNotIterable($actual, string $message = '')
* Asserts that a variable is not of type numeric.
*
* @param mixed $actual
*
* @phpstan-assert !numeric $actual
*/
protected function assertIsNotNumeric($actual, string $message = '')
{
Expand All @@ -544,6 +583,8 @@ protected function assertIsNotNumeric($actual, string $message = '')
* Asserts that a variable is not of type object.
*
* @param mixed $actual
*
* @phpstan-assert !object $actual
*/
protected function assertIsNotObject($actual, string $message = '')
{
Expand All @@ -562,6 +603,8 @@ protected function assertIsNotReadable(string $filename, string $message = '')
* Asserts that a variable is not of type resource.
*
* @param mixed $actual
*
* @phpstan-assert !resource $actual
*/
protected function assertIsNotResource($actual, string $message = '')
{
Expand All @@ -572,6 +615,8 @@ protected function assertIsNotResource($actual, string $message = '')
* Asserts that a variable is not of type scalar.
*
* @param mixed $actual
*
* @psalm-assert !scalar $actual
*/
protected function assertIsNotScalar($actual, string $message = '')
{
Expand All @@ -582,6 +627,8 @@ protected function assertIsNotScalar($actual, string $message = '')
* Asserts that a variable is not of type string.
*
* @param mixed $actual
*
* @phpstan-assert !string $actual
*/
protected function assertIsNotString($actual, string $message = '')
{
Expand All @@ -600,6 +647,8 @@ protected function assertIsNotWritable(string $filename, string $message = '')
* Asserts that a variable is of type numeric.
*
* @param mixed $actual
*
* @phpstan-assert numeric $actual
*/
protected function assertIsNumeric($actual, string $message = '')
{
Expand All @@ -610,6 +659,8 @@ protected function assertIsNumeric($actual, string $message = '')
* Asserts that a variable is of type object.
*
* @param mixed $actual
*
* @phpstan-assert object $actual
*/
protected function assertIsObject($actual, string $message = '')
{
Expand All @@ -628,6 +679,8 @@ protected function assertIsReadable(string $filename, string $message = '')
* Asserts that a variable is of type resource.
*
* @param mixed $actual
*
* @phpstan-assert resource $actual
*/
protected function assertIsResource($actual, string $message = '')
{
Expand All @@ -638,6 +691,8 @@ protected function assertIsResource($actual, string $message = '')
* Asserts that a variable is of type scalar.
*
* @param mixed $actual
*
* @phpstan-assert scalar $actual
*/
protected function assertIsScalar($actual, string $message = '')
{
Expand All @@ -648,6 +703,8 @@ protected function assertIsScalar($actual, string $message = '')
* Asserts that a variable is of type string.
*
* @param mixed $actual
*
* @phpstan-assert string $actual
*/
protected function assertIsString($actual, string $message = '')
{
Expand Down Expand Up @@ -795,6 +852,8 @@ protected function assertNotCount(int $expectedCount, $haystack, string $message
* Asserts that a variable is not empty.
*
* @param mixed $actual
*
* @phpstan-assert !empty $actual
*/
protected function assertNotEmpty($actual, string $message = '')
{
Expand Down Expand Up @@ -849,6 +908,8 @@ protected function assertNotEqualsWithDelta($expected, $actual, float $delta, st
* Asserts that a condition is not false.
*
* @param mixed $condition
*
* @phpstan-assert !false $condition
*/
protected function assertNotFalse($condition, string $message = '')
{
Expand All @@ -858,7 +919,12 @@ protected function assertNotFalse($condition, string $message = '')
/**
* Asserts that a variable is not of a given type.
*
* @template ExpectedType of object
*
* @param mixed $actual
* @param class-string<ExpectedType> $expected
*
* @phpstan-assert !ExpectedType $actual
*/
protected function assertNotInstanceOf(string $expected, $actual, string $message = '')
{
Expand All @@ -869,6 +935,8 @@ protected function assertNotInstanceOf(string $expected, $actual, string $messag
* Asserts that a variable is not null.
*
* @param mixed $actual
*
* @phpstan-assert !null $actual
*/
protected function assertNotNull($actual, string $message = '')
{
Expand Down Expand Up @@ -901,6 +969,8 @@ protected function assertNotSameSize($expected, $actual, string $message = '')
* Asserts that a condition is not true.
*
* @param mixed $condition
*
* @phpstan-assert !true $condition
*/
protected function assertNotTrue($condition, string $message = '')
{
Expand All @@ -911,6 +981,8 @@ protected function assertNotTrue($condition, string $message = '')
* Asserts that a variable is null.
*
* @param mixed $actual
*
* @phpstan-assert null $actual
*/
protected function assertNull($actual, string $message = '')
{
Expand Down Expand Up @@ -947,9 +1019,15 @@ protected function assertObjectNotHasAttribute(string $attributeName, object $ob

/**
* Asserts that two variables have the same type and value.
* Used on objects, it asserts that two variables reference
* the same object.
*
* @param mixed $expected
* @template ExpectedType
*
* @param ExpectedType $expected
* @param mixed $actual
*
* @phpstan-assert =ExpectedType $actual
*/
protected function assertSame($expected, $actual, string $message = '')
{
Expand Down Expand Up @@ -1113,6 +1191,8 @@ protected function assertThat($value, PHPUnitConstraint $constraint, string $mes
* Asserts that a condition is true.
*
* @param mixed $condition
*
* @phpstan-assert true $condition
*/
protected function assertTrue($condition, string $message = '')
{
Expand Down