Skip to content

Commit

Permalink
Mock class rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Dec 12, 2020
1 parent c8f413e commit 1b578e3
Showing 1 changed file with 43 additions and 51 deletions.
94 changes: 43 additions & 51 deletions tests/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Barryvdh\LaravelIdeHelper\Macro;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Tag;
use ReflectionClass;
use ReflectionFunction;
use ReflectionFunctionAbstract;

Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
}

0 comments on commit 1b578e3

Please sign in to comment.