mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 04:19:44 +01:00
remove tests directory, should not be here
This commit is contained in:
parent
f5d3f0d130
commit
3bacb2941f
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Application\ApplicationFileProcessor;
|
||||
|
||||
use Rector\Core\Application\ApplicationFileProcessor;
|
||||
use Rector\Core\Configuration\Configuration;
|
||||
use Rector\Core\ValueObjectFactory\Application\FileFactory;
|
||||
use Rector\Core\ValueObjectFactory\ProcessResultFactory;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ApplicationFileProcessorTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var ApplicationFileProcessor
|
||||
*/
|
||||
private $applicationFileProcessor;
|
||||
|
||||
/**
|
||||
* @var FileFactory
|
||||
*/
|
||||
private $fileFactory;
|
||||
|
||||
/**
|
||||
* @var ProcessResultFactory
|
||||
*/
|
||||
private $processResultFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->bootFromConfigFileInfos([new SmartFileInfo(__DIR__ . '/config/configured_rule.php')]);
|
||||
|
||||
/** @var Configuration $configuration */
|
||||
$configuration = $this->getService(Configuration::class);
|
||||
$configuration->setIsDryRun(true);
|
||||
|
||||
$this->applicationFileProcessor = $this->getService(ApplicationFileProcessor::class);
|
||||
$this->fileFactory = $this->getService(FileFactory::class);
|
||||
$this->processResultFactory = $this->getService(ProcessResultFactory::class);
|
||||
}
|
||||
|
||||
public function test(): void
|
||||
{
|
||||
$files = $this->fileFactory->createFromPaths([__DIR__ . '/Fixture']);
|
||||
$this->assertCount(2, $files);
|
||||
|
||||
$this->applicationFileProcessor->run($files);
|
||||
|
||||
$processResult = $this->processResultFactory->create($files);
|
||||
$this->assertCount(1, $processResult->getFileDiffs());
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
Bar
|
@ -1 +0,0 @@
|
||||
Foo
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Application\ApplicationFileProcessor\Source\Contract;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
|
||||
interface TextRectorInterface extends RectorInterface
|
||||
{
|
||||
public function refactorContent(string $content): string;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Application\ApplicationFileProcessor\Source\Rector;
|
||||
|
||||
use Rector\Core\Tests\Application\ApplicationFileProcessor\Source\Contract\TextRectorInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class ChangeTextRector implements TextRectorInterface
|
||||
{
|
||||
public function refactorContent(string $content): string
|
||||
{
|
||||
return str_replace('Foo', 'Bar', $content);
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
// just for docs
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Application\ApplicationFileProcessor\Source;
|
||||
|
||||
use Rector\Core\Contract\Processor\FileProcessorInterface;
|
||||
use Rector\Core\Tests\Application\ApplicationFileProcessor\Source\Contract\TextRectorInterface;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
|
||||
final class TextFileProcessor implements FileProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @var TextRectorInterface[]
|
||||
*/
|
||||
private $textRectors;
|
||||
|
||||
/**
|
||||
* @param TextRectorInterface[] $textRectors
|
||||
*/
|
||||
public function __construct(array $textRectors)
|
||||
{
|
||||
$this->textRectors = $textRectors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param File[] $files
|
||||
*/
|
||||
public function process(array $files): void
|
||||
{
|
||||
foreach ($files as $file) {
|
||||
$fileContent = $file->getFileContent();
|
||||
|
||||
foreach ($this->textRectors as $textRector) {
|
||||
$fileContent = $textRector->refactorContent($fileContent);
|
||||
}
|
||||
|
||||
$file->changeFileContent($fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
public function supports(File $file): bool
|
||||
{
|
||||
$smartFileInfo = $file->getSmartFileInfo();
|
||||
return $smartFileInfo->hasSuffixes($this->getSupportedFileExtensions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedFileExtensions(): array
|
||||
{
|
||||
return ['txt'];
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Tests\Application\ApplicationFileProcessor\Source\Rector\ChangeTextRector;
|
||||
use Rector\Core\Tests\Application\ApplicationFileProcessor\Source\TextFileProcessor;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(TextFileProcessor::class);
|
||||
|
||||
$services->set(ChangeTextRector::class);
|
||||
};
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\DependencyInjection;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Bootstrap\RectorConfigsResolver;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ConfigurableRectorImportConfigCallsMergeTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @var PrivatesAccessor
|
||||
*/
|
||||
private $privatesAccessor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->privatesAccessor = new PrivatesAccessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
* @param array<string, string> $expectedConfiguration
|
||||
*/
|
||||
public function testMainConfigValues(string $config, array $expectedConfiguration): void
|
||||
{
|
||||
$rectorConfigsResolver = new RectorConfigsResolver();
|
||||
|
||||
$configFileInfos = $rectorConfigsResolver->resolveFromConfigFileInfo(new SmartFileInfo($config));
|
||||
$this->bootFromConfigFileInfos($configFileInfos);
|
||||
|
||||
$renameClassRector = $this->getService(RenameClassRector::class);
|
||||
$oldToNewClasses = $this->privatesAccessor->getPrivateProperty($renameClassRector, 'oldToNewClasses');
|
||||
|
||||
$this->assertSame($expectedConfiguration, $oldToNewClasses);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [
|
||||
__DIR__ . '/config/main_config_with_only_imports.php', [
|
||||
'old_2' => 'new_2',
|
||||
'old_1' => 'new_1',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/config/main_config_with_override_value.php', [
|
||||
'old_2' => 'new_2',
|
||||
'old_1' => 'new_1',
|
||||
'old_4' => 'new_4',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/config/main_config_with_own_value.php', [
|
||||
'old_2' => 'new_2',
|
||||
'old_1' => 'new_1',
|
||||
'old_4' => 'new_4',
|
||||
'old_3' => 'new_3',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/config/one_set.php', [
|
||||
'PHPUnit_Framework_MockObject_Stub' => 'PHPUnit\Framework\MockObject\Stub',
|
||||
'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Parameters' => 'PHPUnit\Framework\MockObject\Matcher\Parameters',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Invocation' => 'PHPUnit\Framework\MockObject\Matcher\Invocation',
|
||||
'PHPUnit_Framework_MockObject_MockObject' => 'PHPUnit\Framework\MockObject\MockObject',
|
||||
'PHPUnit_Framework_MockObject_Invocation_Object' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/config/one_set_with_own_rename.php', [
|
||||
'Old' => 'New',
|
||||
'PHPUnit_Framework_MockObject_Stub' => 'PHPUnit\Framework\MockObject\Stub',
|
||||
'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Parameters' => 'PHPUnit\Framework\MockObject\Matcher\Parameters',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Invocation' => 'PHPUnit\Framework\MockObject\Matcher\Invocation',
|
||||
'PHPUnit_Framework_MockObject_MockObject' => 'PHPUnit\Framework\MockObject\MockObject',
|
||||
'PHPUnit_Framework_MockObject_Invocation_Object' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/config/two_sets.php', [
|
||||
'Twig_SimpleFilter' => 'Twig_Filter',
|
||||
'Twig_SimpleFunction' => 'Twig_Function',
|
||||
'Twig_SimpleTest' => 'Twig_Test',
|
||||
'PHPUnit_Framework_MockObject_Stub' => 'PHPUnit\Framework\MockObject\Stub',
|
||||
'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Parameters' => 'PHPUnit\Framework\MockObject\Matcher\Parameters',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Invocation' => 'PHPUnit\Framework\MockObject\Matcher\Invocation',
|
||||
'PHPUnit_Framework_MockObject_MockObject' => 'PHPUnit\Framework\MockObject\MockObject',
|
||||
'PHPUnit_Framework_MockObject_Invocation_Object' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation',
|
||||
],
|
||||
];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/config/two_sets_with_own_rename.php', [
|
||||
'Old' => 'New',
|
||||
'Twig_SimpleFilter' => 'Twig_Filter',
|
||||
'Twig_SimpleFunction' => 'Twig_Function',
|
||||
'Twig_SimpleTest' => 'Twig_Test',
|
||||
'PHPUnit_Framework_MockObject_Stub' => 'PHPUnit\Framework\MockObject\Stub',
|
||||
'PHPUnit_Framework_MockObject_Stub_Return' => 'PHPUnit\Framework\MockObject\Stub\ReturnStub',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Parameters' => 'PHPUnit\Framework\MockObject\Matcher\Parameters',
|
||||
'PHPUnit_Framework_MockObject_Matcher_Invocation' => 'PHPUnit\Framework\MockObject\Matcher\Invocation',
|
||||
'PHPUnit_Framework_MockObject_MockObject' => 'PHPUnit\Framework\MockObject\MockObject',
|
||||
'PHPUnit_Framework_MockObject_Invocation_Object' => 'PHPUnit\Framework\MockObject\Invocation\ObjectInvocation',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'old_1' => 'new_1',
|
||||
],
|
||||
]]);
|
||||
};
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class);
|
||||
|
||||
$containerConfigurator->import(__DIR__ . '/first_config.php');
|
||||
$containerConfigurator->import(__DIR__ . '/second_config.php');
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'old_2' => 'new_2',
|
||||
],
|
||||
]])
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'old_4' => 'new_4',
|
||||
],
|
||||
]]);
|
||||
|
||||
$containerConfigurator->import(__DIR__ . '/first_config.php');
|
||||
$containerConfigurator->import(__DIR__ . '/second_config.php');
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'old_3' => 'new_3',
|
||||
],
|
||||
]])
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'old_4' => 'new_4',
|
||||
],
|
||||
]]);
|
||||
|
||||
$containerConfigurator->import(__DIR__ . '/first_config.php');
|
||||
$containerConfigurator->import(__DIR__ . '/second_config.php');
|
||||
};
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\PHPUnit\Set\PHPUnitSetList;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_60);
|
||||
};
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\PHPUnit\Set\PHPUnitSetList;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_60);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'Old' => 'New',
|
||||
],
|
||||
]]);
|
||||
};
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'old_2' => 'new_2',
|
||||
],
|
||||
],
|
||||
]);
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\PHPUnit\Set\PHPUnitSetList;
|
||||
use Rector\Symfony\Set\TwigSetList;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_60);
|
||||
$containerConfigurator->import(TwigSetList::TWIG_20);
|
||||
};
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\PHPUnit\Set\PHPUnitSetList;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Rector\Symfony\Set\TwigSetList;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_60);
|
||||
$containerConfigurator->import(TwigSetList::TWIG_20);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'Old' => 'New',
|
||||
],
|
||||
]]);
|
||||
};
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
/**
|
||||
* @see \Rector\Core\Exclusion\ExclusionManager
|
||||
*/
|
||||
final class ExclusionManagerTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/some_config.php';
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Fixture;
|
||||
|
||||
final class DifferentNorector
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
/**
|
||||
* @noRector \Rector\Core\Tests\Exclusion\Source\SomeRector
|
||||
*/
|
||||
round(1 + 0);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Fixture;
|
||||
|
||||
final class DifferentNorector
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
/**
|
||||
* @noRector \Rector\Core\Tests\Exclusion\Source\SomeRector
|
||||
*/
|
||||
round(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Fixture;
|
||||
|
||||
final class SkipCommentWithSpaces
|
||||
{
|
||||
/**
|
||||
* @noRector some comment
|
||||
*/
|
||||
public function foo()
|
||||
{
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Fixture;
|
||||
|
||||
final class SkipDocblockOnParentNorector
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
/** @noRector \Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector */
|
||||
round(1 + 0);
|
||||
|
||||
/** @noRector Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector */
|
||||
round(2 + 0);
|
||||
|
||||
/** @noRector \Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector */
|
||||
round(round(3 + 0));
|
||||
|
||||
round(/** @noRector \Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector */ 4 + 0);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Fixture;
|
||||
|
||||
final class SkipDocblockOnSelfNoRector
|
||||
{
|
||||
/**
|
||||
* @noRector \Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector
|
||||
*/
|
||||
public function bar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** @noRector \Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector */
|
||||
public function baz()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Fixture;
|
||||
|
||||
final class SkipOtherDocblocks
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
/**
|
||||
* @noRector \Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector
|
||||
* @noRector \Rector\DeadCode\Rector\Plus\AnotherRector
|
||||
*/
|
||||
round(1 + 0);
|
||||
|
||||
/** @noRector */
|
||||
round(2 + 0);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Exclusion\Source;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class SomeRector implements RectorInterface
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('...' , []);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
|
||||
use Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(RemoveEmptyClassMethodRector::class);
|
||||
$services->set(RemoveDeadZeroAndOneOperationRector::class);
|
||||
};
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\FileSystem\FilesFinder\ExcludePaths;
|
||||
|
||||
use Rector\Core\FileSystem\FilesFinder;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ExcludePathsTest extends AbstractTestCase
|
||||
{
|
||||
public function testShouldFail(): void
|
||||
{
|
||||
$this->bootFromConfigFileInfos([new SmartFileInfo(__DIR__ . '/config/config-with-excluded-paths.php')]);
|
||||
|
||||
$filesFinder = $this->getService(FilesFinder::class);
|
||||
|
||||
$foundFileInfos = $filesFinder->findInDirectoriesAndFiles([__DIR__ . '/Source'], ['php']);
|
||||
$this->assertCount(1, $foundFileInfos);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\FileSystem\FilesFinder\ExcludePaths\Source\ShouldBeExcluded;
|
||||
|
||||
final class FileWithMissingClass extends ThisClassIsNotHere
|
||||
{
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\FileSystem\FilesFinder\ExcludePaths\Source;
|
||||
|
||||
final class ThisShouldBeHere
|
||||
{
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::SKIP, ['*/ShouldBeExcluded/*']);
|
||||
};
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\FileSystem\FilesFinder;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\FileSystem\FilesFinder;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class FilesFinderTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var FilesFinder
|
||||
*/
|
||||
private $filesFinder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->filesFinder = $this->getService(FilesFinder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function testSingleSuffix(string $suffix, int $count, string $expectedFileName): void
|
||||
{
|
||||
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/Source'], [$suffix]);
|
||||
$this->assertCount($count, $foundFiles);
|
||||
|
||||
/** @var SmartFileInfo $foundFile */
|
||||
$foundFile = array_pop($foundFiles);
|
||||
$this->assertSame($expectedFileName, $foundFile->getBasename());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<array<string|int>>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield ['php', 1, 'SomeFile.php'];
|
||||
yield ['yml', 1, 'some_config.yml'];
|
||||
yield ['yaml', 1, 'other_config.yaml'];
|
||||
yield ['php', 1, 'SomeFile.php'];
|
||||
}
|
||||
|
||||
public function testMultipleSuffixes(): void
|
||||
{
|
||||
$foundFiles = $this->filesFinder->findInDirectoriesAndFiles([__DIR__ . '/Source'], ['yaml', 'yml']);
|
||||
$this->assertCount(2, $foundFiles);
|
||||
|
||||
$foundFileNames = [];
|
||||
foreach ($foundFiles as $foundFile) {
|
||||
$foundFileNames[] = $foundFile->getFilename();
|
||||
}
|
||||
|
||||
$expectedFoundFileNames = ['some_config.yml', 'other_config.yaml'];
|
||||
|
||||
sort($foundFileNames);
|
||||
sort($expectedFoundFileNames);
|
||||
$this->assertSame($expectedFoundFileNames, $foundFileNames);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
echo 'Hi';
|
@ -1 +0,0 @@
|
||||
key: value
|
@ -1 +0,0 @@
|
||||
key: value
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Issues\CallableFixture;
|
||||
|
||||
final class StyleWithCallable implements InterfaceWithCallable
|
||||
{
|
||||
public function ask(?string $default = null, $validator = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
interface InterfaceWithCallable
|
||||
{
|
||||
public function ask(?string $default = null, callable $validator = null);
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Issues\CallableFixture;
|
||||
|
||||
final class StyleWithCallable implements InterfaceWithCallable
|
||||
{
|
||||
/**
|
||||
* @param string|null $default
|
||||
*/
|
||||
public function ask($default = null, $validator = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
interface InterfaceWithCallable
|
||||
{
|
||||
/**
|
||||
* @param callable|null $validator
|
||||
* @param string|null $default
|
||||
*/
|
||||
public function ask($default = null, $validator = null);
|
||||
}
|
||||
|
||||
?>
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class CallableInterfaceDowngradeTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/CallableFixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/callable_interface_downgrade.php';
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class CovariantTrioTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/covariant_trio.php';
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Fixture;
|
||||
|
||||
final class CoriantMixture
|
||||
{
|
||||
private function parseArgument(string $token, array $all)
|
||||
{
|
||||
if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Fixture;
|
||||
|
||||
final class CoriantMixture
|
||||
{
|
||||
/**
|
||||
* @param string $token
|
||||
*/
|
||||
private function parseArgument($token, array $all)
|
||||
{
|
||||
$token = (string) $token;
|
||||
reset($all);
|
||||
if (($inputArgument = isset($all[$key = key($all)]) ? $all[$key = key($all)] : null) && 'command' === $inputArgument->getName()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ArgvInput extends Input
|
||||
{
|
||||
/**
|
||||
* Parses an argument.
|
||||
*
|
||||
* @throws RuntimeException When too many arguments are given
|
||||
*/
|
||||
private function parseArgument(string $token, array $all)
|
||||
{
|
||||
if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasParameterOption($values, bool $onlyParams = false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Input implements InputInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class ArrayInput extends Input
|
||||
{
|
||||
public function hasParameterOption($values, bool $onlyParams = false)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface InputInterface
|
||||
{
|
||||
public function hasParameterOption($values, bool $onlyParams = false);
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
class ArgvInput extends Input
|
||||
{
|
||||
/**
|
||||
* Parses an argument.
|
||||
*
|
||||
* @throws RuntimeException When too many arguments are given
|
||||
* @param string $token
|
||||
*/
|
||||
private function parseArgument($token, array $all)
|
||||
{
|
||||
$token = (string) $token;
|
||||
reset($all);
|
||||
if (($inputArgument = isset($all[$key = key($all)]) ? $all[$key = key($all)] : null) && 'command' === $inputArgument->getName()) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param bool $onlyParams
|
||||
*/
|
||||
public function hasParameterOption($values, $onlyParams = false)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Input implements InputInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class ArrayInput extends Input
|
||||
{
|
||||
/**
|
||||
* @param bool $onlyParams
|
||||
*/
|
||||
public function hasParameterOption($values, $onlyParams = false)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface InputInterface
|
||||
{
|
||||
/**
|
||||
* @param bool $onlyParams
|
||||
*/
|
||||
public function hasParameterOption($values, $onlyParams = false);
|
||||
}
|
||||
|
||||
?>
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Set\ValueObject\DowngradeSetList;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->import(DowngradeSetList::PHP_71);
|
||||
$containerConfigurator->import(DowngradeSetList::PHP_72);
|
||||
$containerConfigurator->import(DowngradeSetList::PHP_73);
|
||||
$containerConfigurator->import(DowngradeSetList::PHP_74);
|
||||
$containerConfigurator->import(DowngradeSetList::PHP_80);
|
||||
};
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\DowngradePhp70\Rector\Coalesce\DowngradeNullCoalesceRector;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeScalarTypeDeclarationRector;
|
||||
use Rector\DowngradePhp73\Rector\FuncCall\DowngradeArrayKeyFirstLastRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_70);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeArrayKeyFirstLastRector::class);
|
||||
$services->set(DowngradeScalarTypeDeclarationRector::class);
|
||||
$services->set(DowngradeNullCoalesceRector::class);
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
<div>
|
||||
<?php
|
||||
if (Session::has('key')) {
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
-----
|
||||
<div>
|
||||
<?php
|
||||
if (Illuminate\Support\Facades\Session::has('key')) {
|
||||
}
|
||||
?>
|
||||
</div>
|
@ -1,17 +0,0 @@
|
||||
<div>
|
||||
<?php
|
||||
|
||||
if (Form::has('key')) {
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
-----
|
||||
<div>
|
||||
<?php
|
||||
|
||||
if (Collective\Html\FormFacade::has('key')) {
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
@ -1,3 +0,0 @@
|
||||
{if \Session::some()}
|
||||
-----
|
||||
{if \Illuminate\Support\Facades\Session::some()}
|
@ -1,8 +0,0 @@
|
||||
<div>
|
||||
<?php
|
||||
|
||||
if (\Illuminate\Support\Facades\Session::has('key')) {
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
@ -1,3 +0,0 @@
|
||||
'Session'
|
||||
|
||||
Session.some
|
@ -1,3 +0,0 @@
|
||||
<div>Session</div>
|
||||
|
||||
First Session
|
@ -1,4 +0,0 @@
|
||||
<div>
|
||||
<div id="Session"></div>
|
||||
<div id="someSessionModal"></div>
|
||||
</div>
|
@ -1,7 +0,0 @@
|
||||
services:
|
||||
-
|
||||
class: Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass
|
||||
-----
|
||||
services:
|
||||
-
|
||||
class: Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass
|
@ -1,7 +0,0 @@
|
||||
<services>
|
||||
<class name="Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass"/>
|
||||
</services>
|
||||
-----
|
||||
<services>
|
||||
<class name="Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass"/>
|
||||
</services>
|
@ -1,5 +0,0 @@
|
||||
services:
|
||||
Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass: null
|
||||
-----
|
||||
services:
|
||||
Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass: null
|
@ -1,5 +0,0 @@
|
||||
services:
|
||||
Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass: null
|
||||
-----
|
||||
services:
|
||||
Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass: null
|
@ -1,5 +0,0 @@
|
||||
{if \Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass::SOME_COSTANT === $value}
|
||||
{/if}
|
||||
-----
|
||||
{if \Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass::SOME_COSTANT === $value}
|
||||
{/if}
|
@ -1,3 +0,0 @@
|
||||
{{ constant('Rector\\Tests\\Renaming\\Rector\\Name\\RenameClassRector\\Source\\OldClass::SOME_COSTANT') }}
|
||||
-----
|
||||
{{ constant('Rector\\Tests\\Renaming\\Rector\\Name\\RenameClassRector\\Source\\NewClass::SOME_COSTANT') }}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\NonPhpFile\Rector\RenameClassNonPhpRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RenameClassNonPhpRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fixtureFileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fixtureFileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<array<int, SmartFileInfo>>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture', '*');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\NonPhpFile\Rector\RenameClassNonPhpRector;
|
||||
use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass;
|
||||
use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(RenameClassNonPhpRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassNonPhpRector::RENAME_CLASSES => [
|
||||
'Session' => 'Illuminate\Support\Facades\Session',
|
||||
OldClass::class => NewClass::class,
|
||||
// Laravel
|
||||
'Form' => 'Collective\Html\FormFacade',
|
||||
'Html' => 'Collective\Html\HtmlFacade',
|
||||
],
|
||||
],
|
||||
]);
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Php;
|
||||
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
|
||||
final class PhpVersionProviderTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var PhpVersionProvider
|
||||
*/
|
||||
private $phpVersionProvider;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->phpVersionProvider = $this->getService(PhpVersionProvider::class);
|
||||
}
|
||||
|
||||
public function test(): void
|
||||
{
|
||||
$phpVersion = $this->phpVersionProvider->provide();
|
||||
$this->assertSame(100000, $phpVersion);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"require": {
|
||||
"php": ">=7.3"
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"require": {
|
||||
"php": ">=7.3"
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "7.4"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Php\PhpVersionResolver\ProjectComposerJsonPhpVersionResolver;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Php\PhpVersionResolver\ProjectComposerJsonPhpVersionResolver;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
|
||||
final class ProjectComposerJsonPhpVersionResolverTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var ProjectComposerJsonPhpVersionResolver
|
||||
*/
|
||||
private $projectComposerJsonPhpVersionResolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->projectComposerJsonPhpVersionResolver = $this->getService(ProjectComposerJsonPhpVersionResolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $composerJsonFilePath, int $expectedPhpVersion): void
|
||||
{
|
||||
$resolvePhpVersion = $this->projectComposerJsonPhpVersionResolver->resolve($composerJsonFilePath);
|
||||
$this->assertSame($expectedPhpVersion, $resolvePhpVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<array<string|int>>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Fixture/some_composer.json', 70300];
|
||||
yield [__DIR__ . '/Fixture/some_composer_with_platform.json', 70400];
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Node\BetterNodeFinder;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Parser\SimplePhpParser;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
|
||||
final class BetterNodeFinderTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var Node[]
|
||||
*/
|
||||
private $nodes = [];
|
||||
|
||||
/**
|
||||
* @var BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
|
||||
$this->betterNodeFinder = $this->getService(BetterNodeFinder::class);
|
||||
|
||||
/** @var SimplePhpParser $simplePhpParser */
|
||||
$simplePhpParser = $this->getService(SimplePhpParser::class);
|
||||
$this->nodes = $simplePhpParser->parseFile(__DIR__ . '/Source/SomeFile.php.inc');
|
||||
}
|
||||
|
||||
public function testFindFirstAncestorInstanceOf(): void
|
||||
{
|
||||
$variable = $this->betterNodeFinder->findFirstInstanceOf($this->nodes, Variable::class);
|
||||
$class = $this->betterNodeFinder->findFirstInstanceOf($this->nodes, Class_::class);
|
||||
|
||||
$this->assertNotNull($variable);
|
||||
$this->assertNotNull($class);
|
||||
|
||||
$this->assertInstanceOf(Variable::class, $variable);
|
||||
$this->assertInstanceOf(Class_::class, $class);
|
||||
|
||||
/** @var Variable $variable */
|
||||
$classLikeNode = $this->betterNodeFinder->findParentType($variable, ClassLike::class);
|
||||
$this->assertSame($classLikeNode, $class);
|
||||
}
|
||||
|
||||
public function testFindMissingFirstAncestorInstanceOf(): void
|
||||
{
|
||||
/** @var Variable $variableNode */
|
||||
$variableNode = $this->betterNodeFinder->findFirstInstanceOf($this->nodes, Variable::class);
|
||||
|
||||
$this->assertNull($this->betterNodeFinder->findParentType($variableNode, Array_::class));
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function someAction()
|
||||
{
|
||||
$variable = 5;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Node;
|
||||
|
||||
use Iterator;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
|
||||
final class NodeFactoryTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
|
||||
$this->nodeFactory = $this->getService(NodeFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[]|array<string, int> $inputArray
|
||||
* @dataProvider provideDataForArray()
|
||||
*/
|
||||
public function testCreateArray(array $inputArray, Array_ $expectedArrayNode): void
|
||||
{
|
||||
$arrayNode = $this->nodeFactory->createArray($inputArray);
|
||||
|
||||
$this->assertEquals($expectedArrayNode, $arrayNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<int[][]|array<string, int>|Array_[]>
|
||||
*/
|
||||
public function provideDataForArray(): Iterator
|
||||
{
|
||||
$array = new Array_();
|
||||
$array->items[] = new ArrayItem(new LNumber(1));
|
||||
|
||||
yield [[1], $array];
|
||||
|
||||
$array = new Array_();
|
||||
$array->items[] = new ArrayItem(new LNumber(1), new String_('a'));
|
||||
|
||||
yield [[
|
||||
'a' => 1,
|
||||
], $array];
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Node\Value;
|
||||
|
||||
use Iterator;
|
||||
use PhpParser\BuilderFactory;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\BinaryOp\Plus;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
|
||||
final class ValueResolverTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var ValueResolver
|
||||
*/
|
||||
private $valueResolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->valueResolver = $this->getService(ValueResolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $expectedValue
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function test(Expr $expr, $expectedValue): void
|
||||
{
|
||||
$resolvedValue = $this->valueResolver->getValue($expr);
|
||||
$this->assertSame($expectedValue, $resolvedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<array<Expr|mixed>>
|
||||
*/
|
||||
public function dataProvider(): Iterator
|
||||
{
|
||||
$builderFactory = new BuilderFactory();
|
||||
|
||||
$classConstFetchNode = $builderFactory->classConstFetch('SomeClass', 'SOME_CONSTANT');
|
||||
$classConstFetchNode->class->setAttribute(
|
||||
AttributeKey::RESOLVED_NAME,
|
||||
new FullyQualified('SomeClassResolveName')
|
||||
);
|
||||
|
||||
yield [$classConstFetchNode, 'SomeClassResolveName::SOME_CONSTANT'];
|
||||
yield [$builderFactory->val(true), true];
|
||||
yield [$builderFactory->val(1), 1];
|
||||
yield [$builderFactory->val(1.0), 1.0];
|
||||
yield [$builderFactory->var('foo'), null];
|
||||
yield [new Plus($builderFactory->val(1), $builderFactory->val(1)), 2];
|
||||
yield [new Plus($builderFactory->val(1), $builderFactory->var('foo')), null];
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer;
|
||||
|
||||
use Iterator;
|
||||
use PhpParser\Comment;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Expr\Yield_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
use Symplify\Astral\ValueObject\NodeBuilder\MethodBuilder;
|
||||
|
||||
final class BetterStandardPrinterTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var BetterStandardPrinter
|
||||
*/
|
||||
private $betterStandardPrinter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->betterStandardPrinter = $this->getService(BetterStandardPrinter::class);
|
||||
}
|
||||
|
||||
public function testAddingCommentOnSomeNodesFail(): void
|
||||
{
|
||||
$methodCall = new MethodCall(new Variable('this'), 'run');
|
||||
|
||||
// cannot be on MethodCall, must be Expression
|
||||
$methodCallExpression = new Expression($methodCall);
|
||||
$methodCallExpression->setAttribute(AttributeKey::COMMENTS, [new Comment('// todo: fix')]);
|
||||
|
||||
$methodBuilder = new MethodBuilder('run');
|
||||
$methodBuilder->addStmt($methodCallExpression);
|
||||
|
||||
$classMethod = $methodBuilder->getNode();
|
||||
|
||||
$printed = $this->betterStandardPrinter->print($classMethod) . PHP_EOL;
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__ . '/Source/expected_code_with_non_stmt_placed_nested_comment.php.inc',
|
||||
$printed
|
||||
);
|
||||
}
|
||||
|
||||
public function testStringWithAddedComment(): void
|
||||
{
|
||||
$string = new String_('hey');
|
||||
$string->setAttribute(AttributeKey::COMMENTS, [new Comment('// todo: fix')]);
|
||||
|
||||
$printed = $this->betterStandardPrinter->print($string) . PHP_EOL;
|
||||
$this->assertStringEqualsFile(__DIR__ . '/Source/expected_code_with_comment.php.inc', $printed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataForDoubleSlashEscaping()
|
||||
*/
|
||||
public function testDoubleSlashEscaping(string $content, string $expectedOutput): void
|
||||
{
|
||||
$printed = $this->betterStandardPrinter->print(new String_($content));
|
||||
$this->assertSame($expectedOutput, $printed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<string[]>
|
||||
*/
|
||||
public function provideDataForDoubleSlashEscaping(): Iterator
|
||||
{
|
||||
yield ['Vendor\Name', "'Vendor\Name'"];
|
||||
yield ['Vendor\\', "'Vendor\\\\'"];
|
||||
yield ["Vendor'Name", "'Vendor\'Name'"];
|
||||
}
|
||||
|
||||
public function testYield(): void
|
||||
{
|
||||
$yield = new Yield_(new String_('value'));
|
||||
|
||||
$printed = $this->betterStandardPrinter->print($yield);
|
||||
$this->assertSame("(yield 'value')", $printed);
|
||||
|
||||
$printed = $this->betterStandardPrinter->print(new Yield_());
|
||||
$this->assertSame('yield', $printed);
|
||||
|
||||
$expression = new Expression($yield);
|
||||
$yield->setAttribute(AttributeKey::PARENT_NODE, $expression);
|
||||
$printed = $this->betterStandardPrinter->print($expression);
|
||||
$this->assertSame("yield 'value';", $printed);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class CommentPreservingTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Fixture;
|
||||
|
||||
use Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Source\LocalEventDispatcher;
|
||||
|
||||
/**
|
||||
* This docblock is being deleted when there's an empty docblock after it.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Another dockblock.
|
||||
*
|
||||
*
|
||||
* first_function()
|
||||
*
|
||||
*
|
||||
* second_function()
|
||||
* third_function()
|
||||
* fourth_function()
|
||||
*/
|
||||
|
||||
final class CommentsForTypedProperty
|
||||
{
|
||||
private $eventDispatcher;
|
||||
|
||||
public function __construct(LocalEventDispatcher $eventDispatcher)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Fixture;
|
||||
|
||||
use Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Source\LocalEventDispatcher;
|
||||
|
||||
/**
|
||||
* This docblock is being deleted when there's an empty docblock after it.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Another dockblock.
|
||||
*
|
||||
*
|
||||
* first_function()
|
||||
*
|
||||
*
|
||||
* second_function()
|
||||
* third_function()
|
||||
* fourth_function()
|
||||
*/
|
||||
|
||||
final class CommentsForTypedProperty
|
||||
{
|
||||
private \Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Source\LocalEventDispatcher $eventDispatcher;
|
||||
|
||||
public function __construct(LocalEventDispatcher $eventDispatcher)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Fixture;
|
||||
|
||||
class KeepComment
|
||||
{
|
||||
public function foo($foo)
|
||||
{
|
||||
//thiscommentshouldnotberemoved
|
||||
return $foo;
|
||||
}
|
||||
|
||||
public function bar($bar)
|
||||
{
|
||||
// @var string $bar['should_not_be_changed]
|
||||
|
||||
return $bar['should_not_be_changed'];
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Fixture;
|
||||
|
||||
class KeepDoubleComments
|
||||
{
|
||||
/*****************************************
|
||||
* should not be removed
|
||||
****************************************/
|
||||
/**
|
||||
* Some multi line
|
||||
* dock block
|
||||
*/
|
||||
public function bizz()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Fixture;
|
||||
|
||||
class KeepMultilineSingleAsterisk
|
||||
{
|
||||
public function baz($baz)
|
||||
{
|
||||
/*
|
||||
should
|
||||
not
|
||||
be changed
|
||||
*/
|
||||
|
||||
return $baz;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer\CommentPreserving\Source;
|
||||
|
||||
final class LocalEventDispatcher
|
||||
{
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(TypedPropertyRector::class);
|
||||
};
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\PhpParser\Printer;
|
||||
|
||||
use Rector\Core\PhpParser\Printer\FormatPerservingPrinter;
|
||||
use Rector\Testing\PHPUnit\AbstractTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
final class FormatPerservingPrinterTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private const EXPECTED_FILEMOD = 0755;
|
||||
|
||||
/**
|
||||
* @var FormatPerservingPrinter
|
||||
*/
|
||||
private $formatPerservingPrinter;
|
||||
|
||||
/**
|
||||
* @var SmartFileSystem
|
||||
*/
|
||||
private $smartFileSystem;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->boot();
|
||||
$this->formatPerservingPrinter = $this->getService(FormatPerservingPrinter::class);
|
||||
$this->smartFileSystem = $this->getService(SmartFileSystem::class);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->smartFileSystem->remove(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function testFileModeIsPreserved(): void
|
||||
{
|
||||
mkdir(__DIR__ . '/Fixture');
|
||||
touch(__DIR__ . '/Fixture/file.php');
|
||||
|
||||
chmod(__DIR__ . '/Fixture/file.php', self::EXPECTED_FILEMOD);
|
||||
|
||||
$fileInfo = new SmartFileInfo(__DIR__ . '/Fixture/file.php');
|
||||
$this->formatPerservingPrinter->printToFile($fileInfo, [], [], []);
|
||||
|
||||
$this->assertSame(self::EXPECTED_FILEMOD, fileperms(__DIR__ . '/Fixture/file.php') & 0777);
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
// todo: fix
|
||||
'hey'
|
@ -1,5 +0,0 @@
|
||||
function run()
|
||||
{
|
||||
// todo: fix
|
||||
$this->run();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Stubs\PHPStanStubLoader;
|
||||
|
||||
require_once __DIR__ . '/../src/constants.php';
|
||||
|
||||
// make local php-parser a priority to avoid conflict
|
||||
require_once __DIR__ . '/../preload.php';
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// silent deprecations, since we test them
|
||||
error_reporting(E_ALL ^ E_DEPRECATED);
|
||||
|
||||
// performance boost
|
||||
gc_disable();
|
||||
|
||||
$phpStanStubLoader = new PHPStanStubLoader();
|
||||
$phpStanStubLoader->loadStubs();
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* @param Node|Node[] $node
|
||||
*/
|
||||
function print_node($node): void
|
||||
{
|
||||
$standard = new Standard();
|
||||
|
||||
if (is_array($node)) {
|
||||
foreach ($node as $singleNode) {
|
||||
$printedContent = $standard->prettyPrint([$singleNode]);
|
||||
dump($printedContent);
|
||||
}
|
||||
} else {
|
||||
$printedContent = $standard->prettyPrint([$node]);
|
||||
dump($printedContent);
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\RectorPrefixed\Tests;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipSomeEntity
|
||||
{
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\RectorPrefixed\Tests;
|
||||
|
||||
class SomeClassWithoutChildren
|
||||
{
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class SomeController
|
||||
{
|
||||
/**
|
||||
* @Route()
|
||||
*/
|
||||
public function someMethod()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user