|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Tests\FileSystem; |
| 6 | + |
| 7 | +use App\FileSystem\RectorFinder; |
| 8 | +use App\Sets\RectorSetsTreeProvider; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Rector\Php84\Rector\Class_\DeprecatedAnnotationToDeprecatedAttributeRector; |
| 11 | + |
| 12 | +final class RectorFinderTest extends TestCase |
| 13 | +{ |
| 14 | + private RectorFinder $rectorFinder; |
| 15 | + |
| 16 | + protected function setUp(): void |
| 17 | + { |
| 18 | + $this->rectorFinder = new RectorFinder(new RectorSetsTreeProvider()); |
| 19 | + } |
| 20 | + |
| 21 | + public function testFindDuplicated(): void |
| 22 | + { |
| 23 | + $foundRectors = $this->rectorFinder->find(); |
| 24 | + |
| 25 | + $shortNames = []; |
| 26 | + $longNames = []; |
| 27 | + foreach ($foundRectors as $ruleMetadata) { |
| 28 | + $shortNames[] = $ruleMetadata->getRuleShortClass(); |
| 29 | + $longNames[] = $ruleMetadata->getRectorClass(); |
| 30 | + } |
| 31 | + |
| 32 | + $uniqueShortNames = array_unique($shortNames); |
| 33 | + $uniqueLongNames = array_unique($longNames); |
| 34 | + |
| 35 | + $this->assertNotSame( |
| 36 | + count($uniqueShortNames), |
| 37 | + count($uniqueLongNames), |
| 38 | + 'There are duplicated short class names.' |
| 39 | + ); |
| 40 | + |
| 41 | + // get duplicated short names and report different slug |
| 42 | + $duplicatedShortNames = array_diff_key($shortNames, $uniqueShortNames); |
| 43 | + |
| 44 | + $this->assertContains( |
| 45 | + 'DeprecatedAnnotationToDeprecatedAttributeRector', |
| 46 | + $duplicatedShortNames, |
| 47 | + 'Expected DeprecatedAnnotationToDeprecatedAttributeRector to be one of the duplicated short names.' |
| 48 | + ); |
| 49 | + |
| 50 | + foreach ($foundRectors as $foundRector) { |
| 51 | + if ($foundRector->getRectorClass() === DeprecatedAnnotationToDeprecatedAttributeRector::class) { |
| 52 | + $this->assertSame( |
| 53 | + 'php-php-84-deprecated-annotation-to-deprecated-attribute-rector', |
| 54 | + $foundRector->getSlug() |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + if ($foundRector->getRectorClass() === \Rector\Php85\Rector\Const_\DeprecatedAnnotationToDeprecatedAttributeRector::class) { |
| 59 | + $this->assertSame( |
| 60 | + 'php-php-85-deprecated-annotation-to-deprecated-attribute-rector', |
| 61 | + $foundRector->getSlug() |
| 62 | + ); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments