Merge pull request #3235 from rectorphp/validate-phpinc

[DX] Add validate fixture suffix
This commit is contained in:
Tomas Votruba 2020-04-23 21:42:13 +02:00 committed by GitHub
commit 2ae793aa70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 87 additions and 6 deletions

View File

@ -18,3 +18,4 @@ jobs:
- run: composer install --no-progress - run: composer install --no-progress
- run: bin/rector validate-fixtures --ansi - run: bin/rector validate-fixtures --ansi
- run: bin/rector validate-fixture-suffix --ansi

View File

@ -23,7 +23,7 @@ final class PhpDocInfoPrinterTest extends AbstractPhpDocInfoPrinterTest
{ {
$this->doComparePrintedFileEquals( $this->doComparePrintedFileEquals(
__DIR__ . '/FixtureChanged/with_space.txt', __DIR__ . '/FixtureChanged/with_space.txt',
__DIR__ . '/FixtureChanged/with_space_expected.txt.inc' __DIR__ . '/FixtureChangedExpected/with_space_expected.txt'
); );
} }

View File

@ -20,7 +20,7 @@ class SetController extends \AppController
{ {
public function index() public function index()
{ {
return $this->render('homepage/index.twig', ['name' => 5]); return $this->render('set/index.twig', ['name' => 5]);
} }
} }

View File

@ -24,7 +24,7 @@ final class CakePHPModelToDoctrineRepositoryRectorTest extends AbstractRectorTes
public function provideData(): Iterator public function provideData(): Iterator
{ {
yield [ yield [
__DIR__ . '/Fixture/find_first.inc', __DIR__ . '/Fixture/find_first.php.inc',
$this->getTempPath() . '/FindFirstRepository.php', $this->getTempPath() . '/FindFirstRepository.php',
__DIR__ . '/Source/ExpectedFindFirstRepository.php', __DIR__ . '/Source/ExpectedFindFirstRepository.php',
]; ];

View File

@ -2,7 +2,7 @@
namespace Rector\CodeQuality\Tests\Rector\FuncCall\AddPregQuoteDelimiterRector\Fixture; namespace Rector\CodeQuality\Tests\Rector\FuncCall\AddPregQuoteDelimiterRector\Fixture;
class SomeClass class UnknownDelimiter
{ {
public function test() public function test()
{ {
@ -12,5 +12,3 @@ class SomeClass
$pattern4 = '#' . preg_quote('name') . '/'; $pattern4 = '#' . preg_quote('name') . '/';
} }
} }
?>

View File

@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Rector\Utils\ProjectValidator\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\PackageBuilder\Console\ShellCode;
use Symplify\SmartFileSystem\Finder\FinderSanitizer;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ValidateFixtureSuffixCommand extends Command
{
/**
* @var FinderSanitizer
*/
private $finderSanitizer;
/**
* @var SymfonyStyle
*/
private $symfonyStyle;
public function __construct(FinderSanitizer $finderSanitizer, SymfonyStyle $symfonyStyle)
{
$this->finderSanitizer = $finderSanitizer;
$this->symfonyStyle = $symfonyStyle;
parent::__construct();
}
protected function configure(): void
{
$this->setName(CommandNaming::classToName(self::class));
$this->setDescription('[CI] Validate tests fixtures suffix');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$hasError = false;
foreach ($this->getInvalidFixtureFileInfos() as $fixtureFileInfo) {
// files content is equal, but it should not
$message = sprintf(
'The "%s" file has invalid suffix. Should be *.php.inc',
$fixtureFileInfo->getRelativeFilePathFromCwd()
);
$this->symfonyStyle->error($message);
$hasError = true;
}
if ($hasError) {
return ShellCode::ERROR;
}
$this->symfonyStyle->success('All fixtures are correct');
return ShellCode::SUCCESS;
}
/**
* @return SmartFileInfo[]
*/
private function getInvalidFixtureFileInfos(): array
{
$finder = (new Finder())
->files()
->name('*.inc')
->notName('*.php.inc')
->in(__DIR__ . '/../../../../tests')
->in(__DIR__ . '/../../../../packages/*/tests')
->in(__DIR__ . '/../../../../rules/*/tests');
return $this->finderSanitizer->sanitize($finder);
}
}