Skip to content

Commit

Permalink
add native expression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan authored and ondrejmirtes committed Oct 11, 2022
1 parent 44c1b12 commit 56b4a37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1065,6 +1065,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/extra-extra-int-types.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/list-count.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Properties/data/bug-7839.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/native-expressions.php');
}

/**
Expand Down
43 changes: 43 additions & 0 deletions tests/PHPStan/Analyser/data/native-expressions.php
@@ -0,0 +1,43 @@
<?php

namespace NativeExpressions;

use function PHPStan\Testing\assertType;

function doFoo(): string
{
}

function (): void {
/** @var non-empty-string $a */
$a = doFoo();
assertType('non-empty-string', $a);
assertNativeType('string', $a);
};

/**
* @param positive-int|non-empty-string $a
*/
function foo(int|string $a): void
{
assertType('int<1, max>|non-empty-string', $a);
assertNativeType('int|string', $a);
if (is_string($a)) {
assertType('non-empty-string', $a);
assertNativeType('string', $a);
}
}

class Foo{
public function __construct(
/** @var non-empty-array<mixed> */
private array $array
){
assertType('non-empty-array', $this->array);
assertNativeType('array', $this->array);
if(count($array) === 0){
throw new \InvalidArgumentException();
}
}
}

0 comments on commit 56b4a37

Please sign in to comment.