|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: Nette\DI\PhpReflection::getReturnType |
| 5 | + * @phpversion 7.1 |
| 6 | + */ |
| 7 | + |
| 8 | +namespace NS |
| 9 | +{ |
| 10 | + use Test\B; |
| 11 | + |
| 12 | + class A |
| 13 | + { |
| 14 | + function noType() |
| 15 | + {} |
| 16 | + |
| 17 | + function classType(): B |
| 18 | + {} |
| 19 | + |
| 20 | + function nativeType(): string |
| 21 | + {} |
| 22 | + |
| 23 | + function selfType(): self |
| 24 | + {} |
| 25 | + |
| 26 | + function nullableClassType(): ?B |
| 27 | + {} |
| 28 | + |
| 29 | + function nullableNativeType(): ?string |
| 30 | + {} |
| 31 | + |
| 32 | + function nullableSelfType(): ?self |
| 33 | + {} |
| 34 | + |
| 35 | + /** @return B */ |
| 36 | + function annotationClassType() |
| 37 | + {} |
| 38 | + |
| 39 | + /** @return B|string */ |
| 40 | + function annotationUnionType() |
| 41 | + {} |
| 42 | + |
| 43 | + /** @return String */ |
| 44 | + function annotationNativeType() |
| 45 | + {} |
| 46 | + |
| 47 | + /** @return self */ |
| 48 | + function annotationSelfType() |
| 49 | + {} |
| 50 | + } |
| 51 | + |
| 52 | + /** @return B */ |
| 53 | + function annotationClassType() |
| 54 | + {} |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +namespace |
| 59 | +{ |
| 60 | + use Nette\DI\PhpReflection; |
| 61 | + use Tester\Assert; |
| 62 | + |
| 63 | + require __DIR__ . '/../bootstrap.php'; |
| 64 | + |
| 65 | + |
| 66 | + Assert::null(PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'noType'))); |
| 67 | + |
| 68 | + Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'classType'))); |
| 69 | + |
| 70 | + Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nativeType'))); |
| 71 | + |
| 72 | + Assert::same('NS\A', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'selfType'))); |
| 73 | + |
| 74 | + Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableClassType'))); |
| 75 | + |
| 76 | + Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableNativeType'))); |
| 77 | + |
| 78 | + Assert::same('NS\A', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableSelfType'))); |
| 79 | + |
| 80 | + Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationClassType'))); |
| 81 | + |
| 82 | + Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationUnionType'))); |
| 83 | + |
| 84 | + Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationNativeType'))); |
| 85 | + |
| 86 | + Assert::same('NS\A', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationSelfType'))); |
| 87 | + |
| 88 | + // class name expanding is NOT supported for global functions |
| 89 | + Assert::same('B', PhpReflection::getReturnType(new \ReflectionFunction('NS\annotationClassType'))); |
| 90 | +} |
0 commit comments