Skip to content

Commit

Permalink
Upgrade to PHPUnit 10 🥳️ (#3332)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 3, 2023
1 parent 1fd3807 commit c3ff0fd
Show file tree
Hide file tree
Showing 632 changed files with 2,572 additions and 3,261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:

- uses: "ramsey/composer-install@v1"

- run: vendor/bin/paratest ${{ matrix.path }} --colors --verbose
- run: vendor/bin/phpunit ${{ matrix.path }} --colors
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ composer.lock
.idea/

.phpunit.result.cache
# since PHPUnit 10
.phpunit.cache

# often customized locally - example on Github is just fine
rector-recipe.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function test(string $filePath): void
/**
* @return Iterator<array<string>>
*/
public function provideData(): Iterator
public static function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"rector/rector-php-parser": "dev-main",
"rector/rector-phpunit": "dev-main",
"rector/rector-symfony": "dev-main",
"sebastian/diff": "^4.0.4",
"sebastian/diff": "^5.0",
"symfony/config": "^6.2",
"symfony/console": "^6.2.2",
"symfony/contracts": "^3.2",
Expand All @@ -39,7 +39,6 @@
"webmozart/assert": "^1.11"
},
"require-dev": {
"brianium/paratest": "^6.7",
"cweagans/composer-patches": "^1.7.2",
"icanhazstring/composer-unused": "^0.8.5",
"myclabs/php-enum": "^1.8.4",
Expand All @@ -49,7 +48,7 @@
"phpstan/phpstan-php-parser": "^1.1",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpstan/phpstan-webmozart-assert": "^1.2.2",
"phpunit/phpunit": "^9.5.27",
"phpunit/phpunit": "^10.0",
"rector/phpstan-rules": "^0.6.5",
"rector/rector-debugging": "dev-main",
"rector/rector-generator": "dev-main",
Expand Down
4 changes: 0 additions & 4 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use Rector\PSR4\Composer\PSR4NamespaceMatcher;
use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface;
use Rector\Utils\Command\MissingInSetCommand;
use SebastianBergmann\Diff\Differ;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
Expand Down Expand Up @@ -227,7 +226,4 @@
$services->set(\PHPStan\PhpDocParser\Lexer\Lexer::class);
$services->set(TypeParser::class);
$services->set(ConstExprParser::class);

// console color diff
$services->set(Differ::class);
};
2 changes: 1 addition & 1 deletion e2e/e2eTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}

// print color diff, to make easy find the differences
$consoleDiffer = new ConsoleDiffer(new Differ(), new ColorConsoleDiffFormatter());
$consoleDiffer = new ConsoleDiffer(new ColorConsoleDiffFormatter());
$diff = $consoleDiffer->diff($output, $expectedOutput);
$symfonyStyle->writeln($diff);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Rector\Testing\Fixture\FixtureFileFinder;
use Rector\Testing\PHPUnit\AbstractTestCase;

abstract class AbstractPhpDocInfoPrinterTest extends AbstractTestCase
abstract class AbstractPhpDocInfoPrinterTestCase extends AbstractTestCase
{
protected FilePathHelper $filePathHelper;

Expand All @@ -41,7 +41,7 @@ protected function createPhpDocInfoFromDocCommentAndNode(string $docComment, Nod
* This is a new way to load test fixtures :)
* @return Iterator<array<int, string>>
*/
protected function yieldFilesFromDirectory(string $directory, string $suffix = '*.php'): Iterator
protected static function yieldFilesFromDirectory(string $directory, string $suffix = '*.php'): Iterator
{
return FixtureFileFinder::yieldDirectory($directory, $suffix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
use Nette\Utils\FileSystem;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\CaseSensitive;
use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\IndexInTable;
use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Doctrine\Short;

final class DoctrineTest extends AbstractPhpDocInfoPrinterTest
final class DoctrineTest extends AbstractPhpDocInfoPrinterTestCase
{
/**
* @dataProvider provideDataClass()
*/
#[DataProvider('provideDataClass')]
public function testClass(string $docFilePath, Node $node): void
{
$docComment = FileSystem::read($docFilePath);
Expand All @@ -26,7 +25,7 @@ public function testClass(string $docFilePath, Node $node): void
$this->assertSame($docComment, $printedPhpDocInfo);
}

public function provideDataClass(): Iterator
public static function provideDataClass(): Iterator
{
yield [__DIR__ . '/Source/Doctrine/index_in_table.txt', new Class_(IndexInTable::class)];
yield [__DIR__ . '/Source/Doctrine/case_sensitive.txt', new Class_(CaseSensitive::class)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Property;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\Class_\SomeEntityClass;
use Rector\Tests\BetterPhpDocParser\PhpDocInfo\PhpDocInfoPrinter\Source\TableClass;

final class MultilineTest extends AbstractPhpDocInfoPrinterTest
final class MultilineTest extends AbstractPhpDocInfoPrinterTestCase
{
/**
* @dataProvider provideData()
* @dataProvider provideDataForProperty()
* @dataProvider provideDataClass()
*/
#[DataProvider('provideData')]
#[DataProvider('provideDataForProperty')]
#[DataProvider('provideDataClass')]
public function test(string $docFilePath, Node $node): void
{
$docComment = FileSystem::read($docFilePath);
Expand All @@ -31,7 +30,7 @@ public function test(string $docFilePath, Node $node): void
$this->assertSame($docComment, $printedPhpDocInfo);
}

public function provideData(): Iterator
public static function provideData(): Iterator
{
yield [__DIR__ . '/Source/Multiline/multiline1.txt', new Nop()];
yield [__DIR__ . '/Source/Multiline/multiline2.txt', new Nop()];
Expand All @@ -43,31 +42,31 @@ public function provideData(): Iterator
/**
* @return Iterator<string[]|Class_[]>
*/
public function provideDataClass(): Iterator
public static 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
public static function provideDataForProperty(): Iterator
{
$property = $this->createPublicPropertyUnderClass('manyTo');
$property = self::createPublicPropertyUnderClass('manyTo');
yield [__DIR__ . '/Source/Multiline/many_to.txt', $property];

$property = $this->createPublicPropertyUnderClass('anotherProperty');
$property = self::createPublicPropertyUnderClass('anotherProperty');
yield [__DIR__ . '/Source/Multiline/assert_serialize.txt', $property];

$property = $this->createPublicPropertyUnderClass('anotherSerializeSingleLine');
$property = self::createPublicPropertyUnderClass('anotherSerializeSingleLine');
yield [__DIR__ . '/Source/Multiline/assert_serialize_single_line.txt', $property];

$property = $this->createPublicPropertyUnderClass('someProperty');
$property = self::createPublicPropertyUnderClass('someProperty');
yield [__DIR__ . '/Source/Multiline/multiline6.txt', $property];

$property = $this->createMethodUnderClass('someMethod');
$property = self::createMethodUnderClass('someMethod');
yield [__DIR__ . '/Source/Multiline/route_property.txt', $property];
}

private function createPublicPropertyUnderClass(string $name): Property
private static function createPublicPropertyUnderClass(string $name): Property
{
$builderFactory = new BuilderFactory();

Expand All @@ -77,7 +76,7 @@ private function createPublicPropertyUnderClass(string $name): Property
return $propertyBuilder->getNode();
}

private function createMethodUnderClass(string $name): ClassMethod
private static function createMethodUnderClass(string $name): ClassMethod
{
$builderFactory = new BuilderFactory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Iterator;
use Nette\Utils\FileSystem;
use PhpParser\Node\Stmt\Nop;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Core\FileSystem\FilePathHelper;

final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTestCase
{
/**
* @dataProvider provideData()
* @dataProvider provideDataCallable()
*/
#[DataProvider('provideData')]
#[DataProvider('provideDataCallable')]
public function test(string $docFilePath): void
{
$this->doComparePrintedFileEquals($docFilePath, $docFilePath);
Expand All @@ -28,19 +27,17 @@ public function testRemoveSpace(): void
);
}

public function provideData(): Iterator
public static function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureBasic', '*.txt');
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureBasic', '*.txt');
}

public function provideDataCallable(): Iterator
public static function provideDataCallable(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureCallable', '*.txt');
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureCallable', '*.txt');
}

/**
* @dataProvider provideDataEmpty()
*/
#[DataProvider('provideDataEmpty')]
public function testEmpty(string $filePath): void
{
$fileContents = FileSystem::read($filePath);
Expand All @@ -49,9 +46,9 @@ public function testEmpty(string $filePath): void
$this->assertEmpty($this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo));
}

public function provideDataEmpty(): Iterator
public static function provideDataEmpty(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureEmpty', '*.txt');
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureEmpty', '*.txt');
}

private function doComparePrintedFileEquals(string $inputFilePath, string $expectedFilePath): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace Rector\Tests\BetterPhpDocParser\PhpDocInlineHtml;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class TestInlineHtmlTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
Expand All @@ -20,9 +19,9 @@ public function test(string $filePath): void
/**
* @return Iterator<array<string>>
*/
public function provideData(): Iterator
public static function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Iterator;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocParser\ClassAnnotationMatcher;
use Rector\Core\Exception\ShouldNotHappenException;
Expand Down Expand Up @@ -39,9 +40,7 @@ protected function setUp(): void
$this->nodeNameResolver = $this->getService(NodeNameResolver::class);
}

/**
* @dataProvider provideData()
*/
#[DataProvider('provideData')]
public function testResolvesClass(string $filePath): void
{
$nodes = $this->testingParser->parseFileToDecoratedNodes($filePath);
Expand Down Expand Up @@ -71,7 +70,7 @@ public function testResolvesClass(string $filePath): void
}
}

public function provideData(): Iterator
public static function provideData(): Iterator
{
return FixtureFileFinder::yieldDirectory(__DIR__ . '/Fixture');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Iterator;
use PhpParser\Node\Scalar\String_;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser;
Expand All @@ -26,10 +27,9 @@ protected function setUp(): void
}

/**
* @dataProvider provideData()
*
* @param ArrayItemNode[] $expectedArrayItemNodes
*/
#[DataProvider('provideData')]
public function test(string $docContent, array $expectedArrayItemNodes): void
{
$betterTokenIterator = $this->tokenIteratorFactory->create($docContent);
Expand All @@ -38,7 +38,7 @@ public function test(string $docContent, array $expectedArrayItemNodes): void
$this->assertEquals($expectedArrayItemNodes, $arrayItemNodes);
}

public function provideData(): Iterator
public static function provideData(): Iterator
{
yield ['{key: "value"}', [new ArrayItemNode('value', 'key', String_::KIND_DOUBLE_QUOTED)]];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Iterator;
use PhpParser\Node\Scalar\String_;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
Expand All @@ -27,9 +28,9 @@ protected function setUp(): void
}

/**
* @dataProvider provideData()
* @param CurlyListNode|array<string, CurlyListNode> $expectedValue
*/
#[DataProvider('provideData')]
public function test(string $docContent, CurlyListNode | array $expectedValue): void
{
$betterTokenIterator = $this->tokenIteratorFactory->create($docContent);
Expand All @@ -40,7 +41,7 @@ public function test(string $docContent, CurlyListNode | array $expectedValue):
$this->assertEquals($expectedValue, $value);
}

public function provideData(): Iterator
public static function provideData(): Iterator
{
$curlyListNode = new CurlyListNode([
new ArrayItemNode('chalet', null, String_::KIND_DOUBLE_QUOTED),
Expand Down
Loading

0 comments on commit c3ff0fd

Please sign in to comment.