diff --git a/tests/Go/Proxy/Part/InterceptedFunctionGeneratorTest.php b/tests/Go/Proxy/Part/InterceptedFunctionGeneratorTest.php index 6d783a3e..7160f2ed 100644 --- a/tests/Go/Proxy/Part/InterceptedFunctionGeneratorTest.php +++ b/tests/Go/Proxy/Part/InterceptedFunctionGeneratorTest.php @@ -12,8 +12,11 @@ namespace Go\Proxy\Part; +use Countable; use Exception; use Go\Proxy\Generator\FunctionGenerator; +use Go\Stubs\StubAttribute; +use Iterator; use PHPUnit\Framework\TestCase; use ReflectionFunction; @@ -30,6 +33,17 @@ function funcWithReturnTypeAndDocBlock(): Exception return new Exception('Test'); } +#[StubAttribute("function")] +function funcWithAttributes(#[StubAttribute("argument")] string $argument): string +{ + return $argument; +} + +function funcWithDNFTypeReturn(Iterator|(Exception&Countable) $value): Iterator|(Exception&Countable) +{ + return $value; +} + /** * Contains test function with nullable parameters and nullable return type */ @@ -83,23 +97,23 @@ public function testGenerate(string $functionName, string $expectedSignature): v public static function dataGenerator(): array { return [ - [ + 'var_dump' => [ 'var_dump', 'function var_dump(mixed $value, mixed ...$values): void' ], - [ + 'array_pop' => [ 'array_pop', 'function array_pop(array &$array): mixed' ], - [ + 'strcoll' => [ 'strcoll', 'function strcoll(string $string1, string $string2): int' ], - [ + 'microtime' => [ 'microtime', 'function microtime(bool $as_float = false): string|float' ], - [ + 'funcWithReturnTypeAndDocBlock' => [ '\Go\Proxy\Part\funcWithReturnTypeAndDocBlock', 'function funcWithReturnTypeAndDocBlock(): \Exception' ], @@ -115,6 +129,14 @@ public static function dataGenerator(): array '\Go\Proxy\Part\funcReturningNull', 'function funcReturningNull(): null' ], + 'funcWithAttributes' => [ + '\Go\Proxy\Part\funcWithAttributes', + "#[\\Go\\Stubs\\StubAttribute('function')]\nfunction funcWithAttributes(\n #[\\Go\\Stubs\\StubAttribute('argument')]\n string \$argument\n): string" + ], + 'funcWithDNFTypeReturn' => [ + '\Go\Proxy\Part\funcWithDNFTypeReturn', + 'function funcWithDNFTypeReturn(\Iterator|(\Exception&\Countable) $value): \Iterator|(\Exception&\Countable)' + ], ]; } } diff --git a/tests/Go/Proxy/Part/InterceptedMethodGeneratorTest.php b/tests/Go/Proxy/Part/InterceptedMethodGeneratorTest.php index 53cbddd6..524d83cb 100644 --- a/tests/Go/Proxy/Part/InterceptedMethodGeneratorTest.php +++ b/tests/Go/Proxy/Part/InterceptedMethodGeneratorTest.php @@ -49,31 +49,51 @@ public function testGenerate(string $className, string $methodName, string $expe public static function dataGenerator(): array { return [ - [ + 'variadicArgsTest' => [ First::class, 'variadicArgsTest', 'public function variadicArgsTest(...$args): string' ], - [ + 'staticLsbRecursion' => [ First::class, 'staticLsbRecursion', 'public static function staticLsbRecursion(int $value, int $level = 0): int' ], - [ + 'staticLsbProtected' => [ First::class, 'staticLsbProtected', 'protected static function staticLsbProtected(): string' ], - [ + 'passByReference' => [ First::class, 'passByReference', 'public function passByReference(&$valueByReference)' ], - [ + 'privateMethod' => [ First::class, 'privateMethod', 'private function privateMethod(): int' ], + 'publicMethodWithUnionTypeReturn' => [ + First::class, + 'publicMethodWithUnionTypeReturn', + 'public function publicMethodWithUnionTypeReturn(\Exception|\Closure $value): \Exception|\Closure' + ], + 'publicMethodWithIntersectionTypeReturn' => [ + First::class, + 'publicMethodWithIntersectionTypeReturn', + 'public function publicMethodWithIntersectionTypeReturn(\Exception&\Countable $value): \Exception&\Countable' + ], + 'publicMethodWithDNFTypeReturn' => [ + First::class, + 'publicMethodWithDNFTypeReturn', + 'public function publicMethodWithDNFTypeReturn(\Iterator|(\Exception&\Countable) $value): \Iterator|(\Exception&\Countable)' + ], + 'publicMethodWithAttribute' => [ + First::class, + 'publicMethodWithAttribute', + "#[\\Go\\Stubs\\StubAttribute('Go\\Stubs\\First')]\npublic function publicMethodWithAttribute(\n #[\\Go\\Stubs\\StubAttribute('argument')]\n string \$argument\n): string" + ], ]; } } diff --git a/tests/Go/Stubs/First.php b/tests/Go/Stubs/First.php index c3443162..2f34f720 100644 --- a/tests/Go/Stubs/First.php +++ b/tests/Go/Stubs/First.php @@ -12,6 +12,11 @@ namespace Go\Stubs; +use Closure; +use Countable; +use Exception; +use Iterator; + #[StubAttribute(First::class)] class First { @@ -38,6 +43,9 @@ protected function protectedMethod(): int return $this->protected; } + /** + * @return int Some description + */ public function publicMethod(): int { return $this->public; @@ -53,10 +61,28 @@ protected final function protectedFinalMethod(): void // nothing here } + /** + * @link https://github.com/laminas/laminas-code/pull/145 For tracking why attributes are not suuported + */ #[StubAttribute(First::class)] - public function publicMethodWithAttribute(): string + public function publicMethodWithAttribute(#[StubAttribute("argument")] string $argument): string { - return $this->publicWithAttribute; + return $argument; + } + + public function publicMethodWithUnionTypeReturn(Exception|Closure $value): Exception|Closure + { + return $value; + } + + public function publicMethodWithIntersectionTypeReturn(Exception&Countable $value): Exception&Countable + { + return $value; + } + + public function publicMethodWithDNFTypeReturn(Iterator|(Exception&Countable) $value): Iterator|(Exception&Countable) + { + return $value; } // Static methods that access self:: properties