mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-13 20:36:23 +01:00
improve doc tests
This commit is contained in:
parent
a92eba9da2
commit
ecf0a430dd
@ -7,13 +7,16 @@ use Nette\Utils\FileSystem;
|
||||
use PhpParser\BuilderFactory;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Nop;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\AnotherPropertyClass;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\Class_\SomeEntityClass;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\DoctrinePropertyClass;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\ManyToPropertyClass;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\RoutePropertyClass;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\SinglePropertyClass;
|
||||
use Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source\TableClass;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
final class MultilineTest extends AbstractPhpDocInfoPrinterTest
|
||||
@ -43,6 +46,8 @@ final class MultilineTest extends AbstractPhpDocInfoPrinterTest
|
||||
public function provideDataClass(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Source/Class_/some_entity_class.txt', new Class_(SomeEntityClass::class)];
|
||||
|
||||
yield [__DIR__ . '/Source/Multiline/table.txt', new Class_(TableClass::class)];
|
||||
}
|
||||
|
||||
public function provideDataForProperty(): Iterator
|
||||
@ -58,6 +63,9 @@ final class MultilineTest extends AbstractPhpDocInfoPrinterTest
|
||||
|
||||
$property = $this->createPublicPropertyUnderClass('someProperty', DoctrinePropertyClass::class);
|
||||
yield [__DIR__ . '/Source/Multiline/multiline6.txt', $property];
|
||||
|
||||
$property = $this->createMethodUnderClass('someMethod', RoutePropertyClass::class);
|
||||
yield [__DIR__ . '/Source/Multiline/route_property.txt', $property];
|
||||
}
|
||||
|
||||
private function createPublicPropertyUnderClass(string $name, string $class): Property
|
||||
@ -72,4 +80,17 @@ final class MultilineTest extends AbstractPhpDocInfoPrinterTest
|
||||
|
||||
return $property;
|
||||
}
|
||||
|
||||
private function createMethodUnderClass(string $name, string $class): ClassMethod
|
||||
{
|
||||
$builderFactory = new BuilderFactory();
|
||||
|
||||
$methodBuilder = $builderFactory->method($name);
|
||||
$methodBuilder->makePublic();
|
||||
|
||||
$method = $methodBuilder->getNode();
|
||||
$method->setAttribute(AttributeKey::CLASS_NAME, $class);
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,17 @@ use PhpParser\Node\Stmt\Nop;
|
||||
|
||||
final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $docFilePath): void
|
||||
{
|
||||
$docComment = FileSystem::read($docFilePath);
|
||||
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, new Nop());
|
||||
|
||||
$this->assertSame($docComment, $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo));
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Source/Basic/doc.txt'];
|
||||
@ -21,27 +32,11 @@ final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
|
||||
yield [__DIR__ . '/Source/Basic/doc9.txt'];
|
||||
yield [__DIR__ . '/Source/Basic/doc10.txt'];
|
||||
yield [__DIR__ . '/Source/Basic/doc11.txt'];
|
||||
yield [__DIR__ . '/Source/Basic/doc12.txt'];
|
||||
yield [__DIR__ . '/Source/Basic/doc13.txt'];
|
||||
yield [__DIR__ . '/Source/Basic/doc14.txt'];
|
||||
yield [__DIR__ . '/Source/Basic/doc15.txt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $docFilePath): void
|
||||
{
|
||||
$docComment = FileSystem::read($docFilePath);
|
||||
$phpDocInfo = $this->createPhpDocInfoFromDocCommentAndNode($docComment, new Nop());
|
||||
|
||||
$this->assertSame(
|
||||
$docComment,
|
||||
$this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo),
|
||||
'Caused in ' . $docFilePath
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataEmpty()
|
||||
*/
|
||||
|
@ -1 +0,0 @@
|
||||
/** @var Type */
|
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @Route(
|
||||
* "/{arg1}/{arg2}",
|
||||
* defaults={"arg1"=null, "arg2"=""},
|
||||
* requirements={"arg1"="\d+", "arg2"=".*"}
|
||||
* )
|
||||
*/
|
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @ORM\Table("Table_Name")
|
||||
* @ORM\Entity()
|
||||
* @ORM\InheritanceType("SINGLE_TABLE")
|
||||
*/
|
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class RoutePropertyClass
|
||||
{
|
||||
/**
|
||||
* @Route(
|
||||
* "/{arg1}/{arg2}",
|
||||
* defaults={"arg1"=null, "arg2"=""},
|
||||
* requirements={"arg1"="\d+", "arg2"=".*"}
|
||||
* )
|
||||
*/
|
||||
public function nothing(): void
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfoPrinter\Source;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Table("Table_Name")
|
||||
* @ORM\Entity()
|
||||
* @ORM\InheritanceType("SINGLE_TABLE")
|
||||
*/
|
||||
class TableClass
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user