Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP8] Add broken test with failing attributes generation #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions tests/Go/Proxy/Part/InterceptedFunctionGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

namespace Go\Proxy\Part;

use Countable;
use Exception;
use Go\Stubs\StubAttribute;
use Iterator;
use PHPUnit\Framework\TestCase;

use ReflectionFunction;
Expand All @@ -29,6 +32,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;
}

/**
* Test case for generated function definition
*/
Expand Down Expand Up @@ -62,26 +76,34 @@ 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) : float|string'
],
[
'funcWithReturnTypeAndDocBlock' => [
'\Go\Proxy\Part\funcWithReturnTypeAndDocBlock',
'function funcWithReturnTypeAndDocBlock() : \Exception'
],
'funcWithAttributes' => [
'\Go\Proxy\Part\funcWithAttributes',
'function funcWithAttributes(#[\Go\Stubs\StubAttribute("argument")] string $argument) : string'
],
'funcWithDNFTypeReturn' => [
'\Go\Proxy\Part\funcWithDNFTypeReturn',
'function funcWithDNFTypeReturn((\Countable&\Exception)|\Iterator $value) : (\Countable&\Exception)|\Iterator'
],
];
}
}
30 changes: 25 additions & 5 deletions tests/Go/Proxy/Part/InterceptedMethodGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(\Closure|\Exception $value) : \Closure|\Exception'
],
'publicMethodWithIntersectionTypeReturn' => [
First::class,
'publicMethodWithIntersectionTypeReturn',
'public function publicMethodWithIntersectionTypeReturn(\Countable&\Exception $value) : \Countable&\Exception'
],
'publicMethodWithDNFTypeReturn' => [
First::class,
'publicMethodWithDNFTypeReturn',
'public function publicMethodWithDNFTypeReturn((\Countable&\Exception)|\Iterator $value) : (\Countable&\Exception)|\Iterator'
],
'publicMethodWithAttribute' => [
First::class,
'publicMethodWithAttribute',
'public function publicMethodWithAttribute(#[\Go\Stubs\StubAttribute("argument")] string $argument) : string'
],
];
}
}
12 changes: 6 additions & 6 deletions tests/Go/Proxy/Part/JoinPointPropertyGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function testGenerate(): void
$generator = new JoinPointPropertyGenerator([
'method' => [
'execute' => [
'advisor.Demo\\Aspect\\LoggingAspect->beforeMethodExecution',
'Demo\\Aspect\\LoggingAspect->beforeMethodExecution',
],
'perform' => [
'advisor.Demo\\Aspect\\LoggingAspect->beforeMethodExecution',
'Demo\\Aspect\\LoggingAspect->beforeMethodExecution',
],
],
'static' => [
'runByName' => [
'advisor.Demo\\Aspect\\LoggingAspect->beforeMethodExecution',
'Demo\\Aspect\\LoggingAspect->beforeMethodExecution',
],
],
]);
Expand All @@ -50,15 +50,15 @@ public function testGenerate(): void
private static $__joinPoints = [
\'method\' => [
\'execute\' => [
\'advisor.Demo\\\\Aspect\\\\LoggingAspect->beforeMethodExecution\',
\'Demo\\\\Aspect\\\\LoggingAspect->beforeMethodExecution\',
],
\'perform\' => [
\'advisor.Demo\\\\Aspect\\\\LoggingAspect->beforeMethodExecution\',
\'Demo\\\\Aspect\\\\LoggingAspect->beforeMethodExecution\',
],
],
\'static\' => [
\'runByName\' => [
\'advisor.Demo\\\\Aspect\\\\LoggingAspect->beforeMethodExecution\',
\'Demo\\\\Aspect\\\\LoggingAspect->beforeMethodExecution\',
],
],
];'
Expand Down
30 changes: 28 additions & 2 deletions tests/Go/Stubs/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

namespace Go\Stubs;

use Closure;
use Countable;
use Exception;
use Iterator;

#[StubAttribute(First::class)]
class First
{
Expand All @@ -38,6 +43,9 @@ protected function protectedMethod(): int
return $this->protected;
}

/**
* @return int Some description
*/
public function publicMethod(): int
{
return $this->public;
Expand All @@ -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
Expand Down
Loading