Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ private static function getExpressionResolvers(): array
new FuncCall(new Name('count'), [$actual]),
),
),
'GreaterThan' => static fn (Scope $scope, Arg $expected, Arg $actual): Expr\BinaryOp\Greater => new Expr\BinaryOp\Greater(
$actual->value,
$expected->value,
),
'LessThan' => static fn (Scope $scope, Arg $expected, Arg $actual): Expr\BinaryOp\Smaller => new Expr\BinaryOp\Smaller(
$actual->value,
$expected->value,
),
'InstanceOf' => static fn (Scope $scope, Arg $class, Arg $object): Instanceof_ => new Instanceof_(
$object->value,
$class->value,
Expand Down
16 changes: 16 additions & 0 deletions tests/Type/PHPUnit/data/assert-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use function PHPUnit\Framework\assertNotCount;
use function PHPUnit\Framework\assertEmpty;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertGreaterThan;
use function PHPUnit\Framework\assertLessThan;

class Foo
{
Expand Down Expand Up @@ -110,4 +112,18 @@ public function notCount(array $a, array $b): void
assertType('array', $b);
}

/** @param string[] $arr */
public function greaterThanFunction(array $arr): void
{
assertGreaterThan(2, count($arr));
assertType('non-empty-array<string>', $arr);
}

/** @param string[] $arr */
public function lessThanFunction(array $arr): void
{
assertLessThan(1, count($arr));
assertType('array{}', $arr);
}

}
40 changes: 40 additions & 0 deletions tests/Type/PHPUnit/data/assert-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AssertMethod;

use PHPUnit\Framework\TestCase;
use function PHPStan\Testing\assertType;

class Foo
Expand All @@ -13,5 +14,44 @@ public function inheritedAssertMethodsNarrowType(?string $s): void
$customAsserter->assertNotNull($s);
assertType('string', $s);
}
}

class FooBar extends TestCase
{
/** @param string[] $arr */
public function referenceAssertTrue(array $arr): void
{
self::assertTrue(count($arr) > 2);
assertType('non-empty-array<string>', $arr);
}

/** @param string[] $arr */
public function greaterThanStatic(array $arr): void
{
self::assertGreaterThan(2, count($arr));
assertType('non-empty-array<string>', $arr);
}

/** @param string[] $arr */
public function greaterThanMethod(array $arr): void
{
$this->assertGreaterThan(2, count($arr));
assertType('non-empty-array<string>', $arr);
}

/** @param string[] $arr */
public function lessThanTest(array $arr): void
{
self::assertLessThan(1, count($arr));
assertType('array{}', $arr);
}

public function integers(int $a, int $c): void
{
self::assertGreaterThan(5, $a);
assertType('int<6, max>', $a);

self::assertLessThan(5, $c);
assertType('int<min, 4>', $c);
}
}
Loading