diff --git a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php index cb66a942057..ebe126d4cd5 100644 --- a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php +++ b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/MultilineTest.php @@ -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; + } } diff --git a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php index 40edea3ab1c..fdf174339ca 100644 --- a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php +++ b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/PhpDocInfoPrinterTest.php @@ -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() */ diff --git a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Basic/doc12.txt b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Basic/doc12.txt deleted file mode 100644 index 54147a452f4..00000000000 --- a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Basic/doc12.txt +++ /dev/null @@ -1 +0,0 @@ -/** @var Type */ \ No newline at end of file diff --git a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/route_property.txt b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/route_property.txt new file mode 100644 index 00000000000..b75c793c5c9 --- /dev/null +++ b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/route_property.txt @@ -0,0 +1,7 @@ +/** + * @Route( + * "/{arg1}/{arg2}", + * defaults={"arg1"=null, "arg2"=""}, + * requirements={"arg1"="\d+", "arg2"=".*"} + * ) + */ diff --git a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/table.txt b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/table.txt new file mode 100644 index 00000000000..23844f12b96 --- /dev/null +++ b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/Multiline/table.txt @@ -0,0 +1,5 @@ +/** + * @ORM\Table("Table_Name") + * @ORM\Entity() + * @ORM\InheritanceType("SINGLE_TABLE") + */ \ No newline at end of file diff --git a/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php new file mode 100644 index 00000000000..ef31a93c582 --- /dev/null +++ b/packages/BetterPhpDocParser/tests/PhpDocInfo/PhpDocInfoPrinter/Source/RoutePropertyClass.php @@ -0,0 +1,19 @@ +