improve doc tests

This commit is contained in:
Tomas Votruba 2019-10-05 12:39:48 +02:00
parent a92eba9da2
commit ecf0a430dd
7 changed files with 77 additions and 17 deletions

View File

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

View File

@ -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()
*/

View File

@ -0,0 +1,7 @@
/**
* @Route(
* "/{arg1}/{arg2}",
* defaults={"arg1"=null, "arg2"=""},
* requirements={"arg1"="\d+", "arg2"=".*"}
* )
*/

View File

@ -0,0 +1,5 @@
/**
* @ORM\Table("Table_Name")
* @ORM\Entity()
* @ORM\InheritanceType("SINGLE_TABLE")
*/

View File

@ -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
{
}
}

View File

@ -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
{
}