Skip to content

Commit

Permalink
Add broken test with failing attributes generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Apr 14, 2024
1 parent 5d7e1ad commit c1f54a5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 18 deletions.
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

0 comments on commit c1f54a5

Please sign in to comment.