Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Jan 17, 2022
1 parent 67f970c commit 895cbf2
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 34 deletions.
10 changes: 8 additions & 2 deletions tests/Type/WebMozartAssert/data/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ public function keyExists(array $a): void
\PHPStan\Testing\assertType('array{foo: string, bar?: string}', $a);
}

public function validArrayKey($a, bool $b): void
public function validArrayKey($a, bool $b, $c): void
{
Assert::validArrayKey($a);
\PHPStan\Testing\assertType('int|string', $a);

Assert::validArrayKey($b);
\PHPStan\Testing\assertType('*NEVER*', $b);

Assert::nullOrValidArrayKey($c);
\PHPStan\Testing\assertType('int|string|null', $c);
}

/**
Expand Down Expand Up @@ -94,10 +97,13 @@ public function countBetween(array $a, array $b, array $c, array $d): void
\PHPStan\Testing\assertType('*NEVER*', $d);
}

public function isList($a): void
public function isList($a, $b): void
{
Assert::isList($a);
\PHPStan\Testing\assertType('array', $a);

Assert::nullOrIsList($b);
\PHPStan\Testing\assertType('array|null', $b);
}

}
6 changes: 6 additions & 0 deletions tests/Type/WebMozartAssert/data/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public function allString(array $a): void
\PHPStan\Testing\assertType('array<string>', $a);
}

public function allStringNotEmpty(array $a): void
{
Assert::allStringNotEmpty($a);
\PHPStan\Testing\assertType('array<string>', $a); // should be array<non-empty-string>
}

public function allInteger(array $a, iterable $b, iterable $c): void
{
Assert::allInteger($a);
Expand Down
22 changes: 17 additions & 5 deletions tests/Type/WebMozartAssert/data/comparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@

class ComparisonTest
{
public function true($a): void
public function true($a, $b): void
{
Assert::true($a);
\PHPStan\Testing\assertType('true', $a);

Assert::nullOrTrue($b);
\PHPStan\Testing\assertType('true|null', $b);
}

public function false($a): void
public function false($a, $b): void
{
Assert::false($a);
\PHPStan\Testing\assertType('false', $a);

Assert::nullOrFalse($b);
\PHPStan\Testing\assertType('false|null', $b);
}

public function notFalse(int $a): void
public function notFalse($a, $b): void
{
/** @var int|false $a */
Assert::notFalse($a);
Expand All @@ -37,10 +43,13 @@ public function notNull(?int $a): void
\PHPStan\Testing\assertType('int', $a);
}

public function same($a): void
public function same($a, $b): void
{
Assert::same($a, 1);
\PHPStan\Testing\assertType('1', $a);

Assert::nullOrSame($b, 1);
\PHPStan\Testing\assertType('1|null', $b);
}

/**
Expand All @@ -61,9 +70,12 @@ public function inArray($a, $b): void
\PHPStan\Testing\assertType('\'bar\'|\'foo\'|null', $b);
}

public function oneOf($a): void
public function oneOf($a, $b): void
{
Assert::oneOf($a, [1, 2]);
\PHPStan\Testing\assertType('1|2', $a);

Assert::nullOrOneOf($b, [1, 2]);
\PHPStan\Testing\assertType('1|2|null', $b);
}
}
20 changes: 16 additions & 4 deletions tests/Type/WebMozartAssert/data/object.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,40 @@
class ObjectTest
{

public function classExists($a): void
public function classExists($a, $b): void
{
Assert::classExists($a);
\PHPStan\Testing\assertType('class-string', $a);

Assert::nullOrClassExists($b);
\PHPStan\Testing\assertType('class-string|null', $b);
}

public function subclassOf($a): void
public function subclassOf($a, $b): void
{
Assert::subclassOf($a, self::class);
\PHPStan\Testing\assertType('class-string<PHPStan\Type\WebMozartAssert\ObjectTest>|PHPStan\Type\WebMozartAssert\ObjectTest', $a);

Assert::nullOrSubclassOf($b, self::class);
\PHPStan\Testing\assertType('class-string<PHPStan\Type\WebMozartAssert\ObjectTest>|PHPStan\Type\WebMozartAssert\ObjectTest|null', $b);
}

public function interfaceExists($a): void
public function interfaceExists($a, $b): void
{
Assert::interfaceExists($a);
\PHPStan\Testing\assertType('class-string', $a);

Assert::nullOrInterfaceExists($b);
\PHPStan\Testing\assertType('class-string|null', $b);
}

public function implementsInterface($a): void
public function implementsInterface($a, $b): void
{
Assert::implementsInterface($a, ObjectFoo::class);
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\ObjectFoo', $a);

Assert::nullOrImplementsInterface($b, ObjectFoo::class);
\PHPStan\Testing\assertType('PHPStan\Type\WebMozartAssert\ObjectFoo|null', $b);
}

public function propertyExists(object $a): void
Expand Down
20 changes: 16 additions & 4 deletions tests/Type/WebMozartAssert/data/string.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,43 @@
class TestStrings
{

public function length(string $a, string $b): void
public function length(string $a, string $b, string $c): void
{
Assert::length($a, 0);
\PHPStan\Testing\assertType('\'\'', $a);

Assert::length($b, 1);
\PHPStan\Testing\assertType('non-empty-string', $b);

Assert::nullOrLength($c, 1);
\PHPStan\Testing\assertType('non-empty-string', $c); // should be non-empty-string|null
}

public function minLength(string $a, string $b): void
public function minLength(string $a, string $b, string $c): void
{
Assert::minLength($a, 0);
\PHPStan\Testing\assertType('string', $a);

Assert::minLength($b, 1);
\PHPStan\Testing\assertType('non-empty-string', $b);

Assert::nullOrMinLength($c, 1);
\PHPStan\Testing\assertType('non-empty-string', $c); // should be non-empty-string|null
}

public function maxLength(string $a, string $b): void
public function maxLength(string $a, string $b, string $c): void
{
Assert::maxLength($a, 0);
\PHPStan\Testing\assertType('\'\'', $a);

Assert::maxLength($b, 1);
\PHPStan\Testing\assertType('string', $b);

Assert::nullOrMaxLength($c, 1);
\PHPStan\Testing\assertType('string', $c); // should be string|null
}

public function lengthBetween(string $a, string $b, string $c, string $d): void
public function lengthBetween(string $a, string $b, string $c, string $d, string $e): void
{
Assert::lengthBetween($a, 0, 0);
\PHPStan\Testing\assertType('\'\'', $a);
Expand All @@ -47,6 +56,9 @@ public function lengthBetween(string $a, string $b, string $c, string $d): void

Assert::lengthBetween($d, 1, 1);
\PHPStan\Testing\assertType('non-empty-string', $d);

Assert::nullOrLengthBetween($e, 1, 1);
\PHPStan\Testing\assertType('non-empty-string', $e); // should be non-empty-string|null
}

}

0 comments on commit 895cbf2

Please sign in to comment.