From 1b578e3c806456d3a15e3535eacf57ebe0827566 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev Date: Sat, 12 Dec 2020 12:02:35 +0400 Subject: [PATCH] Mock class rename. --- tests/MacroTest.php | 94 +++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/tests/MacroTest.php b/tests/MacroTest.php index f0fbf9bbe..20eb56248 100644 --- a/tests/MacroTest.php +++ b/tests/MacroTest.php @@ -7,6 +7,7 @@ use Barryvdh\LaravelIdeHelper\Macro; use Barryvdh\Reflection\DocBlock; use Barryvdh\Reflection\DocBlock\Tag; +use ReflectionClass; use ReflectionFunction; use ReflectionFunctionAbstract; @@ -21,39 +22,13 @@ */ class MacroTest extends TestCase { - private $macro = null; - - public function setUp(): void - { - parent::setUp(); - - $this->macro = new class() extends Macro { - public function __construct() - { - // no need to call parent - } - - public function getPhpDoc(ReflectionFunctionAbstract $method): DocBlock - { - return (new Macro($method, '', $method->getClosureScopeClass()))->phpdoc; - } - }; - } - - public function tearDown(): void - { - $this->macro = null; - - parent::tearDown(); - } - /** * @covers ::initPhpDoc * @throws \ReflectionException */ public function testInitPhpDocClosureWithoutDocBlock(): void { - $phpdoc = $this->macro->getPhpDoc( + $phpdoc = (new MacroMock())->getPhpDoc( new ReflectionFunction( function (int $a = null): int { return 0; @@ -74,11 +49,11 @@ function (int $a = null): int { */ public function testInitPhpDocClosureWithArgsAndReturnType(): void { - $phpdoc = $this->macro->getPhpDoc( + $phpdoc = (new MacroMock())->getPhpDoc( new ReflectionFunction( - /** - * Test docblock. - */ + /** + * Test docblock. + */ function (int $a = null): int { return 0; } @@ -98,11 +73,11 @@ function (int $a = null): int { */ public function testInitPhpDocClosureWithArgs(): void { - $phpdoc = $this->macro->getPhpDoc( + $phpdoc = (new MacroMock())->getPhpDoc( new ReflectionFunction( - /** - * Test docblock. - */ + /** + * Test docblock. + */ function (int $a = null) { return 0; } @@ -122,11 +97,11 @@ function (int $a = null) { */ public function testInitPhpDocClosureWithReturnType(): void { - $phpdoc = $this->macro->getPhpDoc( + $phpdoc = (new MacroMock())->getPhpDoc( new ReflectionFunction( - /** - * Test docblock. - */ + /** + * Test docblock. + */ function (): int { return 0; } @@ -145,13 +120,13 @@ function (): int { */ public function testInitPhpDocParamsAddedOnlyNotPresent(): void { - $phpdoc = $this->macro->getPhpDoc( + $phpdoc = (new MacroMock())->getPhpDoc( new ReflectionFunction( - /** - * Test docblock. - * - * @param \stdClass|null $a aaaaa - */ + /** + * Test docblock. + * + * @param \stdClass|null $a aaaaa + */ function ($a = null): int { return 0; } @@ -169,13 +144,13 @@ function ($a = null): int { */ public function testInitPhpDocReturnAddedOnlyNotPresent(): void { - $phpdoc = $this->macro->getPhpDoc( + $phpdoc = (new MacroMock())->getPhpDoc( new ReflectionFunction( - /** - * Test docblock. - * - * @return \stdClass|null rrrrrrr - */ + /** + * Test docblock. + * + * @return \stdClass|null rrrrrrr + */ function ($a = null): int { return 0; } @@ -202,3 +177,20 @@ function (Tag $tag) { return $tags; } } + +/** + * @internal + * @noinspection PhpMultipleClassesDeclarationsInOneFile + */ +class MacroMock extends Macro +{ + public function __construct() + { + // no need to call parent + } + + public function getPhpDoc(ReflectionFunctionAbstract $method, ReflectionClass $class = null): DocBlock + { + return (new Macro($method, '', $class ?? $method->getClosureScopeClass()))->phpdoc; + } +}