-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type, Reflection: supports intersection types
- Loading branch information
Showing
12 changed files
with
275 additions
and
24 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
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,74 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Utils\Reflection::getParameterType | ||
* @phpversion 8.1 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Utils\Reflection; | ||
use Test\B; // for testing purposes | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class A | ||
{ | ||
public function method( | ||
Undeclared $undeclared, | ||
B $b, | ||
array $array, | ||
callable $callable, | ||
self $self, | ||
$none, | ||
?B $nullable, | ||
mixed $mixed, | ||
array|self $union, | ||
array|self|null $nullableUnion, | ||
AExt&A $intersection, | ||
) { | ||
} | ||
} | ||
|
||
class AExt extends A | ||
{ | ||
public function methodExt(parent $parent) | ||
{ | ||
} | ||
} | ||
|
||
$method = new ReflectionMethod('A', 'method'); | ||
$params = $method->getParameters(); | ||
|
||
Assert::same('Undeclared', Reflection::getParameterType($params[0])); | ||
Assert::same('Test\B', Reflection::getParameterType($params[1])); | ||
Assert::same('array', Reflection::getParameterType($params[2])); | ||
Assert::same('callable', Reflection::getParameterType($params[3])); | ||
Assert::same('A', Reflection::getParameterType($params[4])); | ||
Assert::null(Reflection::getParameterType($params[5])); | ||
Assert::same('Test\B', Reflection::getParameterType($params[6])); | ||
Assert::same(['Test\B', 'null'], Reflection::getParameterTypes($params[6])); | ||
Assert::same('mixed', Reflection::getParameterType($params[7])); | ||
Assert::same(['mixed'], Reflection::getParameterTypes($params[7])); | ||
Assert::same(['A', 'array'], Reflection::getParameterTypes($params[8])); | ||
Assert::same(['A', 'array', 'null'], Reflection::getParameterTypes($params[9])); | ||
|
||
Assert::exception(function () use ($params) { | ||
Reflection::getParameterType($params[8]); | ||
}, Nette\InvalidStateException::class, 'The $union in A::method() is not expected to have a union or intersection type.'); | ||
|
||
Assert::exception(function () use ($params) { | ||
Reflection::getParameterType($params[9]); | ||
}, Nette\InvalidStateException::class, 'The $nullableUnion in A::method() is not expected to have a union or intersection type.'); | ||
|
||
Assert::exception(function () use ($params) { | ||
Reflection::getParameterType($params[10]); | ||
}, Nette\InvalidStateException::class, 'The $intersection in A::method() is not expected to have a union or intersection type.'); | ||
|
||
$method = new ReflectionMethod('AExt', 'methodExt'); | ||
$params = $method->getParameters(); | ||
|
||
Assert::same('A', Reflection::getParameterType($params[0])); |
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,67 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Utils\Reflection::getPropertyType | ||
* @phpversion 8.1 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Utils\Reflection; | ||
use Test\B; // for testing purposes | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class A | ||
{ | ||
public Undeclared $undeclared; | ||
public B $b; | ||
public array $array; | ||
public self $self; | ||
public $none; | ||
public ?B $nullable; | ||
public mixed $mixed; | ||
public array|self $union; | ||
public array|self|null $nullableUnion; | ||
public AExt&A $intersection; | ||
} | ||
|
||
class AExt extends A | ||
{ | ||
public parent $parent; | ||
} | ||
|
||
$class = new ReflectionClass('A'); | ||
$props = $class->getProperties(); | ||
|
||
Assert::same('Undeclared', Reflection::getPropertyType($props[0])); | ||
Assert::same('Test\B', Reflection::getPropertyType($props[1])); | ||
Assert::same('array', Reflection::getPropertyType($props[2])); | ||
Assert::same('A', Reflection::getPropertyType($props[3])); | ||
Assert::null(Reflection::getPropertyType($props[4])); | ||
Assert::same('Test\B', Reflection::getPropertyType($props[5])); | ||
Assert::same(['Test\B', 'null'], Reflection::getPropertyTypes($props[5])); | ||
Assert::same('mixed', Reflection::getPropertyType($props[6])); | ||
Assert::same(['mixed'], Reflection::getPropertyTypes($props[6])); | ||
Assert::same(['A', 'array'], Reflection::getPropertyTypes($props[7])); | ||
Assert::same(['A', 'array', 'null'], Reflection::getPropertyTypes($props[8])); | ||
|
||
Assert::exception(function () use ($props) { | ||
Reflection::getPropertyType($props[7]); | ||
}, Nette\InvalidStateException::class, 'The A::$union is not expected to have a union or intersection type.'); | ||
|
||
Assert::exception(function () use ($props) { | ||
Reflection::getPropertyType($props[8]); | ||
}, Nette\InvalidStateException::class, 'The A::$nullableUnion is not expected to have a union or intersection type.'); | ||
|
||
Assert::exception(function () use ($props) { | ||
Reflection::getPropertyType($props[9]); | ||
}, Nette\InvalidStateException::class, 'The A::$intersection is not expected to have a union or intersection type.'); | ||
|
||
$class = new ReflectionClass('AExt'); | ||
$props = $class->getProperties(); | ||
|
||
Assert::same('A', Reflection::getPropertyType($props[0])); |
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
Oops, something went wrong.