UPDATE Method.php, MethodTest.php

- Modify the RegEx, so that an annotation like `@method static $this myMethod()` is parsed correctly
- Write a Unittest for that usecase
This commit is contained in:
Christoph Harms-Ensink
2017-05-29 14:21:25 +02:00
committed by Jaap van Otterdijk
parent c14a4abfd7
commit e9454d844d
2 changed files with 32 additions and 4 deletions
+8 -4
View File
@@ -91,10 +91,14 @@ final class Method extends BaseTag implements Factory\StaticMethod
)? )?
# Return type # Return type
(?: (?:
( (
(?:[\w\|_\\\\]+) (?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
# array notation |
(?:\[\])* (?:
(?:[\w\|_\\\\]+)
# array notation
(?:\[\])*
)
)? )?
\s+ \s+
)? )?
+24
View File
@@ -22,6 +22,7 @@ use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Object_; use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_; use phpDocumentor\Reflection\Types\String_;
use phpDocumentor\Reflection\Types\This;
use phpDocumentor\Reflection\Types\Void_; use phpDocumentor\Reflection\Types\Void_;
/** /**
@@ -276,6 +277,29 @@ class MethodTest extends \PHPUnit_Framework_TestCase
$this->assertSame($description, $fixture->getDescription()); $this->assertSame($description, $fixture->getDescription());
} }
public function testReturnTypeThis()
{
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('');
$descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description);
$fixture = Method::create(
'static $this myMethod()',
$resolver,
$descriptionFactory,
$context
);
$this->assertTrue($fixture->isStatic());
$this->assertSame('static $this myMethod() ', (string)$fixture);
$this->assertSame('myMethod', $fixture->getMethodName());
$this->assertInstanceOf(This::class, $fixture->getReturnType());
}
public function collectionReturnTypesProvider() public function collectionReturnTypesProvider()
{ {
return [ return [