Skip to content

Commit

Permalink
add native expression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed Oct 9, 2022
1 parent 85b42cf commit 2744c22
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 @@ -1054,6 +1054,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/array-offset-unset.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8008.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5552.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 2744c22

Please sign in to comment.