Skip to content

Commit

Permalink
[Testing] Make use of config new Community config-based test case (#1962
Browse files Browse the repository at this point in the history
)

* inherit from AbstractCommunityTestCase
* show example of upgrade
* make use autowired array
* use native PostRector ignore
* use native Post import rector
* make use of configs in tests
* fix cs
* static fixes
* make use of configurable phpstan for rector path
* add configs
* remove unused DependencyInjection
* run Rector on code base to import FQN and add see annotatoins
* use tagged rector

Closes rectorphp/rector#5478
  • Loading branch information
TomasVotruba authored Feb 12, 2021
1 parent 97e733c commit 7d5e570
Show file tree
Hide file tree
Showing 383 changed files with 3,046 additions and 1,425 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": "^7.3|^8.0",
"phpstan/phpstan": "^0.12.69, <0.12.70",
"rector/rector": "0.9.20"
"rector/rector": "^0.9.23"
},
"require-dev": {
"captainhook/captainhook": "^5.4",
Expand Down
11 changes: 2 additions & 9 deletions config/database-connection-to-dbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

declare(strict_types=1);

use Ssch\TYPO3Rector\Helper\Typo3NodeResolver;
use Ssch\TYPO3Rector\Rector\v9\v0\DatabaseConnectionToDbalRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/services.php');
$services = $containerConfigurator->services();

$services->set(DatabaseConnectionToDbalRector::class)->args(
[
Ssch\TYPO3Rector\Helper\DependencyInjection::service(Typo3NodeResolver::class),
tagged_iterator('database.dbal.refactoring'),
]
);
$services = $containerConfigurator->services();
$services->set(DatabaseConnectionToDbalRector::class);
};
65 changes: 16 additions & 49 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,37 @@

declare(strict_types=1);

use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\PhpDoc\TypeNodeResolver;
use PHPStan\Reflection\ReflectionProvider;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Configuration\Option;
use Ssch\TYPO3Rector\Console\Application;
use Ssch\TYPO3Rector\Console\Output\DecoratedConsoleOutputFormatter;
use Ssch\TYPO3Rector\DependencyInjection\PHPStanServicesFactory;
use Ssch\TYPO3Rector\Helper\Database\Refactorings\DatabaseConnectionToDbalRefactoring;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/../utils/**/config/config.php', null, true);

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/../phpstan.neon');

$services = $containerConfigurator->services();
$services->defaults()
->public()
->autowire();

$services
->instanceof(DatabaseConnectionToDbalRefactoring::class)
->tag('database.dbal.refactoring')
->share(false);

$services->alias(SymfonyApplication::class, Application::class);

$services->set(ReflectionProvider::class)
->factory(
[\Ssch\TYPO3Rector\Helper\DependencyInjection::service(
PHPStanServicesFactory::class
), 'createReflectionProvider']
);

$services->set(NodeScopeResolver::class)
->factory(
[\Ssch\TYPO3Rector\Helper\DependencyInjection::service(
PHPStanServicesFactory::class
), 'createNodeScopeResolver']
);

$services->set(ScopeFactory::class)
->factory(
[\Ssch\TYPO3Rector\Helper\DependencyInjection::service(PHPStanServicesFactory::class), 'createScopeFactory']
);

$services->set(TypeNodeResolver::class)
->factory(
[\Ssch\TYPO3Rector\Helper\DependencyInjection::service(
PHPStanServicesFactory::class
), 'createTypeNodeResolver']
);

$services->load('Ssch\\TYPO3Rector\\', __DIR__ . '/../src')
->exclude(
[
__DIR__ . '/../src/Rector',
__DIR__ . '/../src/Set',
__DIR__ . '/../src/Bootstrap',
__DIR__ . '/../src/HttpKernel',
__DIR__ . '/../src/Compiler',
__DIR__ . '/../src/ValueObject',
]
);

$services->set(DecoratedConsoleOutputFormatter::class)->decorate(ConsoleOutputFormatter::class);
->exclude([
__DIR__ . '/../src/Rector',
__DIR__ . '/../src/Set',
__DIR__ . '/../src/Bootstrap',
__DIR__ . '/../src/HttpKernel',
__DIR__ . '/../src/Compiler',
__DIR__ . '/../src/ValueObject',
]);

$services->set(DecoratedConsoleOutputFormatter::class)
->decorate(ConsoleOutputFormatter::class);
};
2 changes: 2 additions & 0 deletions config/v8/typo3-85.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use TYPO3\CMS\Extbase\Utility\ArrayUtility;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/../../../../../../config/services.php');

$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
Expand Down
2 changes: 2 additions & 0 deletions config/v8/typo3-86.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/../../../../../../config/services.php');

$services = $containerConfigurator->services();
$services->set(RenameNamespaceRector::class)->call('configure', [
RenameNamespaceRector::OLD_TO_NEW_NAMESPACES => [
Expand Down
6 changes: 4 additions & 2 deletions docs/all_rectors_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2340,8 +2340,9 @@ use Ssch\TYPO3Rector\Rector\Migrations\RenameClassMapAliasRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$containerConfigurator->import(__DIR__ . '/../../../../../../config/services.php');

$services = $containerConfigurator->services();
$services->set(RenameClassMapAliasRector::class)
->call('configure', [[RenameClassMapAliasRector::CLASS_ALIAS_MAPS => 'config/Migrations/Code/ClassAliasMap.php']]);
};
Expand Down Expand Up @@ -2411,8 +2412,9 @@ use Ssch\TYPO3Rector\Rector\v9\v0\ReplaceAnnotationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$containerConfigurator->import(__DIR__ . '/../../../../../../config/services.php');

$services = $containerConfigurator->services();
$services->set(ReplaceAnnotationRector::class)
->call('configure', [[ReplaceAnnotationRector::OLD_TO_NEW_ANNOTATIONS => ['transient' => 'TYPO3\CMS\Extbase\Annotation\ORM\Transient']]]);
};
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration_and_processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Let´s say you want to migrate the TCA from a TYPO3 7 project to a TYPO3 9 proje
declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\PostRector\Rector\NameImportingPostRector;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\PostRector\NameImportingPostRector;
use Ssch\TYPO3Rector\Set\Typo3SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -34,11 +35,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
Typo3SetList::TCA_76,
Typo3SetList::TCA_87,
Typo3SetList::TCA_95,
]
);
]);

// FQN classes are not imported by default. If you don't do it manually after every Rector run, enable it by:
$parameters->set(Typo3Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);

// this will not import root namespace classes, like \DateTime or \Exception
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ parameters:
checkGenericClassInNonGenericObjectType: false

ignoreErrors:
- '#Function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ref not found#'
- '#Function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#'
- '#Used function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ref not found#'
- '#Used function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#'
- '#Parameter \#2 \$stmt of method Rector\\Core\\NodeManipulator\\ClassInsertManipulator\:\:addAsFirstMethod\(\) expects PhpParser\\Node\\Stmt\\ClassConst\|PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Property, PhpParser\\Node\\Stmt\\Nop given#'
8 changes: 6 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\PHPUnit\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\Set\ValueObject\SetList;
use Ssch\TYPO3Rector\Rules\Rector\Misc\AddCodeCoverageIgnoreToMethodRectorDefinitionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Expand All @@ -13,16 +14,19 @@

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan.neon');

$parameters->set(Option::SETS, [
SetList::PRIVATIZATION,
SetList::DEAD_CODE,
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
]
);
]);

$services = $containerConfigurator->services();

$services->set(AddCodeCoverageIgnoreToMethodRectorDefinitionRector::class);
$services->set(AddSeeTestAnnotationRector::class);

$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
$parameters->set(Option::SKIP, [__DIR__ . '/src/Bootstrap', __DIR__ . '/src/Set', __DIR__ . '/src/Compiler']);
Expand Down
5 changes: 0 additions & 5 deletions src/Configuration/Typo3Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

final class Typo3Option
{
/**
* @var string
*/
public const AUTO_IMPORT_NAMES = 'typo3_auto_import_names';

/**
* @var string
*/
Expand Down
Loading

0 comments on commit 7d5e570

Please sign in to comment.