Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1af853
commit a9043e0
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection; | ||
|
||
use NativeMixedType\Foo; | ||
use PhpParser\Node\Name; | ||
use PHPStan\Testing\TestCase; | ||
use PHPStan\Type\MixedType; | ||
|
||
class MixedTypeTest extends TestCase | ||
{ | ||
|
||
public function testMixedType(): void | ||
{ | ||
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) { | ||
$this->markTestSkipped('Test requires PHP 8.0'); | ||
} | ||
|
||
$reflectionProvider = $this->createBroker(); | ||
$class = $reflectionProvider->getClass(Foo::class); | ||
$propertyType = $class->getNativeProperty('fooProp')->getNativeType(); | ||
$this->assertInstanceOf(MixedType::class, $propertyType); | ||
$this->assertTrue($propertyType->isExplicitMixed()); | ||
|
||
$method = $class->getNativeMethod('doFoo'); | ||
$methodVariant = ParametersAcceptorSelector::selectSingle($method->getVariants()); | ||
$methodReturnType = $methodVariant->getReturnType(); | ||
$this->assertInstanceOf(MixedType::class, $methodReturnType); | ||
$this->assertTrue($methodReturnType->isExplicitMixed()); | ||
|
||
$methodParameterType = $methodVariant->getParameters()[0]->getType(); | ||
$this->assertInstanceOf(MixedType::class, $methodParameterType); | ||
$this->assertTrue($methodParameterType->isExplicitMixed()); | ||
|
||
$function = $reflectionProvider->getFunction(new Name('NativeMixedType\doFoo'), null); | ||
$functionVariant = ParametersAcceptorSelector::selectSingle($function->getVariants()); | ||
$functionReturnType = $functionVariant->getReturnType(); | ||
$this->assertInstanceOf(MixedType::class, $functionReturnType); | ||
$this->assertTrue($functionReturnType->isExplicitMixed()); | ||
|
||
$functionParameterType = $functionVariant->getParameters()[0]->getType(); | ||
$this->assertInstanceOf(MixedType::class, $functionParameterType); | ||
$this->assertTrue($functionParameterType->isExplicitMixed()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace NativeMixedType; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public mixed $fooProp; | ||
|
||
public function doFoo(mixed $foo): mixed | ||
{ | ||
assertType('mixed', $foo); | ||
assertType('mixed', $this->fooProp); | ||
} | ||
|
||
} | ||
|
||
class Bar | ||
{ | ||
|
||
} | ||
|
||
function doFoo(mixed $foo): mixed | ||
{ | ||
assertType('mixed', $foo); | ||
} | ||
|
||
function (Foo $foo): void { | ||
assertType('mixed', $foo->fooProp); | ||
assertType('mixed', $foo->doFoo(1)); | ||
assertType('mixed', doFoo(1)); | ||
}; | ||
|
||
function (): void { | ||
$f = function (mixed $foo): mixed { | ||
assertType('mixed', $foo); | ||
}; | ||
|
||
assertType('mixed', $f(1)); | ||
}; |