From 17b36a4445489e155f8c22ae1c9c8fce24df8fcc Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 12 Sep 2020 22:24:36 +0200 Subject: [PATCH 01/64] composer: update rector to 0.8 --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 40ac135f..dcdff67f 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "ast" ], "require": { - "rector/rector-prefixed": "0.7.29" + "jawira/case-converter": "^1.1", + "rector/rector-prefixed": "^0.8.6" }, "license": "MIT", "authors": [ From 9732bf1f7ba78f2dabb0358ce164761502c6c32f Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 12 Sep 2020 22:27:54 +0200 Subject: [PATCH 02/64] switch configs from YML to PHP --- .../local_package_functional_tests.yml | 2 +- .../workflows/local_package_run_rector.yml | 2 +- .../packagist_package_run_rector.yml | 2 +- README.md | 10 +-- composer.json | 1 + config/drupal-8/drupal-8-all-deprecations.php | 13 ++++ config/drupal-8/drupal-8-all-deprecations.yml | 16 ----- config/drupal-8/drupal-8.0-deprecations.php | 72 +++++++++++++++++++ config/drupal-8/drupal-8.0-deprecations.yml | 23 ------ config/drupal-8/drupal-8.1-deprecations.php | 8 +++ config/drupal-8/drupal-8.1-deprecations.yml | 2 - config/drupal-8/drupal-8.2-deprecations.php | 12 ++++ config/drupal-8/drupal-8.2-deprecations.yml | 3 - config/drupal-8/drupal-8.3-deprecations.php | 12 ++++ config/drupal-8/drupal-8.3-deprecations.yml | 3 - config/drupal-8/drupal-8.4-deprecations.yml | 5 -- config/drupal-8/drupal-8.5-deprecations.php | 21 ++++++ config/drupal-8/drupal-8.5-deprecations.yml | 6 -- config/drupal-8/drupal-8.6-deprecations.php | 18 +++++ config/drupal-8/drupal-8.6-deprecations.yml | 5 -- config/drupal-8/drupal-8.7-deprecations.php | 27 +++++++ config/drupal-8/drupal-8.7-deprecations.yml | 8 --- config/drupal-8/drupal-8.8-deprecations.php | 45 ++++++++++++ config/drupal-8/drupal-8.8-deprecations.yml | 14 ---- rector-config-docroot-dir.php | 21 ++++++ rector-config-docroot-dir.yml | 50 ------------- rector-config-web-dir.php | 20 ++++++ rector-config-web-dir.yml | 50 ------------- rector.php | 21 ++++++ rector.yml | 50 ------------- .../Base/ConstantToClassConstantBase.php | 2 +- 31 files changed, 300 insertions(+), 244 deletions(-) create mode 100644 config/drupal-8/drupal-8-all-deprecations.php delete mode 100644 config/drupal-8/drupal-8-all-deprecations.yml create mode 100644 config/drupal-8/drupal-8.0-deprecations.php delete mode 100644 config/drupal-8/drupal-8.0-deprecations.yml create mode 100644 config/drupal-8/drupal-8.1-deprecations.php delete mode 100644 config/drupal-8/drupal-8.1-deprecations.yml create mode 100644 config/drupal-8/drupal-8.2-deprecations.php delete mode 100644 config/drupal-8/drupal-8.2-deprecations.yml create mode 100644 config/drupal-8/drupal-8.3-deprecations.php delete mode 100644 config/drupal-8/drupal-8.3-deprecations.yml delete mode 100644 config/drupal-8/drupal-8.4-deprecations.yml create mode 100644 config/drupal-8/drupal-8.5-deprecations.php delete mode 100644 config/drupal-8/drupal-8.5-deprecations.yml create mode 100644 config/drupal-8/drupal-8.6-deprecations.php delete mode 100644 config/drupal-8/drupal-8.6-deprecations.yml create mode 100644 config/drupal-8/drupal-8.7-deprecations.php delete mode 100644 config/drupal-8/drupal-8.7-deprecations.yml create mode 100644 config/drupal-8/drupal-8.8-deprecations.php delete mode 100644 config/drupal-8/drupal-8.8-deprecations.yml create mode 100644 rector-config-docroot-dir.php delete mode 100644 rector-config-docroot-dir.yml create mode 100644 rector-config-web-dir.php delete mode 100644 rector-config-web-dir.yml create mode 100644 rector.php delete mode 100644 rector.yml diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml index c3bee15d..6c352fc1 100644 --- a/.github/workflows/local_package_functional_tests.yml +++ b/.github/workflows/local_package_functional_tests.yml @@ -33,7 +33,7 @@ jobs: - run: | # Prepare rector config files with Drupal specific settings cd .. - cp vendor/palantirnet/drupal-rector/rector.yml . + cp vendor/palantirnet/drupal-rector/rector.php . # This is copied from `local_package_run_rector`. # This seems needed for the autoloading to work. diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index 8ee9d0e3..f3418164 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -34,7 +34,7 @@ jobs: - run: | # Prepare rector config files with Drupal specific settings cd .. - cp vendor/palantirnet/drupal-rector/rector.yml . + cp vendor/palantirnet/drupal-rector/rector.php . - run: | # Prepare rector_examples folder in the drupal modules directory diff --git a/.github/workflows/packagist_package_run_rector.yml b/.github/workflows/packagist_package_run_rector.yml index 6cdf85b5..403b0816 100644 --- a/.github/workflows/packagist_package_run_rector.yml +++ b/.github/workflows/packagist_package_run_rector.yml @@ -37,7 +37,7 @@ jobs: - run: | # Prepare rector config files with Drupal specific settings cd drupal - cp vendor/palantirnet/drupal-rector/rector.yml . + cp vendor/palantirnet/drupal-rector/rector.php . - run: | # Prepare rector_examples folder in the drupal modules directory diff --git a/README.md b/README.md index 3e09d1c7..83de20a2 100644 --- a/README.md +++ b/README.md @@ -58,23 +58,23 @@ $ composer require --dev palantirnet/drupal-rector ### Create a configuration file in your project -You will need to have a `rector.yml` configuration in the root of your repository. This should sit beside your document root such as `web` or `docroot`. +You will need to have a `rector.php` configuration in the root of your repository. This should sit beside your document root such as `web` or `docroot`. This project provides starting files that should handle most use cases. If your document root directory is `web`, you can copy the `rector-config-web-dir.yml` ```bash -cp vendor/palantirnet/drupal-rector/rector-config-web-dir.yml rector.yml +cp vendor/palantirnet/drupal-rector/rector-config-web-dir.yml rector.php ``` If your document root directory is `docroot`, you can copy the `rector-config-docroot-dir.yml` ```bash -cp vendor/palantirnet/drupal-rector/rector-config-docroot-dir.yml rector.yml +cp vendor/palantirnet/drupal-rector/rector-config-docroot-dir.yml rector.php ``` -If your document root directory is something else you will need to manually copy and edit `rector.yml`. +If your document root directory is something else you will need to manually copy and edit `rector.php`. Replace the `web` in these paths with your document root. @@ -140,7 +140,7 @@ If you are having these issues try running Rector from the environment that has ### Iconv error when running Rector in Alpine Docker -If you are getting errors like +If you are getting errors like `iconv(): Wrong charset, conversion from UTF-8 to ASCII//TRANSLIT//IGNORE is not allowed` diff --git a/composer.json b/composer.json index dcdff67f..43f05fa7 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "ast" ], "require": { + "php": "^7.2", "jawira/case-converter": "^1.1", "rector/rector-prefixed": "^0.8.6" }, diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php new file mode 100644 index 00000000..5746f99d --- /dev/null +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -0,0 +1,13 @@ +import(__DIR__ . '/drupal-8.*'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::EXCLUDE_RECTORS, []); +}; diff --git a/config/drupal-8/drupal-8-all-deprecations.yml b/config/drupal-8/drupal-8-all-deprecations.yml deleted file mode 100644 index 3be371c7..00000000 --- a/config/drupal-8/drupal-8-all-deprecations.yml +++ /dev/null @@ -1,16 +0,0 @@ -# General ruleset for Drupal 8. -imports: - - { resource: "./drupal-8.0-deprecations.yml" } - - { resource: "./drupal-8.1-deprecations.yml" } - - { resource: "./drupal-8.2-deprecations.yml" } - - { resource: "./drupal-8.3-deprecations.yml" } - - { resource: "./drupal-8.4-deprecations.yml" } - - { resource: "./drupal-8.5-deprecations.yml" } - - { resource: "./drupal-8.6-deprecations.yml" } - - { resource: "./drupal-8.7-deprecations.yml" } - - { resource: "./drupal-8.8-deprecations.yml" } - -parameters: - exclude_rectors: ~ - -services: ~ diff --git a/config/drupal-8/drupal-8.0-deprecations.php b/config/drupal-8/drupal-8.0-deprecations.php new file mode 100644 index 00000000..55d78f15 --- /dev/null +++ b/config/drupal-8/drupal-8.0-deprecations.php @@ -0,0 +1,72 @@ +services(); + + $services->set(DBInsertRector::class); + + $services->set(DBSelectRector::class); + + $services->set(DBQueryRector::class); + + $services->set(DBDeleteRector::class); + + $services->set(DBUpdateRector::class); + + $services->set(DrupalRenderRector::class); + + $services->set(DrupalRenderRootRector::class); + + $services->set(DrupalURLRector::class); + + $services->set(DrupalLRector::class); + + $services->set(DrupalRealpathRector::class); + + $services->set(EntityCreateRector::class); + + $services->set(EntityInterfaceLinkRector::class); + + $services->set(EntityInterfaceUrlInfoRector::class); + + $services->set(EntityLoadRector::class); + + $services->set(EntityManagerRector::class); + + $services->set(FormatDateRector::class); + + $services->set(FileLoadRector::class); + + $services->set(LinkGeneratorTraitLRector::class); + + $services->set(NodeLoadRector::class); + + $services->set(SafeMarkupFormatRector::class); + + $services->set(UserLoadRector::class); +}; diff --git a/config/drupal-8/drupal-8.0-deprecations.yml b/config/drupal-8/drupal-8.0-deprecations.yml deleted file mode 100644 index f236404c..00000000 --- a/config/drupal-8/drupal-8.0-deprecations.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.0. -services: - DrupalRector\Rector\Deprecation\DBInsertRector: ~ - DrupalRector\Rector\Deprecation\DBSelectRector: ~ - DrupalRector\Rector\Deprecation\DBQueryRector: ~ - DrupalRector\Rector\Deprecation\DBDeleteRector: ~ - DrupalRector\Rector\Deprecation\DBUpdateRector: ~ - DrupalRector\Rector\Deprecation\DrupalRenderRector: ~ - DrupalRector\Rector\Deprecation\DrupalRenderRootRector: ~ - DrupalRector\Rector\Deprecation\DrupalURLRector: ~ - DrupalRector\Rector\Deprecation\DrupalLRector: ~ - DrupalRector\Rector\Deprecation\DrupalRealpathRector: ~ - DrupalRector\Rector\Deprecation\EntityCreateRector: ~ - DrupalRector\Rector\Deprecation\EntityInterfaceLinkRector: ~ - DrupalRector\Rector\Deprecation\EntityInterfaceUrlInfoRector: ~ - DrupalRector\Rector\Deprecation\EntityLoadRector: ~ - DrupalRector\Rector\Deprecation\EntityManagerRector: ~ - DrupalRector\Rector\Deprecation\FormatDateRector: ~ - DrupalRector\Rector\Deprecation\FileLoadRector: ~ - DrupalRector\Rector\Deprecation\LinkGeneratorTraitLRector: ~ - DrupalRector\Rector\Deprecation\NodeLoadRector: ~ - DrupalRector\Rector\Deprecation\SafeMarkupFormatRector: ~ - DrupalRector\Rector\Deprecation\UserLoadRector: ~ diff --git a/config/drupal-8/drupal-8.1-deprecations.php b/config/drupal-8/drupal-8.1-deprecations.php new file mode 100644 index 00000000..4788e9d3 --- /dev/null +++ b/config/drupal-8/drupal-8.1-deprecations.php @@ -0,0 +1,8 @@ +services(); + + $services->set(FileDirectoryOsTempRector::class); +}; diff --git a/config/drupal-8/drupal-8.2-deprecations.yml b/config/drupal-8/drupal-8.2-deprecations.yml deleted file mode 100644 index 2b9b7c6e..00000000 --- a/config/drupal-8/drupal-8.2-deprecations.yml +++ /dev/null @@ -1,3 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.2. -services: - DrupalRector\Rector\Deprecation\FileDirectoryOsTempRector: ~ diff --git a/config/drupal-8/drupal-8.3-deprecations.php b/config/drupal-8/drupal-8.3-deprecations.php new file mode 100644 index 00000000..35b5055f --- /dev/null +++ b/config/drupal-8/drupal-8.3-deprecations.php @@ -0,0 +1,12 @@ +services(); + + $services->set(RequestTimeConstRector::class); +}; diff --git a/config/drupal-8/drupal-8.3-deprecations.yml b/config/drupal-8/drupal-8.3-deprecations.yml deleted file mode 100644 index 53e3bfb7..00000000 --- a/config/drupal-8/drupal-8.3-deprecations.yml +++ /dev/null @@ -1,3 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.3. -services: - DrupalRector\Rector\Deprecation\RequestTimeConstRector: ~ diff --git a/config/drupal-8/drupal-8.4-deprecations.yml b/config/drupal-8/drupal-8.4-deprecations.yml deleted file mode 100644 index 0815fc2f..00000000 --- a/config/drupal-8/drupal-8.4-deprecations.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.4. -services: - DrupalRector\Rector\Deprecation\BrowserTestBaseGetMockRector: ~ - DrupalRector\Rector\Deprecation\KernelTestBaseGetMockRector: ~ - DrupalRector\Rector\Deprecation\UnitTestCaseGetMockRector: ~ diff --git a/config/drupal-8/drupal-8.5-deprecations.php b/config/drupal-8/drupal-8.5-deprecations.php new file mode 100644 index 00000000..20c9468b --- /dev/null +++ b/config/drupal-8/drupal-8.5-deprecations.php @@ -0,0 +1,21 @@ +services(); + + $services->set(DrupalSetMessageRector::class); + + $services->set(DatetimeDateStorageFormatRector::class); + + $services->set(DatetimeDatetimeStorageFormatRector::class); + + $services->set(DatetimeStorageTimezoneRector::class); +}; diff --git a/config/drupal-8/drupal-8.5-deprecations.yml b/config/drupal-8/drupal-8.5-deprecations.yml deleted file mode 100644 index 63f9ea3f..00000000 --- a/config/drupal-8/drupal-8.5-deprecations.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.5. -services: - DrupalRector\Rector\Deprecation\DrupalSetMessageRector: ~ - DrupalRector\Rector\Deprecation\DatetimeDateStorageFormatRector: ~ - DrupalRector\Rector\Deprecation\DatetimeDatetimeStorageFormatRector: ~ - DrupalRector\Rector\Deprecation\DatetimeStorageTimezoneRector: ~ diff --git a/config/drupal-8/drupal-8.6-deprecations.php b/config/drupal-8/drupal-8.6-deprecations.php new file mode 100644 index 00000000..e7abe9ba --- /dev/null +++ b/config/drupal-8/drupal-8.6-deprecations.php @@ -0,0 +1,18 @@ +services(); + + $services->set(UnicodeStrlenRector::class); + + $services->set(UnicodeStrtolowerRector::class); + + $services->set(UnicodeSubstrRector::class); +}; diff --git a/config/drupal-8/drupal-8.6-deprecations.yml b/config/drupal-8/drupal-8.6-deprecations.yml deleted file mode 100644 index 9ce1b196..00000000 --- a/config/drupal-8/drupal-8.6-deprecations.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.6. -services: - DrupalRector\Rector\Deprecation\UnicodeStrlenRector: ~ - DrupalRector\Rector\Deprecation\UnicodeStrtolowerRector: ~ - DrupalRector\Rector\Deprecation\UnicodeSubstrRector: ~ diff --git a/config/drupal-8/drupal-8.7-deprecations.php b/config/drupal-8/drupal-8.7-deprecations.php new file mode 100644 index 00000000..63c2c8d0 --- /dev/null +++ b/config/drupal-8/drupal-8.7-deprecations.php @@ -0,0 +1,27 @@ +services(); + + $services->set(FilePrepareDirectoryRector::class); + + $services->set(FileCreateDirectoryRector::class); + + $services->set(FileExistsReplaceRector::class); + + $services->set(FileUnmanagedSaveDataRector::class); + + $services->set(FileModifyPermissionsRector::class); + + $services->set(FileExistsRenameRector::class); +}; diff --git a/config/drupal-8/drupal-8.7-deprecations.yml b/config/drupal-8/drupal-8.7-deprecations.yml deleted file mode 100644 index 57751a83..00000000 --- a/config/drupal-8/drupal-8.7-deprecations.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.7. -services: - DrupalRector\Rector\Deprecation\FilePrepareDirectoryRector: ~ - DrupalRector\Rector\Deprecation\FileCreateDirectoryRector: ~ - DrupalRector\Rector\Deprecation\FileExistsReplaceRector: ~ - DrupalRector\Rector\Deprecation\FileUnmanagedSaveDataRector: ~ - DrupalRector\Rector\Deprecation\FileModifyPermissionsRector: ~ - DrupalRector\Rector\Deprecation\FileExistsRenameRector: ~ diff --git a/config/drupal-8/drupal-8.8-deprecations.php b/config/drupal-8/drupal-8.8-deprecations.php new file mode 100644 index 00000000..2db4fb6f --- /dev/null +++ b/config/drupal-8/drupal-8.8-deprecations.php @@ -0,0 +1,45 @@ +services(); + + $services->set(PathAliasManagerServiceNameRector::class); + + $services->set(PathAliasWhitelistServiceNameRector::class); + + $services->set(PathSubscriberServiceNameRector::class); + + $services->set(PathProcessorAliasServiceNameRector::class); + + $services->set(PathAliasRepositoryRector::class); + + $services->set(FileDefaultSchemeRector::class); + + $services->set(EntityGetDisplayRector::class); + + $services->set(EntityGetFormDisplayRector::class); + + $services->set(EntityTypeGetLowercaseLabelRector::class); + + $services->set(FileScanDirectoryRector::class); + + $services->set(FileDirectoryTempRector::class); + + $services->set(FileUriTargetRector::class); +}; diff --git a/config/drupal-8/drupal-8.8-deprecations.yml b/config/drupal-8/drupal-8.8-deprecations.yml deleted file mode 100644 index 98511198..00000000 --- a/config/drupal-8/drupal-8.8-deprecations.yml +++ /dev/null @@ -1,14 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.8. -services: - DrupalRector\Rector\Deprecation\PathAliasManagerServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathAliasWhitelistServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathSubscriberServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathProcessorAliasServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathAliasRepositoryRector: ~ - DrupalRector\Rector\Deprecation\FileDefaultSchemeRector: ~ - DrupalRector\Rector\Deprecation\EntityGetDisplayRector: ~ - DrupalRector\Rector\Deprecation\EntityGetFormDisplayRector: ~ - DrupalRector\Rector\Deprecation\EntityTypeGetLowercaseLabelRector: ~ - DrupalRector\Rector\Deprecation\FileScanDirectoryRector: ~ - DrupalRector\Rector\Deprecation\FileDirectoryTempRector: ~ - DrupalRector\Rector\Deprecation\FileUriTargetRector: ~ diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php new file mode 100644 index 00000000..554d7be4 --- /dev/null +++ b/rector-config-docroot-dir.php @@ -0,0 +1,21 @@ +import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml'); + + $parameters = $containerConfigurator->parameters(); + + $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/core/modules', 'docroot/modules', 'docroot/profiles']); + $parameters->set(Option::EXCLUDE_PATHS, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + $parameters->set(Option::IMPORT_DOC_BLOCKS, false); + + $parameters->set('drupal_rector_notices_as_comments', true); +}; diff --git a/rector-config-docroot-dir.yml b/rector-config-docroot-dir.yml deleted file mode 100644 index 31f6cc47..00000000 --- a/rector-config-docroot-dir.yml +++ /dev/null @@ -1,50 +0,0 @@ -imports: - - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" } - # includes: - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.0-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.1-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.2-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.3-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.4-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.8-deprecations.yml" } - -parameters: - autoload_paths: - - 'docroot/core' - - 'docroot/core/modules' - - 'docroot/modules' - - 'docroot/profiles' - - exclude_paths: - # This path is used by the upgrade_status module. - - '*/upgrade_status/tests/modules/*' - # If you would like to skip test directories, uncomment the following lines: - # - '*/tests/*' - # - '*/Tests/*' - - file_extensions: - - module - - theme - - install - - profile - - inc - - engine - - # If you would like Rector to include PHPUnit 8 upgrades, uncomment the following lines: - # sets: - # - phpunit80 - - # Create `use` statements. - auto_import_names: true - # Do not convert `\Drupal` to `Drupal`, etc. - import_short_classes: false - # This will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ - import_doc_blocks: false - - # This will add comments to call out edge cases in replacements. - drupal_rector_notices_as_comments: true - -services: ~ diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php new file mode 100644 index 00000000..875e5e43 --- /dev/null +++ b/rector-config-web-dir.php @@ -0,0 +1,20 @@ +import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); + $parameters->set(Option::EXCLUDE_PATHS, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + $parameters->set(Option::IMPORT_DOC_BLOCKS, false); + + $parameters->set('drupal_rector_notices_as_comments', true); +}; diff --git a/rector-config-web-dir.yml b/rector-config-web-dir.yml deleted file mode 100644 index ae09616e..00000000 --- a/rector-config-web-dir.yml +++ /dev/null @@ -1,50 +0,0 @@ -imports: - - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" } - # includes: - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.0-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.1-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.2-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.3-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.4-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.8-deprecations.yml" } - -parameters: - autoload_paths: - - 'web/core' - - 'web/core/modules' - - 'web/modules' - - 'web/profiles' - - exclude_paths: - # This path is used by the upgrade_status module. - - '*/upgrade_status/tests/modules/*' - # If you would like to skip test directories, uncomment the following lines: - # - '*/tests/*' - # - '*/Tests/*' - - file_extensions: - - module - - theme - - install - - profile - - inc - - engine - - # If you would like Rector to include PHPUnit 8 upgrades, uncomment the following lines: - # sets: - # - phpunit80 - - # Create `use` statements. - auto_import_names: true - # Do not convert `\Drupal` to `Drupal`, etc. - import_short_classes: false - # This will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ - import_doc_blocks: false - - # This will add comments to call out edge cases in replacements. - drupal_rector_notices_as_comments: true - -services: ~ diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..e180bb43 --- /dev/null +++ b/rector.php @@ -0,0 +1,21 @@ +import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); + + $parameters->set(Option::EXCLUDE_PATHS, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + $parameters->set(Option::IMPORT_DOC_BLOCKS, false); + + $parameters->set('drupal_rector_notices_as_comments', true); +}; diff --git a/rector.yml b/rector.yml deleted file mode 100644 index ae09616e..00000000 --- a/rector.yml +++ /dev/null @@ -1,50 +0,0 @@ -imports: - - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" } - # includes: - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.0-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.1-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.2-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.3-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.4-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.8-deprecations.yml" } - -parameters: - autoload_paths: - - 'web/core' - - 'web/core/modules' - - 'web/modules' - - 'web/profiles' - - exclude_paths: - # This path is used by the upgrade_status module. - - '*/upgrade_status/tests/modules/*' - # If you would like to skip test directories, uncomment the following lines: - # - '*/tests/*' - # - '*/Tests/*' - - file_extensions: - - module - - theme - - install - - profile - - inc - - engine - - # If you would like Rector to include PHPUnit 8 upgrades, uncomment the following lines: - # sets: - # - phpunit80 - - # Create `use` statements. - auto_import_names: true - # Do not convert `\Drupal` to `Drupal`, etc. - import_short_classes: false - # This will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ - import_doc_blocks: false - - # This will add comments to call out edge cases in replacements. - drupal_rector_notices_as_comments: true - -services: ~ diff --git a/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php b/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php index e4b8bfff..27ef7620 100644 --- a/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php +++ b/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php @@ -52,7 +52,7 @@ public function refactor(Node $node): ?Node /** @var Node\Expr\FuncCall $node */ if ($this->getName($node->name) === $this->deprecatedConstant) { - // We add a fully qualified class name and the parameters in `rector.yml` adds the use statement. + // We add a fully qualified class name and the parameters in `rector.php` adds the use statement. $fully_qualified_class = new Node\Name\FullyQualified($this->constantFullyQualifiedClassName); $name = new Node\Identifier($this->constant); From e1e09b041927efaeb5902d42f23f18d444fafc01 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 12 Sep 2020 22:47:49 +0200 Subject: [PATCH 03/64] drop duplicated info in editorconfig --- .editorconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index e1b987c7..75d5192d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,3 @@ indent_size = 4 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true - -[composer.{json,lock}] -indent_size = 4 From b6ad9c857acf0a72002027c4f5670a084996fd7e Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 24 Mar 2021 14:31:26 -0500 Subject: [PATCH 04/64] Add phpstan and rector dev trunk --- .editorconfig | 4 ++++ composer.json | 8 ++++++-- phpstan.neon | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 phpstan.neon diff --git a/.editorconfig b/.editorconfig index e1b987c7..49864369 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,7 @@ insert_final_newline = true [composer.{json,lock}] indent_size = 4 + +[*.neon] +indent_size = 4 +indent_style = tab diff --git a/composer.json b/composer.json index 717aef3a..d3d759f3 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "ast" ], "require": { - "rector/rector-prefixed": "0.7.29" + "rector/rector-prefixed": "~0.10.0" }, "license": "MIT", "authors": [ @@ -45,6 +45,10 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "behat/behat": "^3.6" + "behat/behat": "^3.6", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^0.12.82", + "phpstan/phpstan-deprecation-rules": "^0.12.6", + "rector/rector": "~0.10.0" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..7229da62 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,2 @@ +parameters: + level: 0 From c043b055ef9af62f6bffe426db866cc10f946293 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 24 Mar 2021 14:39:51 -0500 Subject: [PATCH 05/64] Add back EntityDeleteMultipleRector --- config/drupal-8/drupal-8.0-deprecations.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/drupal-8/drupal-8.0-deprecations.php b/config/drupal-8/drupal-8.0-deprecations.php index 55d78f15..a1dcf0de 100644 --- a/config/drupal-8/drupal-8.0-deprecations.php +++ b/config/drupal-8/drupal-8.0-deprecations.php @@ -13,6 +13,7 @@ use DrupalRector\Rector\Deprecation\DrupalRenderRootRector; use DrupalRector\Rector\Deprecation\DrupalURLRector; use DrupalRector\Rector\Deprecation\EntityCreateRector; +use DrupalRector\Rector\Deprecation\EntityDeleteMultipleRector; use DrupalRector\Rector\Deprecation\EntityInterfaceLinkRector; use DrupalRector\Rector\Deprecation\EntityInterfaceUrlInfoRector; use DrupalRector\Rector\Deprecation\EntityLoadRector; @@ -50,6 +51,8 @@ $services->set(EntityCreateRector::class); + $services->set(EntityDeleteMultipleRector::class); + $services->set(EntityInterfaceLinkRector::class); $services->set(EntityInterfaceUrlInfoRector::class); From e02f8cca204c3531ee7c56221b932a110f188dd1 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 24 Mar 2021 15:17:06 -0500 Subject: [PATCH 06/64] Update rule definitions for Rector 0.10 --- config/drupal-8/drupal-8-all-deprecations.php | 2 +- .../Base/DrupalServiceRenameBase.php | 8 +++---- src/Rector/Deprecation/Base/GetMockBase.php | 21 ++++++++++++++++-- .../BrowserTestBaseGetMockRector.php | 8 +++---- src/Rector/Deprecation/DBDeleteRector.php | 8 +++---- src/Rector/Deprecation/DBInsertRector.php | 8 +++---- src/Rector/Deprecation/DBQueryRector.php | 8 +++---- src/Rector/Deprecation/DBSelectRector.php | 8 +++---- src/Rector/Deprecation/DBUpdateRector.php | 8 +++---- .../DatetimeDateStorageFormatRector.php | 8 +++---- .../DatetimeDatetimeStorageFormatRector.php | 8 +++---- .../DatetimeStorageTimezoneRector.php | 8 +++---- src/Rector/Deprecation/DrupalLRector.php | 8 +++---- .../Deprecation/DrupalRealpathRector.php | 8 +++---- src/Rector/Deprecation/DrupalRenderRector.php | 8 +++---- .../Deprecation/DrupalRenderRootRector.php | 8 +++---- .../Deprecation/DrupalSetMessageRector.php | 8 +++---- src/Rector/Deprecation/DrupalURLRector.php | 8 +++---- src/Rector/Deprecation/EntityCreateRector.php | 8 +++---- .../EntityDeleteMultipleRector.php | 8 +++---- .../Deprecation/EntityGetDisplayRector.php | 8 +++---- .../EntityGetFormDisplayRector.php | 8 +++---- .../Deprecation/EntityInterfaceLinkRector.php | 8 +++---- .../EntityInterfaceUrlInfoRector.php | 8 +++---- src/Rector/Deprecation/EntityLoadRector.php | 8 +++---- .../Deprecation/EntityManagerRector.php | 22 ++++++++++++++----- .../EntityTypeGetLowercaseLabelRector.php | 8 +++---- .../Deprecation/FileCreateDirectoryRector.php | 8 +++---- .../Deprecation/FileDefaultSchemeRector.php | 8 +++---- .../Deprecation/FileDirectoryOsTempRector.php | 8 +++---- .../Deprecation/FileDirectoryTempRector.php | 8 +++---- .../Deprecation/FileExistsRenameRector.php | 8 +++---- .../Deprecation/FileExistsReplaceRector.php | 8 +++---- src/Rector/Deprecation/FileLoadRector.php | 8 +++---- .../FileModifyPermissionsRector.php | 8 +++---- .../FilePrepareDirectoryRector.php | 8 +++---- .../Deprecation/FileScanDirectoryRector.php | 8 +++---- .../FileUnmanagedSaveDataRector.php | 8 +++---- .../Deprecation/FileUriTargetRector.php | 8 +++---- src/Rector/Deprecation/FormatDateRector.php | 8 +++---- .../KernelTestBaseGetMockRector.php | 8 +++---- .../Deprecation/LinkGeneratorTraitLRector.php | 8 +++---- src/Rector/Deprecation/NodeLoadRector.php | 8 +++---- .../Deprecation/RequestTimeConstRector.php | 8 +++---- .../Deprecation/SafeMarkupFormatRector.php | 12 +++++----- .../Deprecation/UnicodeStrlenRector.php | 8 +++---- .../Deprecation/UnicodeStrtolowerRector.php | 8 +++---- .../Deprecation/UnicodeSubstrRector.php | 8 +++---- .../Deprecation/UnitTestCaseGetMockRector.php | 8 +++---- src/Rector/Deprecation/UserLoadRector.php | 8 +++---- 50 files changed, 225 insertions(+), 200 deletions(-) diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php index 5746f99d..cc480d97 100644 --- a/config/drupal-8/drupal-8-all-deprecations.php +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -9,5 +9,5 @@ $containerConfigurator->import(__DIR__ . '/drupal-8.*'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::EXCLUDE_RECTORS, []); + $parameters->set(Option::SKIP, []); }; diff --git a/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php b/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php index f1194435..08eb6030 100644 --- a/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php +++ b/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php @@ -2,8 +2,8 @@ namespace DrupalRector\Rector\Deprecation\Base; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Renames deprecated Drupal::services(). @@ -30,8 +30,8 @@ abstract class DrupalServiceRenameBase extends StaticArgumentRenameBase { /** * @inheritdoc */ - public function getDefinition(): RectorDefinition { - return new RectorDefinition('Renames the IDs in Drupal::service() calls',[ + public function getRuleDefinition(): RuleDefinition { + return new RuleDefinition('Renames the IDs in Drupal::service() calls',[ new CodeSample( <<<'CODE_BEFORE' \Drupal::service('old')->foo(); diff --git a/src/Rector/Deprecation/Base/GetMockBase.php b/src/Rector/Deprecation/Base/GetMockBase.php index b3cde8b2..cd5e24dc 100644 --- a/src/Rector/Deprecation/Base/GetMockBase.php +++ b/src/Rector/Deprecation/Base/GetMockBase.php @@ -3,7 +3,7 @@ namespace DrupalRector\Rector\Deprecation\Base; use PhpParser\Node; -use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\Core\Rector\AbstractRector; /** @@ -25,6 +25,15 @@ abstract class GetMockBase extends AbstractRector protected $baseClassBeingExtended; /** + * @var ParentClassScopeResolver + */ + protected $parentClassScopeResolver; + + public function __construct(ParentClassScopeResolver $parentClassScopeResolver) { + $this->parentClassScopeResolver = $parentClassScopeResolver; + } + + /** * @inheritdoc */ public function getNodeTypes(): array @@ -39,8 +48,16 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); /* @var Node\Expr\MethodCall $node */ - if ($this->getName($node->name) === 'getMock' && ($node->var instanceof Node\Expr\Variable) && $this->getName($node->var) === 'this' && $node->hasAttribute(AttributeKey::PARENT_CLASS_NAME) && $node->getAttribute(AttributeKey::PARENT_CLASS_NAME) === $this->baseClassBeingExtended) { + // This checks for a method call with the method name of `getMock` and that + // the variable calling `getMock` is `$this`, not some other variable call, + // such as `$myOtherService->getMock` and have unintended consequences. + if ($this->getName($node->name) === 'getMock' + && ($node->var instanceof Node\Expr\Variable) + && $this->getName($node->var) === 'this' + && $parentClassName === $this->baseClassBeingExtended + ) { // Build the arguments. $method_arguments = $node->args; diff --git a/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php b/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php index d0c21ff4..04d276b0 100644 --- a/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php +++ b/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\GetMockBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated getMock() calls in classes that extend BrowserTestBase. @@ -21,9 +21,9 @@ final class BrowserTestBaseGetMockRector extends GetMockBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated getMock() calls',[ + return new RuleDefinition('Fixes deprecated getMock() calls',[ new CodeSample( <<<'CODE_BEFORE' $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); diff --git a/src/Rector/Deprecation/DBDeleteRector.php b/src/Rector/Deprecation/DBDeleteRector.php index 6a8d9bb2..ec597dd2 100644 --- a/src/Rector/Deprecation/DBDeleteRector.php +++ b/src/Rector/Deprecation/DBDeleteRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_delete() calls. @@ -26,9 +26,9 @@ final class DBDeleteRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_insert() calls',[ + return new RuleDefinition('Fixes deprecated db_insert() calls',[ new CodeSample( <<<'CODE_BEFORE' db_delete($table, $options); diff --git a/src/Rector/Deprecation/DBInsertRector.php b/src/Rector/Deprecation/DBInsertRector.php index b518cfc9..df7a658d 100644 --- a/src/Rector/Deprecation/DBInsertRector.php +++ b/src/Rector/Deprecation/DBInsertRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_insert() calls. @@ -26,9 +26,9 @@ final class DBInsertRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_insert() calls',[ + return new RuleDefinition('Fixes deprecated db_insert() calls',[ new CodeSample( <<<'CODE_BEFORE' db_insert($table, $options); diff --git a/src/Rector/Deprecation/DBQueryRector.php b/src/Rector/Deprecation/DBQueryRector.php index 5a9c517f..79caf63c 100644 --- a/src/Rector/Deprecation/DBQueryRector.php +++ b/src/Rector/Deprecation/DBQueryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_query() calls. @@ -26,9 +26,9 @@ final class DBQueryRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_query() calls',[ + return new RuleDefinition('Fixes deprecated db_query() calls',[ new CodeSample( <<<'CODE_BEFORE' db_query($query, $args, $options); diff --git a/src/Rector/Deprecation/DBSelectRector.php b/src/Rector/Deprecation/DBSelectRector.php index 3154f31d..f3af7618 100644 --- a/src/Rector/Deprecation/DBSelectRector.php +++ b/src/Rector/Deprecation/DBSelectRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_select() calls. @@ -26,9 +26,9 @@ final class DBSelectRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_select() calls',[ + return new RuleDefinition('Fixes deprecated db_select() calls',[ new CodeSample( <<<'CODE_BEFORE' db_select($table, $alias, $options); diff --git a/src/Rector/Deprecation/DBUpdateRector.php b/src/Rector/Deprecation/DBUpdateRector.php index 81af6230..3e9940d8 100644 --- a/src/Rector/Deprecation/DBUpdateRector.php +++ b/src/Rector/Deprecation/DBUpdateRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_update() calls. @@ -26,9 +26,9 @@ final class DBUpdateRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_update() calls',[ + return new RuleDefinition('Fixes deprecated db_update() calls',[ new CodeSample( <<<'CODE_BEFORE' db_update($table, $options); diff --git a/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php b/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php index 55704552..4698a243 100644 --- a/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php +++ b/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated DATETIME_DATE_STORAGE_FORMAT constant use. @@ -29,9 +29,9 @@ final class DatetimeDateStorageFormatRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated DATETIME_DATE_STORAGE_FORMAT use',[ + return new RuleDefinition('Fixes deprecated DATETIME_DATE_STORAGE_FORMAT use',[ new CodeSample( <<<'CODE_BEFORE' use Drupal\Core\Datetime\DrupalDateTime; diff --git a/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php b/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php index b3b7be44..23e32506 100644 --- a/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php +++ b/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated DATETIME_DATETIME_STORAGE_FORMAT constant use. @@ -29,9 +29,9 @@ final class DatetimeDatetimeStorageFormatRector extends ConstantToClassConstantB /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated DATETIME_DATETIME_STORAGE_FORMAT use',[ + return new RuleDefinition('Fixes deprecated DATETIME_DATETIME_STORAGE_FORMAT use',[ new CodeSample( <<<'CODE_BEFORE' use Drupal\Core\Datetime\DrupalDateTime; diff --git a/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php b/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php index 92684591..cdd16699 100644 --- a/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php +++ b/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated DATETIME_STORAGE_TIMEZONE constant use. @@ -29,9 +29,9 @@ final class DatetimeStorageTimezoneRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated DATETIME_STORAGE_TIMEZONE use',[ + return new RuleDefinition('Fixes deprecated DATETIME_STORAGE_TIMEZONE use',[ new CodeSample( <<<'CODE_BEFORE' $timezone = new \DateTimeZone(DATETIME_STORAGE_TIMEZONE); diff --git a/src/Rector/Deprecation/DrupalLRector.php b/src/Rector/Deprecation/DrupalLRector.php index 96b0efcf..d13a568e 100644 --- a/src/Rector/Deprecation/DrupalLRector.php +++ b/src/Rector/Deprecation/DrupalLRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated \Drupal::l() calls. @@ -24,9 +24,9 @@ final class DrupalLRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal::l() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal::l() calls',[ new CodeSample( <<<'CODE_BEFORE' \Drupal::l('User Login', \Drupal\Core\Url::fromRoute('user.login')); diff --git a/src/Rector/Deprecation/DrupalRealpathRector.php b/src/Rector/Deprecation/DrupalRealpathRector.php index fa856247..4ba6cdb2 100644 --- a/src/Rector/Deprecation/DrupalRealpathRector.php +++ b/src/Rector/Deprecation/DrupalRealpathRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_realpath() calls. @@ -29,9 +29,9 @@ final class DrupalRealpathRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_realpath() calls',[ + return new RuleDefinition('Fixes deprecated drupal_realpath() calls',[ new CodeSample( <<<'CODE_BEFORE' $path = drupal_realpath($path); diff --git a/src/Rector/Deprecation/DrupalRenderRector.php b/src/Rector/Deprecation/DrupalRenderRector.php index c4d6159f..3ac92476 100644 --- a/src/Rector/Deprecation/DrupalRenderRector.php +++ b/src/Rector/Deprecation/DrupalRenderRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_render() calls. @@ -29,9 +29,9 @@ final class DrupalRenderRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_render() calls',[ + return new RuleDefinition('Fixes deprecated drupal_render() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = drupal_render($elements); diff --git a/src/Rector/Deprecation/DrupalRenderRootRector.php b/src/Rector/Deprecation/DrupalRenderRootRector.php index 236f1234..bb63cda5 100644 --- a/src/Rector/Deprecation/DrupalRenderRootRector.php +++ b/src/Rector/Deprecation/DrupalRenderRootRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_render_root() calls. @@ -29,9 +29,9 @@ final class DrupalRenderRootRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_render_root() calls',[ + return new RuleDefinition('Fixes deprecated drupal_render_root() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = drupal_render_root($elements); diff --git a/src/Rector/Deprecation/DrupalSetMessageRector.php b/src/Rector/Deprecation/DrupalSetMessageRector.php index 9cfd01ea..fc0a6e1e 100644 --- a/src/Rector/Deprecation/DrupalSetMessageRector.php +++ b/src/Rector/Deprecation/DrupalSetMessageRector.php @@ -7,8 +7,8 @@ use PhpParser\Node; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_set_message() calls. @@ -33,9 +33,9 @@ final class DrupalSetMessageRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_set_message() calls',[ + return new RuleDefinition('Fixes deprecated drupal_set_message() calls',[ new CodeSample( <<<'CODE_BEFORE' drupal_set_message('example status', 'status'); diff --git a/src/Rector/Deprecation/DrupalURLRector.php b/src/Rector/Deprecation/DrupalURLRector.php index 5ccc9b5d..b6f28a8a 100644 --- a/src/Rector/Deprecation/DrupalURLRector.php +++ b/src/Rector/Deprecation/DrupalURLRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated \Drupal::url() calls. @@ -34,9 +34,9 @@ public function getNodeTypes(): array /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal::url() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal::url() calls',[ new CodeSample( <<<'CODE_BEFORE' \Drupal::url('user.login'); diff --git a/src/Rector/Deprecation/EntityCreateRector.php b/src/Rector/Deprecation/EntityCreateRector.php index 65b29223..05e306a8 100644 --- a/src/Rector/Deprecation/EntityCreateRector.php +++ b/src/Rector/Deprecation/EntityCreateRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_create() calls. @@ -25,9 +25,9 @@ final class EntityCreateRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_create() calls',[ + return new RuleDefinition('Fixes deprecated entity_create() calls',[ new CodeSample( <<<'CODE_BEFORE' entity_create('node', ['bundle' => 'page', 'title' => 'Hello world']); diff --git a/src/Rector/Deprecation/EntityDeleteMultipleRector.php b/src/Rector/Deprecation/EntityDeleteMultipleRector.php index 0ddba833..0b2a2f28 100644 --- a/src/Rector/Deprecation/EntityDeleteMultipleRector.php +++ b/src/Rector/Deprecation/EntityDeleteMultipleRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_create() calls. @@ -25,9 +25,9 @@ final class EntityDeleteMultipleRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_delete_multiple() calls',[ + return new RuleDefinition('Fixes deprecated entity_delete_multiple() calls',[ new CodeSample( <<<'CODE_BEFORE' entity_delete_multiple('node', [1, 2, 42]); diff --git a/src/Rector/Deprecation/EntityGetDisplayRector.php b/src/Rector/Deprecation/EntityGetDisplayRector.php index 79a74502..5c37c33e 100644 --- a/src/Rector/Deprecation/EntityGetDisplayRector.php +++ b/src/Rector/Deprecation/EntityGetDisplayRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_get_display() calls. @@ -29,9 +29,9 @@ final class EntityGetDisplayRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_get_display() calls',[ + return new RuleDefinition('Fixes deprecated entity_get_display() calls',[ new CodeSample( <<<'CODE_BEFORE' $display = entity_get_display($entity_type, $bundle, $view_mode) diff --git a/src/Rector/Deprecation/EntityGetFormDisplayRector.php b/src/Rector/Deprecation/EntityGetFormDisplayRector.php index b7b0f873..d200d65a 100644 --- a/src/Rector/Deprecation/EntityGetFormDisplayRector.php +++ b/src/Rector/Deprecation/EntityGetFormDisplayRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_get_form_display() calls. @@ -29,9 +29,9 @@ final class EntityGetFormDisplayRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_get_form_display() calls',[ + return new RuleDefinition('Fixes deprecated entity_get_form_display() calls',[ new CodeSample( <<<'CODE_BEFORE' $display = entity_get_form_display($entity_type, $bundle, $form_mode) diff --git a/src/Rector/Deprecation/EntityInterfaceLinkRector.php b/src/Rector/Deprecation/EntityInterfaceLinkRector.php index 90ed208f..3e9b747a 100644 --- a/src/Rector/Deprecation/EntityInterfaceLinkRector.php +++ b/src/Rector/Deprecation/EntityInterfaceLinkRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Utility\AddCommentTrait; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use PhpParser\Node; use Rector\Core\Rector\AbstractRector; @@ -26,9 +26,9 @@ final class EntityInterfaceLinkRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated link() calls',[ + return new RuleDefinition('Fixes deprecated link() calls',[ new CodeSample( <<<'CODE_BEFORE' $url = $entity->link(); diff --git a/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php b/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php index 2a950ecf..b4d225f3 100644 --- a/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php +++ b/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\MethodToMethodBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated function call to EntityInterface::urlInfo. @@ -28,9 +28,9 @@ final class EntityInterfaceUrlInfoRector extends MethodToMethodBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated urlInfo() calls',[ + return new RuleDefinition('Fixes deprecated urlInfo() calls',[ new CodeSample( <<<'CODE_BEFORE' $url = $entity->urlInfo(); diff --git a/src/Rector/Deprecation/EntityLoadRector.php b/src/Rector/Deprecation/EntityLoadRector.php index 16120839..a2aa58e1 100644 --- a/src/Rector/Deprecation/EntityLoadRector.php +++ b/src/Rector/Deprecation/EntityLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated entity_load() calls. @@ -23,9 +23,9 @@ final class EntityLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_load() use',[ + return new RuleDefinition('Fixes deprecated entity_load() use',[ new CodeSample( <<<'CODE_BEFORE' $node = entity_load('node', 123); diff --git a/src/Rector/Deprecation/EntityManagerRector.php b/src/Rector/Deprecation/EntityManagerRector.php index 7326ae12..32bc36f1 100644 --- a/src/Rector/Deprecation/EntityManagerRector.php +++ b/src/Rector/Deprecation/EntityManagerRector.php @@ -4,10 +4,10 @@ use DrupalRector\Utility\AddCommentTrait; use PhpParser\Node; -use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated `\Drupal::entityManager()` calls. @@ -28,11 +28,20 @@ final class EntityManagerRector extends AbstractRector { use AddCommentTrait; + /** + * @var ParentClassScopeResolver + */ + protected $parentClassScopeResolver; + + public function __construct(ParentClassScopeResolver $parentClassScopeResolver) { + $this->parentClassScopeResolver = $parentClassScopeResolver; + } + /** * @inheritdoc */ - public function getDefinition(): RectorDefinition { - return new RectorDefinition('Fixes deprecated \Drupal::entityManager() calls',[ + public function getRuleDefinition(): RuleDefinition { + return new RuleDefinition('Fixes deprecated \Drupal::entityManager() calls',[ new CodeSample( <<<'CODE_BEFORE' $entity_manager = \Drupal::entityManager(); @@ -81,7 +90,8 @@ public function refactor(Node $node): ?Node { return $node; } - if ($node instanceof Node\Expr\MethodCall && $node->hasAttribute(AttributeKey::PARENT_CLASS_NAME) && $node->getAttribute(AttributeKey::PARENT_CLASS_NAME) === 'Drupal\Core\Controller\ControllerBase') { + $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); + if ($node instanceof Node\Expr\MethodCall && $parentClassName === 'Drupal\Core\Controller\ControllerBase') { // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. $next_node = $node->getAttribute('nextNode'); diff --git a/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php b/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php index e3565d4d..dcae4ac8 100644 --- a/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php +++ b/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\MethodToMethodBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated function call to EntityType::getLowercaseLabel(). @@ -42,9 +42,9 @@ final class EntityTypeGetLowercaseLabelRector extends MethodToMethodBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated EntityType::getLowercaseLabel()',[ + return new RuleDefinition('Fixes deprecated EntityType::getLowercaseLabel()',[ new CodeSample( <<<'CODE_BEFORE' /* @var \Drupal\node\Entity\Node $node */ diff --git a/src/Rector/Deprecation/FileCreateDirectoryRector.php b/src/Rector/Deprecation/FileCreateDirectoryRector.php index 0e1aa0b9..dcdab7a2 100644 --- a/src/Rector/Deprecation/FileCreateDirectoryRector.php +++ b/src/Rector/Deprecation/FileCreateDirectoryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_CREATE_DIRECTORY constant use. @@ -29,9 +29,9 @@ final class FileCreateDirectoryRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_CREATE_DIRECTORY use',[ + return new RuleDefinition('Fixes deprecated FILE_CREATE_DIRECTORY use',[ new CodeSample( <<<'CODE_BEFORE' $result = \Drupal::service('file_system')->prepareDirectory($directory, FILE_CREATE_DIRECTORY); diff --git a/src/Rector/Deprecation/FileDefaultSchemeRector.php b/src/Rector/Deprecation/FileDefaultSchemeRector.php index c2e5ad8f..3f9e3359 100644 --- a/src/Rector/Deprecation/FileDefaultSchemeRector.php +++ b/src/Rector/Deprecation/FileDefaultSchemeRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToImmutableConfigBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces the deprecated file_default_scheme function calls. @@ -22,9 +22,9 @@ final class FileDefaultSchemeRector extends FunctionToImmutableConfigBase /** * @inheritDoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_default_scheme calls',[ + return new RuleDefinition('Fixes deprecated file_default_scheme calls',[ new CodeSample( <<<'CODE_BEFORE' $file_default_scheme = file_default_scheme(); diff --git a/src/Rector/Deprecation/FileDirectoryOsTempRector.php b/src/Rector/Deprecation/FileDirectoryOsTempRector.php index 2850eb68..184a04d0 100644 --- a/src/Rector/Deprecation/FileDirectoryOsTempRector.php +++ b/src/Rector/Deprecation/FileDirectoryOsTempRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToStatic; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_directory_temp() calls. @@ -25,9 +25,9 @@ final class FileDirectoryOsTempRector extends FunctionToStatic /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_directory_temp() calls',[ + return new RuleDefinition('Fixes deprecated file_directory_temp() calls',[ new CodeSample( <<<'CODE_BEFORE' $dir = file_directory_os_temp(); diff --git a/src/Rector/Deprecation/FileDirectoryTempRector.php b/src/Rector/Deprecation/FileDirectoryTempRector.php index 5cd1c618..c2876cbf 100644 --- a/src/Rector/Deprecation/FileDirectoryTempRector.php +++ b/src/Rector/Deprecation/FileDirectoryTempRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_directory_temp() calls. @@ -28,9 +28,9 @@ final class FileDirectoryTempRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_directory_temp() calls',[ + return new RuleDefinition('Fixes deprecated file_directory_temp() calls',[ new CodeSample( <<<'CODE_BEFORE' $dir = file_directory_temp(); diff --git a/src/Rector/Deprecation/FileExistsRenameRector.php b/src/Rector/Deprecation/FileExistsRenameRector.php index a423b243..f5cf5e91 100644 --- a/src/Rector/Deprecation/FileExistsRenameRector.php +++ b/src/Rector/Deprecation/FileExistsRenameRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_EXISTS_RENAME constant use. @@ -29,9 +29,9 @@ final class FileExistsRenameRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_EXISTS_RENAME use',[ + return new RuleDefinition('Fixes deprecated FILE_EXISTS_RENAME use',[ new CodeSample( <<<'CODE_BEFORE' $result = file_unmanaged_copy($source, $destination, FILE_EXISTS_RENAME); diff --git a/src/Rector/Deprecation/FileExistsReplaceRector.php b/src/Rector/Deprecation/FileExistsReplaceRector.php index f9cf4de8..6395e392 100644 --- a/src/Rector/Deprecation/FileExistsReplaceRector.php +++ b/src/Rector/Deprecation/FileExistsReplaceRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_EXISTS_REPLACE constant use. @@ -29,9 +29,9 @@ final class FileExistsReplaceRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_EXISTS_REPLACE use',[ + return new RuleDefinition('Fixes deprecated FILE_EXISTS_REPLACE use',[ new CodeSample( <<<'CODE_BEFORE' $result = file_copy($file, $dest, FILE_EXISTS_REPLACE); diff --git a/src/Rector/Deprecation/FileLoadRector.php b/src/Rector/Deprecation/FileLoadRector.php index ffeb74e6..71603d3d 100644 --- a/src/Rector/Deprecation/FileLoadRector.php +++ b/src/Rector/Deprecation/FileLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated file_load() calls. @@ -24,9 +24,9 @@ final class FileLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_load() use',[ + return new RuleDefinition('Fixes deprecated file_load() use',[ new CodeSample( <<<'CODE_BEFORE' $file = file_load(123); diff --git a/src/Rector/Deprecation/FileModifyPermissionsRector.php b/src/Rector/Deprecation/FileModifyPermissionsRector.php index 65ba5d4a..d6eef514 100644 --- a/src/Rector/Deprecation/FileModifyPermissionsRector.php +++ b/src/Rector/Deprecation/FileModifyPermissionsRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_MODIFY_PERMISSIONS constant use. @@ -29,9 +29,9 @@ final class FileModifyPermissionsRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_MODIFY_PERMISSIONS use',[ + return new RuleDefinition('Fixes deprecated FILE_MODIFY_PERMISSIONS use',[ new CodeSample( <<<'CODE_BEFORE' $result = file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS); diff --git a/src/Rector/Deprecation/FilePrepareDirectoryRector.php b/src/Rector/Deprecation/FilePrepareDirectoryRector.php index c6b05a72..9364f97d 100644 --- a/src/Rector/Deprecation/FilePrepareDirectoryRector.php +++ b/src/Rector/Deprecation/FilePrepareDirectoryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_prepare_directory() calls. @@ -29,9 +29,9 @@ final class FilePrepareDirectoryRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_prepare_directory() calls',[ + return new RuleDefinition('Fixes deprecated file_prepare_directory() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = file_prepare_directory($directory, $options); diff --git a/src/Rector/Deprecation/FileScanDirectoryRector.php b/src/Rector/Deprecation/FileScanDirectoryRector.php index 847845c7..36a92f1f 100644 --- a/src/Rector/Deprecation/FileScanDirectoryRector.php +++ b/src/Rector/Deprecation/FileScanDirectoryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_scan_directory() calls. @@ -30,9 +30,9 @@ final class FileScanDirectoryRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_scan_directory() calls',[ + return new RuleDefinition('Fixes deprecated file_scan_directory() calls',[ new CodeSample( <<<'CODE_BEFORE' $files = file_scan_directory($directory); diff --git a/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php b/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php index f6f3d483..e1358afe 100644 --- a/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php +++ b/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_unmanaged_save_data() calls. @@ -29,9 +29,9 @@ final class FileUnmanagedSaveDataRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_unmanaged_save_data() calls',[ + return new RuleDefinition('Fixes deprecated file_unmanaged_save_data() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = file_unmanaged_save_data($data, $destination, $replace); diff --git a/src/Rector/Deprecation/FileUriTargetRector.php b/src/Rector/Deprecation/FileUriTargetRector.php index 5c5657d8..a6ecbe6a 100644 --- a/src/Rector/Deprecation/FileUriTargetRector.php +++ b/src/Rector/Deprecation/FileUriTargetRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_uri_target() calls. @@ -29,9 +29,9 @@ final class FileUriTargetRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_uri_target() calls',[ + return new RuleDefinition('Fixes deprecated file_uri_target() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = file_uri_target($uri) diff --git a/src/Rector/Deprecation/FormatDateRector.php b/src/Rector/Deprecation/FormatDateRector.php index 6d00d068..7cd65605 100644 --- a/src/Rector/Deprecation/FormatDateRector.php +++ b/src/Rector/Deprecation/FormatDateRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated format_date() calls. @@ -29,9 +29,9 @@ final class FormatDateRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated format_date() calls',[ + return new RuleDefinition('Fixes deprecated format_date() calls', [ new CodeSample( <<<'CODE_BEFORE' $date = format_date($timestamp, $type, $format, $timezone, $langcode); diff --git a/src/Rector/Deprecation/KernelTestBaseGetMockRector.php b/src/Rector/Deprecation/KernelTestBaseGetMockRector.php index 194c868b..902de3af 100644 --- a/src/Rector/Deprecation/KernelTestBaseGetMockRector.php +++ b/src/Rector/Deprecation/KernelTestBaseGetMockRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\GetMockBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated getMock() calls in classes that extend KernelTestBase. @@ -21,9 +21,9 @@ final class KernelTestBaseGetMockRector extends GetMockBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated getMock() calls',[ + return new RuleDefinition('Fixes deprecated getMock() calls', [ new CodeSample( <<<'CODE_BEFORE' $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); diff --git a/src/Rector/Deprecation/LinkGeneratorTraitLRector.php b/src/Rector/Deprecation/LinkGeneratorTraitLRector.php index f54b4a92..c9ebd4de 100644 --- a/src/Rector/Deprecation/LinkGeneratorTraitLRector.php +++ b/src/Rector/Deprecation/LinkGeneratorTraitLRector.php @@ -7,8 +7,8 @@ use PhpParser\Node; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated \Drupal\Core\Routing\LinkGeneratorTrait::l() calls. @@ -29,9 +29,9 @@ final class LinkGeneratorTraitLRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated l() calls',[ + return new RuleDefinition('Fixes deprecated l() calls',[ new CodeSample( <<<'CODE_BEFORE' $this->l($text, $url); diff --git a/src/Rector/Deprecation/NodeLoadRector.php b/src/Rector/Deprecation/NodeLoadRector.php index 7805c3ac..8bbb56e6 100644 --- a/src/Rector/Deprecation/NodeLoadRector.php +++ b/src/Rector/Deprecation/NodeLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated node_load() calls. @@ -24,9 +24,9 @@ final class NodeLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated node_load() use',[ + return new RuleDefinition('Fixes deprecated node_load() use',[ new CodeSample( <<<'CODE_BEFORE' $node = node_load(123); diff --git a/src/Rector/Deprecation/RequestTimeConstRector.php b/src/Rector/Deprecation/RequestTimeConstRector.php index 56c51625..04f7a5cc 100644 --- a/src/Rector/Deprecation/RequestTimeConstRector.php +++ b/src/Rector/Deprecation/RequestTimeConstRector.php @@ -6,8 +6,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; class RequestTimeConstRector extends AbstractRector { @@ -40,9 +40,9 @@ public function refactor(Node $node): ?Node /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated REQUEST_TIME calls',[ + return new RuleDefinition('Fixes deprecated REQUEST_TIME calls',[ new CodeSample( <<<'CODE_BEFORE' $request_time = REQUEST_TIME; diff --git a/src/Rector/Deprecation/SafeMarkupFormatRector.php b/src/Rector/Deprecation/SafeMarkupFormatRector.php index 518f4094..b86e5b8d 100644 --- a/src/Rector/Deprecation/SafeMarkupFormatRector.php +++ b/src/Rector/Deprecation/SafeMarkupFormatRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated SafeMarkup::format() calls. @@ -23,9 +23,9 @@ final class SafeMarkupFormatRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated SafeMarkup::format() calls',[ + return new RuleDefinition('Fixes deprecated SafeMarkup::format() calls',[ new CodeSample( <<<'CODE_BEFORE' $safe_string_markup_object = \Drupal\Component\Utility\SafeMarkup::format('hello world'); @@ -58,9 +58,7 @@ public function refactor(Node $node): ?Node $class = new Node\Name\FullyQualified('Drupal\Component\Render\FormattableMarkup'); - $new_node = new Node\Expr\New_($class, $node->args); - - return $new_node; + return new Node\Expr\New_($class, $node->args); } return null; diff --git a/src/Rector/Deprecation/UnicodeStrlenRector.php b/src/Rector/Deprecation/UnicodeStrlenRector.php index eea8e4e2..faa32464 100644 --- a/src/Rector/Deprecation/UnicodeStrlenRector.php +++ b/src/Rector/Deprecation/UnicodeStrlenRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\StaticToFunctionBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated Unicode::strlen() calls. @@ -26,9 +26,9 @@ final class UnicodeStrlenRector extends StaticToFunctionBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strlen() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strlen() calls',[ new CodeSample( <<<'CODE_BEFORE' $length = \Drupal\Component\Utility\Unicode::strlen('example'); diff --git a/src/Rector/Deprecation/UnicodeStrtolowerRector.php b/src/Rector/Deprecation/UnicodeStrtolowerRector.php index bea42b63..c764f7c5 100644 --- a/src/Rector/Deprecation/UnicodeStrtolowerRector.php +++ b/src/Rector/Deprecation/UnicodeStrtolowerRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\StaticToFunctionBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated Unicode::strtolower() calls. @@ -26,9 +26,9 @@ final class UnicodeStrtolowerRector extends StaticToFunctionBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strtolower() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strtolower() calls',[ new CodeSample( <<<'CODE_BEFORE' $string = \Drupal\Component\Utility\Unicode::strtolower('example'); diff --git a/src/Rector/Deprecation/UnicodeSubstrRector.php b/src/Rector/Deprecation/UnicodeSubstrRector.php index 3abeff1b..8e6504bb 100644 --- a/src/Rector/Deprecation/UnicodeSubstrRector.php +++ b/src/Rector/Deprecation/UnicodeSubstrRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\StaticToFunctionBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated Unicode::substr() calls. @@ -26,9 +26,9 @@ final class UnicodeSubstrRector extends StaticToFunctionBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::substr() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::substr() calls',[ new CodeSample( <<<'CODE_BEFORE' $string = \Drupal\Component\Utility\Unicode::substr('example', 0, 2); diff --git a/src/Rector/Deprecation/UnitTestCaseGetMockRector.php b/src/Rector/Deprecation/UnitTestCaseGetMockRector.php index 66c87ca2..e983c64e 100644 --- a/src/Rector/Deprecation/UnitTestCaseGetMockRector.php +++ b/src/Rector/Deprecation/UnitTestCaseGetMockRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\GetMockBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated getMock() calls in classes that extend UnitTestCase. @@ -21,9 +21,9 @@ final class UnitTestCaseGetMockRector extends GetMockBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated getMock() calls',[ + return new RuleDefinition('Fixes deprecated getMock() calls',[ new CodeSample( <<<'CODE_BEFORE' $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); diff --git a/src/Rector/Deprecation/UserLoadRector.php b/src/Rector/Deprecation/UserLoadRector.php index f201213c..158bbebd 100644 --- a/src/Rector/Deprecation/UserLoadRector.php +++ b/src/Rector/Deprecation/UserLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated user_load() calls. @@ -24,9 +24,9 @@ final class UserLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated user_load() use',[ + return new RuleDefinition('Fixes deprecated user_load() use',[ new CodeSample( <<<'CODE_BEFORE' $user = user_load(123); From 541584c20f7c461eefe28e2fdadced52c983e19a Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 24 Mar 2021 15:36:26 -0500 Subject: [PATCH 07/64] Fix remaining usages of Option::EXCLUDE_PATHS Also adds PHPStan workflow to catch unused calls. --- .github/workflows/packagist_package_run_rector.yml | 3 +-- phpstan.neon | 6 ++++++ rector-config-docroot-dir.php | 2 +- rector-config-web-dir.php | 2 +- rector.php | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/packagist_package_run_rector.yml b/.github/workflows/packagist_package_run_rector.yml index 403b0816..8af45450 100644 --- a/.github/workflows/packagist_package_run_rector.yml +++ b/.github/workflows/packagist_package_run_rector.yml @@ -1,8 +1,7 @@ name: packagist_package_run_rector -# This test will run on every pull request, and on every commit that is pushed to master +# This test will run on every commit that is pushed to master on: - pull_request: null push: branches: - master diff --git a/phpstan.neon b/phpstan.neon index 7229da62..d8ec9e9d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,2 +1,8 @@ parameters: level: 0 + paths: + - config + - src + - rector.php + - rector-config-docroot-dir.php + - rector-config-web-dir.php diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php index 554d7be4..08f38d03 100644 --- a/rector-config-docroot-dir.php +++ b/rector-config-docroot-dir.php @@ -11,7 +11,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/core/modules', 'docroot/modules', 'docroot/profiles']); - $parameters->set(Option::EXCLUDE_PATHS, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php index 875e5e43..327bbac9 100644 --- a/rector-config-web-dir.php +++ b/rector-config-web-dir.php @@ -10,7 +10,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); - $parameters->set(Option::EXCLUDE_PATHS, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); diff --git a/rector.php b/rector.php index e180bb43..3a03eb92 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); - $parameters->set(Option::EXCLUDE_PATHS, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); From f29c567b803db22141dc3fd84becff1cc35ba415 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 24 Mar 2021 15:37:19 -0500 Subject: [PATCH 08/64] PHPStan workflow to catch unused calls. --- .github/workflows/phpstan.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/phpstan.yml diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..69cd59d5 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,17 @@ +name: phpstan +on: [push, pull_request] +jobs: + phpstan_analyze: + name: PHPStan Analyze + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + extensions: "intl" + - run: | + # Install local packages, including Behat + composer install + - run: vendor/bin/phpstan From 669038dc9fe690dd237fb02771910fe52b0baa32 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Sun, 28 Mar 2021 10:38:35 -0500 Subject: [PATCH 09/64] Add PHPUnit and initial test --- .gitignore | 2 + composer.json | 6 +++ phpunit.xml | 26 +++++++++++++ .../DatetimeStorageTimezoneRectorTest.php | 37 +++++++++++++++++++ .../config/configured_rule.php | 12 ++++++ .../fixture/fixture.php.inc | 21 +++++++++++ 6 files changed, 104 insertions(+) create mode 100644 phpunit.xml create mode 100644 tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php create mode 100644 tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php create mode 100644 tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc diff --git a/.gitignore b/.gitignore index f861eff1..fe60fb89 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ /features/tmp/* !/features/tmp/.placeholder + +/.phpunit.cache diff --git a/composer.json b/composer.json index d3d759f3..77d1f6b7 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,11 @@ "DrupalRector\\": "src" } }, + "autoload-dev": { + "psr-4": { + "DrupalRector\\Tests\\": "tests/src" + } + }, "config": { "optimize-autoloader": true, "update-with-dependencies": true, @@ -49,6 +54,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^0.12.82", "phpstan/phpstan-deprecation-rules": "^0.12.6", + "phpunit/phpunit": "^9.5", "rector/rector": "~0.10.0" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..21d3ddc5 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + tests + + + + + + src + + + diff --git a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php new file mode 100644 index 00000000..d9f2c058 --- /dev/null +++ b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php @@ -0,0 +1,37 @@ +doTestFileInfo($fileInfo); + } + + /** + * @return Iterator + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/fixture'); + } + + public function provideConfigFilePath(): string + { + // must be implemented + return __DIR__ . '/config/configured_rule.php'; + } + +} diff --git a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php new file mode 100644 index 00000000..a6a0a21d --- /dev/null +++ b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php @@ -0,0 +1,12 @@ +services(); + + $services->set(DatetimeStorageTimezoneRector::class); +}; diff --git a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc new file mode 100644 index 00000000..d10ece7c --- /dev/null +++ b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc @@ -0,0 +1,21 @@ + +----- + From 7c81ed49890571d3f9ee1430b15d7240ad229c51 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Sun, 28 Mar 2021 11:49:59 -0500 Subject: [PATCH 10/64] Update local packages flow --- .../local_package_functional_tests.yml | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml index 6c352fc1..8e15788d 100644 --- a/.github/workflows/local_package_functional_tests.yml +++ b/.github/workflows/local_package_functional_tests.yml @@ -14,46 +14,40 @@ jobs: with: php-version: 7.3 coverage: none # disable xdebug, pcov - extensions: "intl" + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv # This is copied from `local_package_run_rector`. - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 ../drupal --no-progress - mv ../drupal/* .. - - # This is copied from `local_package_run_rector`. - - run: | - # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) - cd .. - composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' + - name: Setup Drupal + run: | + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction + cd ~/drupal + composer config minimum-stability dev + composer config prefer-stable true + composer config preferred-install dist + composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" + composer config repositories.1 composer https://packages.drupal.org/8 + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies + - run: | + cd ~/drupal composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress # This is copied from `local_package_run_rector`. - run: | # Prepare rector config files with Drupal specific settings - cd .. + cd ~/drupal cp vendor/palantirnet/drupal-rector/rector.php . - # This is copied from `local_package_run_rector`. - # This seems needed for the autoloading to work. - run: | # Prepare rector_examples folder in the drupal modules directory - cd .. + cd ~/drupal mkdir -p web/modules/custom cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - run: | - # Install phpunit/phpunit on the Drupal site since it's needed for some of our examples. - cd .. - composer require phpunit/phpunit:~7.5 - - run: | # Install local packages, including Behat composer install - # - uses: mxschmitt/action-tmate@v2 - - run: | # Run Behat vendor/bin/behat From ece4915feef13d1086d06483244b8b23630741db Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Sun, 28 Mar 2021 12:03:11 -0500 Subject: [PATCH 11/64] Handle ~/drupal in specific workflow --- .github/workflows/local_package_functional_tests.yml | 2 +- .github/workflows/local_package_run_rector.yml | 2 +- features/bootstrap/FeatureContext.php | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml index 8e15788d..6e672fef 100644 --- a/.github/workflows/local_package_functional_tests.yml +++ b/.github/workflows/local_package_functional_tests.yml @@ -30,7 +30,7 @@ jobs: COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - run: | cd ~/drupal - composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress + composer require palantirnet/drupal-rector:@dev --no-progress # This is copied from `local_package_run_rector`. - run: | diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index f3418164..75190c0d 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -29,7 +29,7 @@ jobs: # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) cd .. composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' - composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress + composer require palantirnet/drupal-rector:@dev --no-progress - run: | # Prepare rector config files with Drupal specific settings diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 511b8a53..01e86994 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -69,7 +69,12 @@ public function iRunDrupalRectorOnTheTest() { * @When I run Drupal Rector on the file/folder :path */ public function iRunDrupalRectorOnThe($path) { - chdir('..'); + $githubWorkflow = $_ENV['GITHUB_WORKFLOW'] ?? ''; + if ($githubWorkflow === 'local_package_functional_tests') { + chdir('~/drupal'); + } else { + chdir('..'); + } $output = NULL; $return_value = NULL; From d76341689381b7bf1228eed66fd94e4668c7e0c7 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Sun, 28 Mar 2021 12:07:38 -0500 Subject: [PATCH 12/64] Normalize GitHub flows --- .../workflows/local_package_run_rector.yml | 34 +++++++++---------- features/bootstrap/FeatureContext.php | 7 +--- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index 75190c0d..fabe40dd 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -14,35 +14,35 @@ jobs: with: php-version: 7.3 coverage: none # disable xdebug, pcov - extensions: "intl" - -# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started -# - name: Debugging with tmate -# uses: mxschmitt/action-tmate@v2 - - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 ../drupal --no-progress - mv ../drupal/* .. - + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + + - name: Setup Drupal + run: | + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction + cd ~/drupal + composer config minimum-stability dev + composer config prefer-stable true + composer config preferred-install dist + composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" + composer config repositories.1 composer https://packages.drupal.org/8 + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - run: | - # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) - cd .. - composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' + cd ~/drupal composer require palantirnet/drupal-rector:@dev --no-progress - run: | # Prepare rector config files with Drupal specific settings - cd .. + cd ~/drupal cp vendor/palantirnet/drupal-rector/rector.php . - run: | # Prepare rector_examples folder in the drupal modules directory - cd .. + cd ~/drupal mkdir -p web/modules/custom cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - run: | # Run Rector - cd .. + cd ~/drupal vendor/bin/rector process web/modules/custom/rector_examples diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 01e86994..8dded45c 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -69,12 +69,7 @@ public function iRunDrupalRectorOnTheTest() { * @When I run Drupal Rector on the file/folder :path */ public function iRunDrupalRectorOnThe($path) { - $githubWorkflow = $_ENV['GITHUB_WORKFLOW'] ?? ''; - if ($githubWorkflow === 'local_package_functional_tests') { - chdir('~/drupal'); - } else { - chdir('..'); - } + chdir('~/drupal'); $output = NULL; $return_value = NULL; From f72dfaaa29a707e80f1648730e1035ec1f1c7982 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Sun, 28 Mar 2021 21:26:03 -0500 Subject: [PATCH 13/64] Add PHPUnit flow, move deprecation-index tests to PHPUnit --- .github/workflows/phpstan.yml | 7 ++-- .github/workflows/phpunit.yml | 17 +++++++++ .gitignore | 1 + features/bootstrap/FeatureContext.php | 33 +----------------- features/deprecation-index.feature | 15 -------- phpunit.xml | 7 ++-- tests/config/rector-phpunit.php | 32 +++++++++++++++++ tests/src/DeprecationIndexTest.php | 27 +++++++++++++++ tests/src/DrupalIntegrationTest.php | 50 +++++++++++++++++++++++++++ 9 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/phpunit.yml delete mode 100644 features/deprecation-index.feature create mode 100644 tests/config/rector-phpunit.php create mode 100644 tests/src/DeprecationIndexTest.php create mode 100644 tests/src/DrupalIntegrationTest.php diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 69cd59d5..75915a5d 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -10,8 +10,7 @@ jobs: with: php-version: 7.3 coverage: none # disable xdebug, pcov - extensions: "intl" - - run: | - # Install local packages, including Behat - composer install + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + - run: composer install - run: vendor/bin/phpstan diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 00000000..3fc50249 --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,17 @@ +name: phpunit +on: [push, pull_request] +jobs: + phpunit: + name: PHPUnit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + - run: composer install + - run: composer create-project drupal/recommended-project:^8.9 tests/fixtures/drupal + - run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index fe60fb89..9106b4b4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ !/features/tmp/.placeholder /.phpunit.cache +/tests/fixtures/drupal diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 8dded45c..3e32692d 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -69,7 +69,7 @@ public function iRunDrupalRectorOnTheTest() { * @When I run Drupal Rector on the file/folder :path */ public function iRunDrupalRectorOnThe($path) { - chdir('~/drupal'); + chdir('../drupal'); $output = NULL; $return_value = NULL; @@ -129,35 +129,4 @@ public function theTestMatches($path) { } } - /** - * @When I examine the :file file - */ - public function iExamineTheFile($file) { - $this->examinedFileContents = file_get_contents($file); - - if ($this->examinedFileContents === FALSE) { - throw new Exception("The file $file could not be read."); - } - } - - /** - * @Then The file is valid YAML - */ - public function theFileIsValidYaml() { - try { - $parsed_data = Yaml::parse($this->examinedFileContents); - } - catch (ParseException $exception) { - throw new Exception("The YAML was not valid. This is often caused by unescaped quotes. Please use `'` to escape a single quote.\n\n{$exception->getMessage()}"); - } - } - - /** - * @Then The file only uses ASCII characters. - */ - public function theFileOnlyHasASCIICharacters() { - if (mb_detect_encoding($this->examinedFileContents, 'ASCII', TRUE) === FALSE) { - throw new Exception('The file contains non ASCII characters. Please make sure `\` and spaces are only using ASCII characters.'); - } - } } diff --git a/features/deprecation-index.feature b/features/deprecation-index.feature deleted file mode 100644 index cac25508..00000000 --- a/features/deprecation-index.feature +++ /dev/null @@ -1,15 +0,0 @@ -Feature: deprecation-index.yml - As a Drupal developer - I want the deprecation-index.yml file to parse cleanly - So that other systems can reference this file - - # Most often, quotes are not escaped. - Scenario: deprecation-index.yml is valid YAML - When I examine the "deprecation-index.yml" file - Then The file is valid YAML - - # Unicode characters sometimes get added when copy & pasting. - # They are not intended and don't match as easily. - Scenario: deprecation-index.yml only uses ASCII characters - When I examine the "deprecation-index.yml" file - Then The file only uses ASCII characters. diff --git a/phpunit.xml b/phpunit.xml index 21d3ddc5..23cf6f69 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,19 +4,18 @@ bootstrap="vendor/autoload.php" cacheResultFile=".phpunit.cache/test-results" executionOrder="depends,defects" - forceCoversAnnotation="true" - beStrictAboutCoversAnnotation="true" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" + colors="true" failOnRisky="true" failOnWarning="true" verbose="true"> - tests + tests/src + tests/fixtures - diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php new file mode 100644 index 00000000..fda13e9f --- /dev/null +++ b/tests/config/rector-phpunit.php @@ -0,0 +1,32 @@ +import(__DIR__ . '/../../config/drupal-8/drupal-8-all-deprecations.php'); + + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::AUTOLOAD_PATHS, [ + __DIR__ . '/../fixtures/drupal/web/core', + __DIR__ . '/../fixtures/drupal/web/core/modules', + __DIR__ . '/../fixtures/drupal/web/modules', + __DIR__ . '/../fixtures/drupal/web/profiles' + ]); + + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + $parameters->set(Option::IMPORT_DOC_BLOCKS, false); + + $parameters->set('drupal_rector_notices_as_comments', true); +}; diff --git a/tests/src/DeprecationIndexTest.php b/tests/src/DeprecationIndexTest.php new file mode 100644 index 00000000..21163958 --- /dev/null +++ b/tests/src/DeprecationIndexTest.php @@ -0,0 +1,27 @@ +provide(); + }; + $bootstrapConfigs = $callable(); + + $rectorContainerFactory = new RectorContainerFactory(); + $container = $rectorContainerFactory->createFromBootstrapConfigs($bootstrapConfigs); + + /** @var ConsoleApplication $application */ + $application = $container->get(ConsoleApplication::class); + $command = $application->find('process'); + $commandTester = new CommandTester($command); + + ob_start(); + $commandTester->execute([ + 'source' => __DIR__ . '/../../rector_examples/datetime_date_storage_format.php', + '--dry-run' => true, + '--output-format' => 'json', + ], [ + 'capture_stderr_separately' => true, + 'decorated' => true, + 'verbosity' => OutputInterface::VERBOSITY_DEBUG + ]); + $output = json_decode(ob_get_clean()); + self::assertContains(DatetimeDateStorageFormatRector::class, $output->file_diffs[0]->applied_rectors); + self::assertContains('rector_examples/datetime_date_storage_format.php', $output->changed_files); + } + +} From dcb66fff25ecb475c6facfcf19d51b645edd2775 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Sun, 28 Mar 2021 21:49:10 -0500 Subject: [PATCH 14/64] Move away from Behat and to specific commands --- .../local_package_functional_tests.yml | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml index 6e672fef..eef5cc2d 100644 --- a/.github/workflows/local_package_functional_tests.yml +++ b/.github/workflows/local_package_functional_tests.yml @@ -17,7 +17,6 @@ jobs: tools: composer:v2 extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - # This is copied from `local_package_run_rector`. - name: Setup Drupal run: | COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction @@ -28,26 +27,30 @@ jobs: composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" composer config repositories.1 composer https://packages.drupal.org/8 COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - - run: | + - name: Install drupal-rector + run: | cd ~/drupal composer require palantirnet/drupal-rector:@dev --no-progress - # This is copied from `local_package_run_rector`. - - run: | - # Prepare rector config files with Drupal specific settings + - name: Copy rector config + run: | cd ~/drupal cp vendor/palantirnet/drupal-rector/rector.php . + cat rector.php - - run: | - # Prepare rector_examples folder in the drupal modules directory + - name: Prepare rector_examples folder in the drupal modules directory + run: | cd ~/drupal mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Install local packages, including Behat - composer install + mv vendor/palantirnet/drupal-rector/rector_examples web/modules/custom + ls -la web/modules/custom/rector_examples - - run: | - # Run Behat - vendor/bin/behat + - name: Run rector against Drupal (dry-run) + run: | + cd ~/drupal + vendor/bin/rector process web/modules/custom/rector_examples --dry-run --debug + - name: Run rector against Drupal + run: | + cd ~/drupal + vendor/bin/rector process web/modules/custom/rector_examples --debug + - run: diff -rubB rector_examples_updated ~/drupal/web/modules/custom/rector_examples From 41e95875699899166a253a23c14f906b82254cb3 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Mon, 29 Mar 2021 10:26:14 -0500 Subject: [PATCH 15/64] Must add php suffix --- rector-config-docroot-dir.php | 2 +- rector-config-web-dir.php | 2 +- rector.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php index 08f38d03..24379fd0 100644 --- a/rector-config-docroot-dir.php +++ b/rector-config-docroot-dir.php @@ -12,7 +12,7 @@ $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/core/modules', 'docroot/modules', 'docroot/profiles']); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); $parameters->set(Option::IMPORT_DOC_BLOCKS, false); diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php index 327bbac9..a4088ed9 100644 --- a/rector-config-web-dir.php +++ b/rector-config-web-dir.php @@ -11,7 +11,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); $parameters->set(Option::IMPORT_DOC_BLOCKS, false); diff --git a/rector.php b/rector.php index 3a03eb92..584125b5 100644 --- a/rector.php +++ b/rector.php @@ -12,7 +12,7 @@ $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); $parameters->set(Option::IMPORT_DOC_BLOCKS, false); From 6a58e12cb6a4393be011170bd10dfbb924f7b14e Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Mon, 29 Mar 2021 12:13:43 -0500 Subject: [PATCH 16/64] Run with debug, remove duplicated core discovery --- .github/workflows/local_package_run_rector.yml | 2 +- rector-config-docroot-dir.php | 2 +- rector-config-web-dir.php | 2 +- rector.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index fabe40dd..98f355e4 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -45,4 +45,4 @@ jobs: - run: | # Run Rector cd ~/drupal - vendor/bin/rector process web/modules/custom/rector_examples + vendor/bin/rector process web/modules/custom/rector_examples --debug diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php index 24379fd0..902a8ab3 100644 --- a/rector-config-docroot-dir.php +++ b/rector-config-docroot-dir.php @@ -10,7 +10,7 @@ $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/core/modules', 'docroot/modules', 'docroot/profiles']); + $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/modules', 'docroot/profiles', 'docroot/themes']); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php index a4088ed9..9f12b603 100644 --- a/rector-config-web-dir.php +++ b/rector-config-web-dir.php @@ -9,7 +9,7 @@ $containerConfigurator->import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); + $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/rector.php b/rector.php index 584125b5..b17a09a2 100644 --- a/rector.php +++ b/rector.php @@ -9,7 +9,7 @@ $containerConfigurator->import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/core/modules', 'web/modules', 'web/profiles']); + $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); From c1d9e48059469c1bc318db28fcbe9b5ec08c9d53 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 7 Apr 2021 14:57:27 -0500 Subject: [PATCH 17/64] Add missing 8.4 deprecation Rector rules config --- config/drupal-8/drupal-8.4-deprecations.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 config/drupal-8/drupal-8.4-deprecations.php diff --git a/config/drupal-8/drupal-8.4-deprecations.php b/config/drupal-8/drupal-8.4-deprecations.php new file mode 100644 index 00000000..092bf186 --- /dev/null +++ b/config/drupal-8/drupal-8.4-deprecations.php @@ -0,0 +1,13 @@ +services(); + + $services->set(\DrupalRector\Rector\Deprecation\BrowserTestBaseGetMockRector::class); + $services->set(\DrupalRector\Rector\Deprecation\KernelTestBaseGetMockRector::class); + $services->set(\DrupalRector\Rector\Deprecation\UnitTestCaseGetMockRector::class); +}; From 4f4c56a9860065f04ad614aa3e7e0ce20115cdf2 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 7 Apr 2021 15:29:19 -0500 Subject: [PATCH 18/64] Ensure we load the PHPUnit bootstrap for test class autoloading --- rector-config-docroot-dir.php | 1 + rector-config-web-dir.php | 1 + rector.php | 1 + 3 files changed, 3 insertions(+) diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php index 902a8ab3..2a85c9a3 100644 --- a/rector-config-docroot-dir.php +++ b/rector-config-docroot-dir.php @@ -11,6 +11,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/modules', 'docroot/profiles', 'docroot/themes']); + require_once __DIR__ . '/docroot/core/tests/bootstrap.php'; $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php index 9f12b603..8e22ce28 100644 --- a/rector-config-web-dir.php +++ b/rector-config-web-dir.php @@ -10,6 +10,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); + require_once __DIR__ . '/web/core/tests/bootstrap.php'; $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/rector.php b/rector.php index b17a09a2..b2a10a85 100644 --- a/rector.php +++ b/rector.php @@ -10,6 +10,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); + require_once __DIR__ . '/web/core/tests/bootstrap.php'; $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); From 0eb9c3864b603bc4d028ab7bc01bd86f98817034 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 7 Apr 2021 15:30:38 -0500 Subject: [PATCH 19/64] Update the integration test --- tests/config/rector-phpunit.php | 4 +-- tests/src/DrupalIntegrationTest.php | 42 +++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php index fda13e9f..31da4562 100644 --- a/tests/config/rector-phpunit.php +++ b/tests/config/rector-phpunit.php @@ -21,9 +21,9 @@ __DIR__ . '/../fixtures/drupal/web/modules', __DIR__ . '/../fixtures/drupal/web/profiles' ]); - + require_once __DIR__ . '/../fixtures/drupal/web/core/tests/bootstrap.php'; $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::IMPORT_SHORT_CLASSES, false); $parameters->set(Option::IMPORT_DOC_BLOCKS, false); diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index 7ea1194f..bf6448d6 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -3,6 +3,7 @@ namespace DrupalRector\Tests; use DrupalRector\Rector\Deprecation\DatetimeDateStorageFormatRector; +use DrupalRector\Rector\Deprecation\FileCreateDirectoryRector; use PHPUnit\Framework\TestCase; use Rector\Core\Bootstrap\RectorConfigsResolver; use Rector\Core\Console\ConsoleApplication; @@ -12,11 +13,30 @@ final class DrupalIntegrationTest extends TestCase { - public function testIntegration() { + protected function setUp(): void + { + parent::setUp(); + if (!file_exists(__DIR__ . '/../fixtures/drupal/composer.json')) { + self::markTestSkipped(<< __DIR__ . '/../../rector_examples/datetime_date_storage_format.php', + 'source' => $source, '--dry-run' => true, '--output-format' => 'json', ], [ @@ -43,8 +63,20 @@ public function testIntegration() { 'verbosity' => OutputInterface::VERBOSITY_DEBUG ]); $output = json_decode(ob_get_clean()); - self::assertContains(DatetimeDateStorageFormatRector::class, $output->file_diffs[0]->applied_rectors); - self::assertContains('rector_examples/datetime_date_storage_format.php', $output->changed_files); + self::assertObjectNotHasAttribute('errors', $output, var_export($output, true)); + self::assertObjectHasAttribute('file_diffs', $output); + self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); + } + + public function integrationData(): \Generator { + yield [ + __DIR__ . '/../../rector_examples/datetime_date_storage_format.php', + [DatetimeDateStorageFormatRector::class] + ]; + yield [ + __DIR__ . '/../../rector_examples/src/FileCreateDirectoryNoUseStatement.php', + [FileCreateDirectoryRector::class] + ]; } } From bfacd7d4d5290d6b2a65f5fd7c2f77dc0f1ff625 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 7 Apr 2021 15:37:27 -0500 Subject: [PATCH 20/64] Expect dry-run exit code 1 --- .github/workflows/local_package_functional_tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml index eef5cc2d..9dedc749 100644 --- a/.github/workflows/local_package_functional_tests.yml +++ b/.github/workflows/local_package_functional_tests.yml @@ -45,10 +45,11 @@ jobs: mv vendor/palantirnet/drupal-rector/rector_examples web/modules/custom ls -la web/modules/custom/rector_examples + # dry-run is expected to return exit code 1 if there are changes, which we are expecting to happen, here. - name: Run rector against Drupal (dry-run) run: | cd ~/drupal - vendor/bin/rector process web/modules/custom/rector_examples --dry-run --debug + vendor/bin/rector process web/modules/custom/rector_examples --dry-run --debug || if (($? == 1)); then true; else false; fi - name: Run rector against Drupal run: | cd ~/drupal From 3bea584e2d80f45336cdba500088a191a95e9e31 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 7 Apr 2021 15:38:17 -0500 Subject: [PATCH 21/64] Remove phpunit bootstrap --- tests/config/rector-phpunit.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php index 31da4562..72b7d482 100644 --- a/tests/config/rector-phpunit.php +++ b/tests/config/rector-phpunit.php @@ -21,7 +21,8 @@ __DIR__ . '/../fixtures/drupal/web/modules', __DIR__ . '/../fixtures/drupal/web/profiles' ]); - require_once __DIR__ . '/../fixtures/drupal/web/core/tests/bootstrap.php'; + // @todo this crashes PHPUnit but fixes Drupal's test namespace autoloading. + // require_once __DIR__ . '/../fixtures/drupal/web/core/tests/bootstrap.php'; $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); From 1d08f2babb300c8243de803fb77a26d3b74eb9f5 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 7 Apr 2021 17:02:11 -0500 Subject: [PATCH 22/64] Update examples_updated for db_* --- rector_examples_updated/db_delete.php | 3 ++- rector_examples_updated/db_insert.php | 3 ++- rector_examples_updated/db_query.php | 9 +++++++-- rector_examples_updated/db_select.php | 3 ++- rector_examples_updated/db_update.php | 3 ++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rector_examples_updated/db_delete.php b/rector_examples_updated/db_delete.php index cf3034dd..668a54ad 100644 --- a/rector_examples_updated/db_delete.php +++ b/rector_examples_updated/db_delete.php @@ -1,5 +1,6 @@ delete('user', []); + Database::getConnection('my_non_default_database')->delete('user', []); } /** diff --git a/rector_examples_updated/db_insert.php b/rector_examples_updated/db_insert.php index 5f64ba80..5c000106 100644 --- a/rector_examples_updated/db_insert.php +++ b/rector_examples_updated/db_insert.php @@ -1,5 +1,6 @@ insert('user', []); + Database::getConnection('my_non_default_database')->insert('user', []); } /** diff --git a/rector_examples_updated/db_query.php b/rector_examples_updated/db_query.php index 64e3de26..a3a668ab 100644 --- a/rector_examples_updated/db_query.php +++ b/rector_examples_updated/db_query.php @@ -26,7 +26,12 @@ function placeholder() { * An example using arguments and options. */ function arguments_and_options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], ['fetch' => \PDO::FETCH_OBJ, 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, 'allow_delimiter_in_query' => FALSE]); + \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [ + 'fetch' => \PDO::FETCH_OBJ, + 'return' => \Drupal\core\Database\Database::RETURN_STATEMENT, + 'throw_exception' => TRUE, + 'allow_delimiter_in_query' => FALSE + ]); } /** @@ -39,7 +44,7 @@ function query_and_arguments_and_options_as_variables() { $opts = ['target' => 'my_non_default_database', 'fetch' => \PDO::FETCH_OBJ, - 'return' => Database::RETURN_STATEMENT, + 'return' => \Drupal\core\Database\Database::RETURN_STATEMENT, 'throw_exception' => TRUE, 'allow_delimiter_in_query' => FALSE, ]; diff --git a/rector_examples_updated/db_select.php b/rector_examples_updated/db_select.php index c0d99d59..e2fca4a2 100644 --- a/rector_examples_updated/db_select.php +++ b/rector_examples_updated/db_select.php @@ -1,5 +1,6 @@ select('user', 'u', []); + Database::getConnection('my_non_default_database')->select('user', 'u', []); } /** diff --git a/rector_examples_updated/db_update.php b/rector_examples_updated/db_update.php index ac6f9006..ab3075e6 100644 --- a/rector_examples_updated/db_update.php +++ b/rector_examples_updated/db_update.php @@ -1,5 +1,6 @@ update('user', []); + $database = Database::getConnection('my_non_default_database')->update('user', []); } /** From 02c49a54bb7a61ac97a20db9987358ca5501128e Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 8 Apr 2021 10:00:18 -0500 Subject: [PATCH 23/64] Fix comments: parentNode is now just parent --- src/Utility/AddCommentTrait.php | 9 ++++++--- tests/src/DrupalIntegrationTest.php | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Utility/AddCommentTrait.php b/src/Utility/AddCommentTrait.php index de8dc1ee..65158e0d 100644 --- a/src/Utility/AddCommentTrait.php +++ b/src/Utility/AddCommentTrait.php @@ -23,8 +23,8 @@ protected function getClosestStatementNode(Node $node): ?Node { if ($node instanceof Node\Stmt) { $statement_node = $node; } - elseif ($node->hasAttribute('parentNode')) { - $parent_node = $node->getAttribute('parentNode'); + elseif ($node->hasAttribute('parent')) { + $parent_node = $node->getAttribute('parent'); $statement_node = $this->getClosestStatementNode($parent_node); } @@ -39,7 +39,10 @@ protected function getClosestStatementNode(Node $node): ?Node { * @param string $comment */ protected function addDrupalRectorComment(Node $node, $comment) { - // Referencing the `parameterProvider` property in this way isn't a great idea since we are assuming the property exists, but it does in `AbstractRector` which all of our rules extend in some form or another. + // Referencing the `parameterProvider` property in this way isn't a + // great idea since we are assuming the property exists, but it does in + // `AbstractRector` which all of our rules extend in some form or + // another. if ($this->parameterProvider->provideParameter('drupal_rector_notices_as_comments')) { $comment_with_wrapper = "// TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes." . PHP_EOL . "// $comment"; diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index bf6448d6..659a6cce 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -3,6 +3,7 @@ namespace DrupalRector\Tests; use DrupalRector\Rector\Deprecation\DatetimeDateStorageFormatRector; +use DrupalRector\Rector\Deprecation\DrupalSetMessageRector; use DrupalRector\Rector\Deprecation\FileCreateDirectoryRector; use PHPUnit\Framework\TestCase; use Rector\Core\Bootstrap\RectorConfigsResolver; @@ -77,6 +78,10 @@ public function integrationData(): \Generator { __DIR__ . '/../../rector_examples/src/FileCreateDirectoryNoUseStatement.php', [FileCreateDirectoryRector::class] ]; + yield [ + __DIR__ . '/../../rector_examples/drupal_set_message.php', + [DrupalSetMessageRector::class] + ]; } } From 9df523a41f55e02f59fadcf586714079b73ca9ef Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 9 Apr 2021 15:35:42 -0500 Subject: [PATCH 24/64] nextNode is just next --- rector_examples_updated/db_insert.php | 2 +- rector_examples_updated/db_query.php | 9 +++++---- src/Rector/Deprecation/EntityManagerRector.php | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rector_examples_updated/db_insert.php b/rector_examples_updated/db_insert.php index 5c000106..375d9a2d 100644 --- a/rector_examples_updated/db_insert.php +++ b/rector_examples_updated/db_insert.php @@ -1,6 +1,6 @@ query('select * from user where name="%test"', ['%test'=>'Adam'], [ + Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [ 'fetch' => \PDO::FETCH_OBJ, - 'return' => \Drupal\core\Database\Database::RETURN_STATEMENT, + 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, - 'allow_delimiter_in_query' => FALSE + 'allow_delimiter_in_query' => FALSE, ]); } @@ -44,7 +45,7 @@ function query_and_arguments_and_options_as_variables() { $opts = ['target' => 'my_non_default_database', 'fetch' => \PDO::FETCH_OBJ, - 'return' => \Drupal\core\Database\Database::RETURN_STATEMENT, + 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, 'allow_delimiter_in_query' => FALSE, ]; diff --git a/src/Rector/Deprecation/EntityManagerRector.php b/src/Rector/Deprecation/EntityManagerRector.php index 32bc36f1..90867b33 100644 --- a/src/Rector/Deprecation/EntityManagerRector.php +++ b/src/Rector/Deprecation/EntityManagerRector.php @@ -74,8 +74,8 @@ public function refactor(Node $node): ?Node { $service = 'entity_type.manager'; // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. - if ($node->hasAttribute('nextNode')) { - $next_node = $node->getAttribute('nextNode'); + if ($node->hasAttribute('next')) { + $next_node = $node->getAttribute('next'); $service = $this->getServiceByMethodName($this->getName($next_node)); } @@ -93,7 +93,7 @@ public function refactor(Node $node): ?Node { $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); if ($node instanceof Node\Expr\MethodCall && $parentClassName === 'Drupal\Core\Controller\ControllerBase') { // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. - $next_node = $node->getAttribute('nextNode'); + $next_node = $node->getAttribute('next'); if (!is_null($next_node)) { $service = $this->getServiceByMethodName($this->getName($next_node)); From f03df1bc9064966fb3cafac87f43717f7ddf0e6b Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 9 Apr 2021 15:42:51 -0500 Subject: [PATCH 25/64] Fix remaining diff errors --- rector_examples_updated/db_insert.php | 2 +- rector_examples_updated/db_query.php | 3 +-- rector_examples_updated/src/DBDeleteStatic.php | 3 ++- rector_examples_updated/src/DBInsertStatic.php | 3 ++- rector_examples_updated/src/DBQueryStatic.php | 7 ++++++- rector_examples_updated/src/DBSelectStatic.php | 3 ++- rector_examples_updated/src/DBUpdateStatic.php | 3 ++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/rector_examples_updated/db_insert.php b/rector_examples_updated/db_insert.php index 375d9a2d..5c000106 100644 --- a/rector_examples_updated/db_insert.php +++ b/rector_examples_updated/db_insert.php @@ -1,6 +1,6 @@ query('select * from user where name="%test"', ['%test'=>'Adam'], [ + \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [ 'fetch' => \PDO::FETCH_OBJ, 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, diff --git a/rector_examples_updated/src/DBDeleteStatic.php b/rector_examples_updated/src/DBDeleteStatic.php index 311be5e2..1d0d9458 100644 --- a/rector_examples_updated/src/DBDeleteStatic.php +++ b/rector_examples_updated/src/DBDeleteStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -20,7 +21,7 @@ public function simple_example() { * An example using options. */ public function options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->delete('user', []); + Database::getConnection('my_non_default_database')->delete('user', []); } /** diff --git a/rector_examples_updated/src/DBInsertStatic.php b/rector_examples_updated/src/DBInsertStatic.php index 022e8481..89c4778b 100644 --- a/rector_examples_updated/src/DBInsertStatic.php +++ b/rector_examples_updated/src/DBInsertStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -20,7 +21,7 @@ public function simple_example() { * An example using options. */ public function options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->insert('user', []); + Database::getConnection('my_non_default_database')->insert('user', []); } /** diff --git a/rector_examples_updated/src/DBQueryStatic.php b/rector_examples_updated/src/DBQueryStatic.php index d581520e..e1712e63 100644 --- a/rector_examples_updated/src/DBQueryStatic.php +++ b/rector_examples_updated/src/DBQueryStatic.php @@ -29,7 +29,12 @@ public function placeholder() { * An example using arguments and options. */ public function arguments_and_options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], ['fetch' => \PDO::FETCH_OBJ, 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, 'allow_delimiter_in_query' => FALSE]); + \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [ + 'fetch' => \PDO::FETCH_OBJ, + 'return' => Database::RETURN_STATEMENT, + 'throw_exception' => TRUE, + 'allow_delimiter_in_query' => FALSE, + ]); } /** diff --git a/rector_examples_updated/src/DBSelectStatic.php b/rector_examples_updated/src/DBSelectStatic.php index d603f4dc..8e8dda94 100644 --- a/rector_examples_updated/src/DBSelectStatic.php +++ b/rector_examples_updated/src/DBSelectStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -29,7 +30,7 @@ public function alias() { * An example using alias and options. */ public function alias_and_options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->select('user', 'u', []); + Database::getConnection('my_non_default_database')->select('user', 'u', []); } /** diff --git a/rector_examples_updated/src/DBUpdateStatic.php b/rector_examples_updated/src/DBUpdateStatic.php index d65feff8..efe5e750 100644 --- a/rector_examples_updated/src/DBUpdateStatic.php +++ b/rector_examples_updated/src/DBUpdateStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -20,7 +21,7 @@ public function simple_example() { * An example using options. */ public function options() { - $database = \Drupal\core\Database\Database::getConnection('my_non_default_database')->update('user', []); + $database = Database::getConnection('my_non_default_database')->update('user', []); } /** From ee7c7758bf9130b00b801cb863274cec1ea117ad Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 9 Apr 2021 16:02:32 -0500 Subject: [PATCH 26/64] rector/rector:0.10.4 stopped returning applied rectors --- tests/src/DrupalIntegrationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index 659a6cce..8b312b94 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -66,7 +66,8 @@ public function testIntegration(string $source, array $applied_rules) $output = json_decode(ob_get_clean()); self::assertObjectNotHasAttribute('errors', $output, var_export($output, true)); self::assertObjectHasAttribute('file_diffs', $output); - self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); + // @todo rector/rector 0.10.4 stopped having applied_rectors with data. + // self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); } public function integrationData(): \Generator { From 71b077fa95ab6bf3570405271baf7fb7d1b9958b Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 14 Apr 2021 22:04:26 -0500 Subject: [PATCH 27/64] Use constants for accessing attribute values --- src/Rector/Deprecation/EntityManagerRector.php | 7 ++++--- src/Utility/AddCommentTrait.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Rector/Deprecation/EntityManagerRector.php b/src/Rector/Deprecation/EntityManagerRector.php index 90867b33..979197c3 100644 --- a/src/Rector/Deprecation/EntityManagerRector.php +++ b/src/Rector/Deprecation/EntityManagerRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\Core\Rector\AbstractRector; +use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -74,8 +75,8 @@ public function refactor(Node $node): ?Node { $service = 'entity_type.manager'; // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. - if ($node->hasAttribute('next')) { - $next_node = $node->getAttribute('next'); + if ($node->hasAttribute(AttributeKey::NEXT_NODE)) { + $next_node = $node->getAttribute(AttributeKey::NEXT_NODE); $service = $this->getServiceByMethodName($this->getName($next_node)); } @@ -93,7 +94,7 @@ public function refactor(Node $node): ?Node { $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); if ($node instanceof Node\Expr\MethodCall && $parentClassName === 'Drupal\Core\Controller\ControllerBase') { // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. - $next_node = $node->getAttribute('next'); + $next_node = $node->getAttribute(AttributeKey::NEXT_NODE); if (!is_null($next_node)) { $service = $this->getServiceByMethodName($this->getName($next_node)); diff --git a/src/Utility/AddCommentTrait.php b/src/Utility/AddCommentTrait.php index 65158e0d..92a5d950 100644 --- a/src/Utility/AddCommentTrait.php +++ b/src/Utility/AddCommentTrait.php @@ -4,6 +4,7 @@ use PhpParser\Comment; use PhpParser\Node; +use Rector\NodeTypeResolver\Node\AttributeKey; /** * Provides an easy way to add a comment to a statement. @@ -23,8 +24,8 @@ protected function getClosestStatementNode(Node $node): ?Node { if ($node instanceof Node\Stmt) { $statement_node = $node; } - elseif ($node->hasAttribute('parent')) { - $parent_node = $node->getAttribute('parent'); + elseif ($node->hasAttribute(AttributeKey::PARENT_NODE)) { + $parent_node = $node->getAttribute(AttributeKey::PARENT_NODE); $statement_node = $this->getClosestStatementNode($parent_node); } From bd16f1accb97cc00897035292982a34bb878b555 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 09:04:22 -0500 Subject: [PATCH 28/64] Remove include of "core/tests/bootstrap.php" --- rector-config-docroot-dir.php | 2 +- rector-config-web-dir.php | 2 +- rector.php | 1 - tests/config/rector-phpunit.php | 11 +++++------ tests/src/DrupalIntegrationTest.php | 4 ++++ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php index 2a85c9a3..e089639f 100644 --- a/rector-config-docroot-dir.php +++ b/rector-config-docroot-dir.php @@ -11,7 +11,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/modules', 'docroot/profiles', 'docroot/themes']); - require_once __DIR__ . '/docroot/core/tests/bootstrap.php'; + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php index 8e22ce28..efc29fb4 100644 --- a/rector-config-web-dir.php +++ b/rector-config-web-dir.php @@ -10,7 +10,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); - require_once __DIR__ . '/web/core/tests/bootstrap.php'; + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/rector.php b/rector.php index b2a10a85..b17a09a2 100644 --- a/rector.php +++ b/rector.php @@ -10,7 +10,6 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); - require_once __DIR__ . '/web/core/tests/bootstrap.php'; $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php index 72b7d482..78d36416 100644 --- a/tests/config/rector-phpunit.php +++ b/tests/config/rector-phpunit.php @@ -14,15 +14,14 @@ return static function (ContainerConfigurator $containerConfigurator): void { $containerConfigurator->import(__DIR__ . '/../../config/drupal-8/drupal-8-all-deprecations.php'); + $drupalRoot = __DIR__ . '/../fixtures/drupal/web'; $parameters = $containerConfigurator->parameters(); $parameters->set(Option::AUTOLOAD_PATHS, [ - __DIR__ . '/../fixtures/drupal/web/core', - __DIR__ . '/../fixtures/drupal/web/core/modules', - __DIR__ . '/../fixtures/drupal/web/modules', - __DIR__ . '/../fixtures/drupal/web/profiles' + $drupalRoot . '/core', + $drupalRoot . '/modules', + $drupalRoot . '/profiles', ]); - // @todo this crashes PHPUnit but fixes Drupal's test namespace autoloading. - // require_once __DIR__ . '/../fixtures/drupal/web/core/tests/bootstrap.php'; + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $parameters->set(Option::AUTO_IMPORT_NAMES, true); diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index 8b312b94..8c2e8432 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -83,6 +83,10 @@ public function integrationData(): \Generator { __DIR__ . '/../../rector_examples/drupal_set_message.php', [DrupalSetMessageRector::class] ]; + yield [ + __DIR__ . '/../../rector_examples/test/src/Functional/BrowserTestBaseGetMock.php', + [DrupalSetMessageRector::class] + ]; } } From abd687d353c3f8ee51198fdb0357b46c8a791cdf Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 09:20:05 -0500 Subject: [PATCH 29/64] 0.10.6 restores ability to check file_diffs for applied rules --- tests/src/DrupalIntegrationTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index 8c2e8432..528b0991 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -66,8 +66,7 @@ public function testIntegration(string $source, array $applied_rules) $output = json_decode(ob_get_clean()); self::assertObjectNotHasAttribute('errors', $output, var_export($output, true)); self::assertObjectHasAttribute('file_diffs', $output); - // @todo rector/rector 0.10.4 stopped having applied_rectors with data. - // self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); + self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); } public function integrationData(): \Generator { From 87ac7f21e42c878f80419ba73a5b46fec15818d1 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 09:58:14 -0500 Subject: [PATCH 30/64] Update remaining `yml` documentation --- README.md | 20 ++++++++++---------- rector.php | 7 ++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 83de20a2..a669461c 100644 --- a/README.md +++ b/README.md @@ -62,16 +62,16 @@ You will need to have a `rector.php` configuration in the root of your repositor This project provides starting files that should handle most use cases. -If your document root directory is `web`, you can copy the `rector-config-web-dir.yml` +If your document root directory is `web`, you can copy the `rector-config-web-dir.php` ```bash -cp vendor/palantirnet/drupal-rector/rector-config-web-dir.yml rector.php +cp vendor/palantirnet/drupal-rector/rector-config-web-dir.php rector.php ``` -If your document root directory is `docroot`, you can copy the `rector-config-docroot-dir.yml` +If your document root directory is `docroot`, you can copy the `rector-config-docroot-dir.php` ```bash -cp vendor/palantirnet/drupal-rector/rector-config-docroot-dir.yml rector.php +cp vendor/palantirnet/drupal-rector/rector-config-docroot-dir.php rector.php ``` If your document root directory is something else you will need to manually copy and edit `rector.php`. @@ -79,12 +79,12 @@ If your document root directory is something else you will need to manually copy Replace the `web` in these paths with your document root. ``` -parameters: - autoload_paths: - - 'web/core' - - 'web/core/modules' - - 'web/modules' - - 'web/profiles' +$parameters->set(Option::AUTOLOAD_PATHS, [ + 'web/core', + 'web/modules', + 'web/profiles', + 'web/themes' +]); ``` ## Suggested workflow diff --git a/rector.php b/rector.php index b17a09a2..05c59244 100644 --- a/rector.php +++ b/rector.php @@ -9,7 +9,12 @@ $containerConfigurator->import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); + $parameters->set(Option::AUTOLOAD_PATHS, [ + 'web/core', + 'web/modules', + 'web/profiles', + 'web/themes' + ]); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); From 31e1c1c6b32644ab14b17217cdc6182bae85cfc3 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 12:07:50 -0500 Subject: [PATCH 31/64] Initial work to fix test traits autoloading --- composer.json | 3 + drupal-phpunit-hack.php | 39 +++++++ tests/config/drupal-phpunit-fixes.php | 144 ++++++++++++++++++++++++++ tests/config/rector-phpunit.php | 3 + tests/src/DrupalIntegrationTest.php | 3 +- 5 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 drupal-phpunit-hack.php create mode 100644 tests/config/drupal-phpunit-fixes.php diff --git a/composer.json b/composer.json index 77d1f6b7..f89de46b 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,9 @@ } ], "autoload": { + "files": [ + "drupal-phpunit-hack.php" + ], "psr-4": { "DrupalRector\\": "src" } diff --git a/drupal-phpunit-hack.php b/drupal-phpunit-hack.php new file mode 100644 index 00000000..b20ee383 --- /dev/null +++ b/drupal-phpunit-hack.php @@ -0,0 +1,39 @@ +findFile('PHPUnit\Framework\TestCase'); +if (!$alteredFile) { + return; +} +$phpunit_dir = dirname($alteredFile, 3); +// Mutate TestCase code to make it compatible with Drupal 8 and 9 tests. +$alteredCode = file_get_contents($alteredFile); +$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode); +$alteredCode = str_replace("__DIR__ . '/../Util/", "'$phpunit_dir/src/Util/", $alteredCode); +// Only write when necessary. +$filename = __DIR__ . '/tests/fixtures/MutatedTestCase.php'; + +if (!file_exists($filename) || md5_file($filename) !== md5($alteredCode)) { + file_put_contents($filename, $alteredCode); +} +include $filename; diff --git a/tests/config/drupal-phpunit-fixes.php b/tests/config/drupal-phpunit-fixes.php new file mode 100644 index 00000000..932292df --- /dev/null +++ b/tests/config/drupal-phpunit-fixes.php @@ -0,0 +1,144 @@ +getPathname(), '.info.yml') !== FALSE) { + // Cut off ".info.yml" from the filename for use as the extension name. We + // use getRealPath() so that we can scan extensions represented by + // directory aliases. + $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo() + ->getRealPath(); + } + } + return $extensions; +} + +/** + * Returns directories under which contributed extensions may exist. + * + * @param string $root + * (optional) Path to the root of the Drupal installation. + * + * @return array + * An array of directories under which contributed extensions may exist. + */ +function drupal_phpunit_contrib_extension_directory_roots($root) { + $paths = [ + $root . '/core/modules', + $root . '/core/profiles', + $root . '/modules', + $root . '/profiles', + $root . '/themes', + ]; + $sites_path = $root . '/sites'; + // Note this also checks sites/../modules and sites/../profiles. + foreach (scandir($sites_path) as $site) { + if ($site[0] === '.' || $site === 'simpletest') { + continue; + } + $path = "$sites_path/$site"; + $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL; + $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL; + $paths[] = is_dir("$path/themes") ? realpath("$path/themes") : NULL; + } + return array_filter($paths, 'file_exists'); +} + +/** + * Registers the namespace for each extension directory with the autoloader. + * + * @param array $dirs + * An associative array of extension directories, keyed by extension name. + * + * @return array + * An associative array of extension directories, keyed by their namespace. + */ +function drupal_phpunit_get_extension_namespaces($dirs) { + $suite_names = ['Unit', 'Kernel', 'Functional', 'Build', 'FunctionalJavascript']; + $namespaces = []; + foreach ($dirs as $extension => $dir) { + if (is_dir($dir . '/src')) { + // Register the PSR-4 directory for module-provided classes. + $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src'; + } + $test_dir = $dir . '/tests/src'; + if (is_dir($test_dir)) { + foreach ($suite_names as $suite_name) { + $suite_dir = $test_dir . '/' . $suite_name; + if (is_dir($suite_dir)) { + // Register the PSR-4 directory for PHPUnit-based suites. + $namespaces['Drupal\\Tests\\' . $extension . '\\' . $suite_name . '\\'][] = $suite_dir; + } + } + // Extensions can have a \Drupal\extension\Traits namespace for + // cross-suite trait code. + $trait_dir = $test_dir . '/Traits'; + if (is_dir($trait_dir)) { + $namespaces['Drupal\\Tests\\' . $extension . '\\Traits\\'][] = $trait_dir; + } + } + } + return $namespaces; +} + + +/** + * Populate class loader with additional namespaces for tests. + * + * We run this in a function to avoid setting the class loader to a global + * that can change. This change can cause unpredictable false positives for + * phpunit's global state change watcher. The class loader can be retrieved from + * composer at any time by requiring autoload.php. + */ +function drupal_phpunit_populate_class_loader() { + $drupalRoot = __DIR__ . '/../fixtures/drupal/web'; + + /** @var \Composer\Autoload\ClassLoader $loader */ + $loader = require __DIR__ . '/../fixtures/drupal/vendor/autoload.php'; + + // Start with classes in known locations. + $loader->add('Drupal\\BuildTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\Tests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\TestSite', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\KernelTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\FunctionalTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\FunctionalJavascriptTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\TestTools', $drupalRoot . '/core/tests'); + + if (!isset($GLOBALS['namespaces'])) { + // Scan for arbitrary extension namespaces from core and contrib. + $extension_roots = drupal_phpunit_contrib_extension_directory_roots($drupalRoot); + + $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots); + $dirs = array_reduce($dirs, 'array_merge', []); + $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs); + } + foreach ($GLOBALS['namespaces'] as $prefix => $paths) { + $loader->addPsr4($prefix, $paths); + } + + return $loader; +} + +// Do class loader population. +drupal_phpunit_populate_class_loader(); + +// Force the alias to PHPUnit 7. This prevents possibly aliasing to PhpUnit9. +require_once __DIR__ . '/../fixtures/drupal/web/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/TestCompatibilityTrait.php'; +class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit7\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php index 78d36416..71d7a7f1 100644 --- a/tests/config/rector-phpunit.php +++ b/tests/config/rector-phpunit.php @@ -21,6 +21,9 @@ $drupalRoot . '/modules', $drupalRoot . '/profiles', ]); + $parameters->set(Option::BOOTSTRAP_FILES, [ + __DIR__ . '/drupal-phpunit-fixes.php' + ]); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index 528b0991..ac1f4935 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -2,6 +2,7 @@ namespace DrupalRector\Tests; +use DrupalRector\Rector\Deprecation\BrowserTestBaseGetMockRector; use DrupalRector\Rector\Deprecation\DatetimeDateStorageFormatRector; use DrupalRector\Rector\Deprecation\DrupalSetMessageRector; use DrupalRector\Rector\Deprecation\FileCreateDirectoryRector; @@ -84,7 +85,7 @@ public function integrationData(): \Generator { ]; yield [ __DIR__ . '/../../rector_examples/test/src/Functional/BrowserTestBaseGetMock.php', - [DrupalSetMessageRector::class] + [BrowserTestBaseGetMockRector::class] ]; } From 5146376cfb2803ba7ad4130b2c26ad88bd838c46 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 12:35:36 -0500 Subject: [PATCH 32/64] Make PHPUnit autoloading bootstrap file generic for all config --- config/drupal-8/drupal-8-all-deprecations.php | 3 +++ .../drupal-phpunit-bootstrap-file.php | 27 ++++++++++++++----- tests/config/rector-phpunit.php | 3 --- 3 files changed, 24 insertions(+), 9 deletions(-) rename tests/config/drupal-phpunit-fixes.php => config/drupal-phpunit-bootstrap-file.php (83%) diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php index cc480d97..7308790b 100644 --- a/config/drupal-8/drupal-8-all-deprecations.php +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -10,4 +10,7 @@ $parameters = $containerConfigurator->parameters(); $parameters->set(Option::SKIP, []); + $parameters->set(Option::BOOTSTRAP_FILES, [ + __DIR__ . '/../drupal-phpunit-bootstrap-file.php' + ]); }; diff --git a/tests/config/drupal-phpunit-fixes.php b/config/drupal-phpunit-bootstrap-file.php similarity index 83% rename from tests/config/drupal-phpunit-fixes.php rename to config/drupal-phpunit-bootstrap-file.php index 932292df..27cd805f 100644 --- a/tests/config/drupal-phpunit-fixes.php +++ b/config/drupal-phpunit-bootstrap-file.php @@ -1,9 +1,25 @@ parameterProvider; +assert($parameterProvider instanceof ParameterProvider); + +// @todo replace with webflo/drupal-finder to find core from first path. +$autoloadPaths = $parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS); +$corePath = $autoloadPaths[0]; +$drupalRoot = dirname($corePath); +$vendorRoot = dirname($drupalRoot) . '/vendor'; + /** * Finds all valid extension directories recursively within a given directory. * @@ -106,11 +122,10 @@ function drupal_phpunit_get_extension_namespaces($dirs) { * phpunit's global state change watcher. The class loader can be retrieved from * composer at any time by requiring autoload.php. */ -function drupal_phpunit_populate_class_loader() { - $drupalRoot = __DIR__ . '/../fixtures/drupal/web'; +function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { /** @var \Composer\Autoload\ClassLoader $loader */ - $loader = require __DIR__ . '/../fixtures/drupal/vendor/autoload.php'; + $loader = require $vendorRoot . '/autoload.php'; // Start with classes in known locations. $loader->add('Drupal\\BuildTests', $drupalRoot . '/core/tests'); @@ -137,8 +152,8 @@ function drupal_phpunit_populate_class_loader() { } // Do class loader population. -drupal_phpunit_populate_class_loader(); +drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot); // Force the alias to PHPUnit 7. This prevents possibly aliasing to PhpUnit9. -require_once __DIR__ . '/../fixtures/drupal/web/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/TestCompatibilityTrait.php'; +require_once $drupalRoot . '/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/TestCompatibilityTrait.php'; class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit7\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php index 71d7a7f1..78d36416 100644 --- a/tests/config/rector-phpunit.php +++ b/tests/config/rector-phpunit.php @@ -21,9 +21,6 @@ $drupalRoot . '/modules', $drupalRoot . '/profiles', ]); - $parameters->set(Option::BOOTSTRAP_FILES, [ - __DIR__ . '/drupal-phpunit-fixes.php' - ]); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); From b20270b208e08d3fa7dfb6e97ac8c69659cffb63 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 16:22:43 -0500 Subject: [PATCH 33/64] Use webflo/drupal-finder --- README.md | 24 +++--------------------- composer.json | 3 ++- config/drupal-phpunit-bootstrap-file.php | 19 ++++++++++++++----- rector-config-docroot-dir.php | 22 ---------------------- rector-config-web-dir.php | 21 --------------------- rector.php | 13 +++++++++---- 6 files changed, 28 insertions(+), 74 deletions(-) delete mode 100644 rector-config-docroot-dir.php delete mode 100644 rector-config-web-dir.php diff --git a/README.md b/README.md index a669461c..16d3b4ef 100644 --- a/README.md +++ b/README.md @@ -60,32 +60,14 @@ $ composer require --dev palantirnet/drupal-rector You will need to have a `rector.php` configuration in the root of your repository. This should sit beside your document root such as `web` or `docroot`. -This project provides starting files that should handle most use cases. +This project uses [`webflo/drupal-finder`](https://packagist.org/packages/webflo/drupal-finder) to find your document root that contains Drupal. -If your document root directory is `web`, you can copy the `rector-config-web-dir.php` +To get started, copy the `rector.php` configuration file provided by this package: ```bash -cp vendor/palantirnet/drupal-rector/rector-config-web-dir.php rector.php +cp vendor/palantirnet/drupal-rector/rector.php . ``` -If your document root directory is `docroot`, you can copy the `rector-config-docroot-dir.php` - -```bash -cp vendor/palantirnet/drupal-rector/rector-config-docroot-dir.php rector.php -``` - -If your document root directory is something else you will need to manually copy and edit `rector.php`. - -Replace the `web` in these paths with your document root. - -``` -$parameters->set(Option::AUTOLOAD_PATHS, [ - 'web/core', - 'web/modules', - 'web/profiles', - 'web/themes' -]); -``` ## Suggested workflow diff --git a/composer.json b/composer.json index f89de46b..5960fd00 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "ast" ], "require": { - "rector/rector-prefixed": "~0.10.0" + "rector/rector-prefixed": "~0.10.0", + "webflo/drupal-finder": "^1.2" }, "license": "MIT", "authors": [ diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php index 27cd805f..f22a10a6 100644 --- a/config/drupal-phpunit-bootstrap-file.php +++ b/config/drupal-phpunit-bootstrap-file.php @@ -6,6 +6,7 @@ * This fixes Drupal testing namespace autoloading and PHPUnit compatibility. */ +use DrupalFinder\DrupalFinder; use Rector\Core\Autoloading\BootstrapFilesIncluder; use Symplify\PackageBuilder\Parameter\ParameterProvider; @@ -14,11 +15,19 @@ $parameterProvider = $this->parameterProvider; assert($parameterProvider instanceof ParameterProvider); -// @todo replace with webflo/drupal-finder to find core from first path. $autoloadPaths = $parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS); -$corePath = $autoloadPaths[0]; -$drupalRoot = dirname($corePath); -$vendorRoot = dirname($drupalRoot) . '/vendor'; +if (count($autoloadPaths) === 0) { + throw new \RuntimeException('No autoload paths were specified.'); +} + +$drupalFinder = new DrupalFinder(); +$drupalFinder->locateRoot($autoloadPaths[0]); +$drupalRoot = $drupalFinder->getDrupalRoot(); +$drupalVendorRoot = $drupalFinder->getVendorDir(); + +if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) { + throw new \RuntimeException("Unable to detect Drupal at $drupalRoot"); +} /** * Finds all valid extension directories recursively within a given directory. @@ -152,7 +161,7 @@ function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { } // Do class loader population. -drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot); +drupal_phpunit_populate_class_loader($drupalRoot, $drupalVendorRoot); // Force the alias to PHPUnit 7. This prevents possibly aliasing to PhpUnit9. require_once $drupalRoot . '/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/TestCompatibilityTrait.php'; diff --git a/rector-config-docroot-dir.php b/rector-config-docroot-dir.php deleted file mode 100644 index e089639f..00000000 --- a/rector-config-docroot-dir.php +++ /dev/null @@ -1,22 +0,0 @@ -import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml'); - - $parameters = $containerConfigurator->parameters(); - - $parameters->set(Option::AUTOLOAD_PATHS, ['docroot/core', 'docroot/modules', 'docroot/profiles', 'docroot/themes']); - - $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); - $parameters->set(Option::AUTO_IMPORT_NAMES, true); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - $parameters->set(Option::IMPORT_DOC_BLOCKS, false); - - $parameters->set('drupal_rector_notices_as_comments', true); -}; diff --git a/rector-config-web-dir.php b/rector-config-web-dir.php deleted file mode 100644 index efc29fb4..00000000 --- a/rector-config-web-dir.php +++ /dev/null @@ -1,21 +0,0 @@ -import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); - - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTOLOAD_PATHS, ['web/core', 'web/modules', 'web/profiles', 'web/themes']); - - $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); - $parameters->set(Option::AUTO_IMPORT_NAMES, true); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - $parameters->set(Option::IMPORT_DOC_BLOCKS, false); - - $parameters->set('drupal_rector_notices_as_comments', true); -}; diff --git a/rector.php b/rector.php index 05c59244..f23db143 100644 --- a/rector.php +++ b/rector.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use DrupalFinder\DrupalFinder; use Rector\Core\Configuration\Option; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -9,11 +10,15 @@ $containerConfigurator->import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); $parameters = $containerConfigurator->parameters(); + + $drupalFinder = new DrupalFinder(); + $drupalFinder->locateRoot(__DIR__); + $drupalRoot = $drupalFinder->getDrupalRoot(); $parameters->set(Option::AUTOLOAD_PATHS, [ - 'web/core', - 'web/modules', - 'web/profiles', - 'web/themes' + $drupalRoot . '/core', + $drupalRoot . '/modules', + $drupalRoot . '/profiles', + $drupalRoot . '/themes' ]); $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); From d33c4b072326163a54492ad7ffd5b44e2b01ff25 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 16:28:13 -0500 Subject: [PATCH 34/64] Ensure test/fixtures directory --- tests/fixtures/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/fixtures/.gitignore diff --git a/tests/fixtures/.gitignore b/tests/fixtures/.gitignore new file mode 100644 index 00000000..4d59665d --- /dev/null +++ b/tests/fixtures/.gitignore @@ -0,0 +1 @@ +/MutatedTestCase.php From 7d315540a6c10a88bdbb2d9c5d7b01796a651803 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Thu, 15 Apr 2021 16:30:22 -0500 Subject: [PATCH 35/64] Update phpstan.neon to remove old config files --- phpstan.neon | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index d8ec9e9d..440f6abd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,5 +4,3 @@ parameters: - config - src - rector.php - - rector-config-docroot-dir.php - - rector-config-web-dir.php From 4f498c8d8741b2f1661fdc01b4b3a9c20b4baf8c Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 16 Apr 2021 08:16:11 -0500 Subject: [PATCH 36/64] Fix notice on assert for a prefixed class --- config/drupal-phpunit-bootstrap-file.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php index f22a10a6..26c0d964 100644 --- a/config/drupal-phpunit-bootstrap-file.php +++ b/config/drupal-phpunit-bootstrap-file.php @@ -8,12 +8,17 @@ use DrupalFinder\DrupalFinder; use Rector\Core\Autoloading\BootstrapFilesIncluder; -use Symplify\PackageBuilder\Parameter\ParameterProvider; +use Rector\Core\Exception\ShouldNotHappenException; + +if ($this === NULL || !$this instanceof BootstrapFilesIncluder) { + throw new ShouldNotHappenException('The Drupal PHPUnit Bootstrap file could not access the BootstrapFilesIncluder'); +} -assert($this instanceof BootstrapFilesIncluder); /** @phpstan-ignore-next-line */ $parameterProvider = $this->parameterProvider; -assert($parameterProvider instanceof ParameterProvider); +if ($parameterProvider === NULL) { + throw new ShouldNotHappenException('We were unable to access the parameter provider from the BootstrapFilesIncluder.'); +} $autoloadPaths = $parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS); if (count($autoloadPaths) === 0) { From 8de2317bbac6735f916fdb76dd1cf26748f2b42e Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 16 Apr 2021 08:16:29 -0500 Subject: [PATCH 37/64] Run a test against webform for catching output errors --- .../workflows/local_package_run_rector.yml | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index 98f355e4..e7024e2c 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -6,7 +6,7 @@ on: jobs: run_rector_on_rector_examples_module: - name: Run Drupal Rector + name: rector_examples check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -27,7 +27,8 @@ jobs: composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" composer config repositories.1 composer https://packages.drupal.org/8 COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - - run: | + - name: require local druapl-rector + run: | cd ~/drupal composer require palantirnet/drupal-rector:@dev --no-progress @@ -46,3 +47,41 @@ jobs: # Run Rector cd ~/drupal vendor/bin/rector process web/modules/custom/rector_examples --debug + run_rector_on_webform: + name: webform check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + + - name: Setup Drupal + run: | + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction + cd ~/drupal + composer config minimum-stability dev + composer config prefer-stable true + composer config preferred-install dist + composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" + composer config repositories.1 composer https://packages.drupal.org/8 + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies + # Include webform and its conditionally supported dependencies + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/bootstrap drupal/webform + - name: require local druapl-rector + run: | + cd ~/drupal + composer require palantirnet/drupal-rector:@dev --no-progress + + - run: | + # Prepare rector config files with Drupal specific settings + cd ~/drupal + cp vendor/palantirnet/drupal-rector/rector.php . + + - run: | + # Run Rector + cd ~/drupal + vendor/bin/rector process web/modules/contrib/webform --debug From d66bdc712b67dfaaadcee8406bfb55d55b335377 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 16 Apr 2021 08:40:01 -0500 Subject: [PATCH 38/64] Dynamic PhpunitVersionDependentTestCompatibilityTrait version aliasing --- .github/workflows/local_package_run_rector.yml | 4 ++++ config/drupal-phpunit-bootstrap-file.php | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index e7024e2c..d717673d 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -50,6 +50,10 @@ jobs: run_rector_on_webform: name: webform check runs-on: ubuntu-latest + # There are some non-related errors. So this run acts as a canary + # that we manually review to shake loose errors. + # @todo: remove when PHPStan doesn't choke on WebformLikert doc block + continue-on-error: true steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php index 26c0d964..9ba2df57 100644 --- a/config/drupal-phpunit-bootstrap-file.php +++ b/config/drupal-phpunit-bootstrap-file.php @@ -7,6 +7,7 @@ */ use DrupalFinder\DrupalFinder; +use PHPUnit\Runner\Version; use Rector\Core\Autoloading\BootstrapFilesIncluder; use Rector\Core\Exception\ShouldNotHappenException; @@ -168,6 +169,19 @@ function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { // Do class loader population. drupal_phpunit_populate_class_loader($drupalRoot, $drupalVendorRoot); -// Force the alias to PHPUnit 7. This prevents possibly aliasing to PhpUnit9. -require_once $drupalRoot . '/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/TestCompatibilityTrait.php'; +// Determines the major version of PHPUnit. +// @see \PHPUnit\Runner\Version\RunnerVersion::getMajor(). +if (class_exists(Version::class)) { + $major = (int) explode('.', Version::id())[0]; + // Force the alias to PHPUnit 7. This prevents possibly aliasing to + // PhpUnit8 or PhpUnit9, which do not exist. + if ($major > 7) { + $major = 7; + } +} +else { + // Default to the higher option. + $major = 6; +} +require_once $drupalRoot . "/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit{$major}/TestCompatibilityTrait.php"; class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit7\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); From 619f96abd22156a2d5f98df35fef7669d4920612 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 16 Apr 2021 11:31:16 -0500 Subject: [PATCH 39/64] Do not error with Webform if it fails --- .github/workflows/local_package_run_rector.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index d717673d..1d041923 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -52,8 +52,6 @@ jobs: runs-on: ubuntu-latest # There are some non-related errors. So this run acts as a canary # that we manually review to shake loose errors. - # @todo: remove when PHPStan doesn't choke on WebformLikert doc block - continue-on-error: true steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 @@ -89,3 +87,5 @@ jobs: # Run Rector cd ~/drupal vendor/bin/rector process web/modules/contrib/webform --debug + # @todo: remove when PHPStan doesn't choke on WebformLikert doc block + continue-on-error: true From ad43a86c74d204bf220e16489b2a36e666678ef3 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 16 Apr 2021 15:29:35 -0500 Subject: [PATCH 40/64] Run on different PHPUnit versions, fix hardcoded trait namespace --- .github/workflows/local_package_run_rector.yml | 15 ++++++++++++--- config/drupal-phpunit-bootstrap-file.php | 16 ++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml index 1d041923..419d7a62 100644 --- a/.github/workflows/local_package_run_rector.yml +++ b/.github/workflows/local_package_run_rector.yml @@ -6,8 +6,17 @@ on: jobs: run_rector_on_rector_examples_module: - name: rector_examples check + name: rector_examples (drupal/${{ matrix.dev_dependencies_package }}) runs-on: ubuntu-latest + strategy: + matrix: + drupal_version: + - "~8" + dev_dependencies_package: + # drupal/core-dev installs phpunit:7 + - "core-dev" + # drupal/core-dev-pinned installs phpunit:6 + - "core-dev-pinned" steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 @@ -19,14 +28,14 @@ jobs: - name: Setup Drupal run: | - COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:${{ matrix.drupal_version }} ~/drupal --no-interaction cd ~/drupal composer config minimum-stability dev composer config prefer-stable true composer config preferred-install dist composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" composer config repositories.1 composer https://packages.drupal.org/8 - COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/${{ matrix.dev_dependencies_package }}:${{ matrix.drupal_version }} --with-all-dependencies - name: require local druapl-rector run: | cd ~/drupal diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php index 9ba2df57..b2bbc30a 100644 --- a/config/drupal-phpunit-bootstrap-file.php +++ b/config/drupal-phpunit-bootstrap-file.php @@ -170,18 +170,14 @@ function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { drupal_phpunit_populate_class_loader($drupalRoot, $drupalVendorRoot); // Determines the major version of PHPUnit. -// @see \PHPUnit\Runner\Version\RunnerVersion::getMajor(). +$major = 7; if (class_exists(Version::class)) { $major = (int) explode('.', Version::id())[0]; - // Force the alias to PHPUnit 7. This prevents possibly aliasing to - // PhpUnit8 or PhpUnit9, which do not exist. - if ($major > 7) { - $major = 7; - } } -else { - // Default to the higher option. - $major = 6; +if ($major > 7) { + $major = 7; } +// @todo This was added in 8.8.x, which means 8.7.x would fail on this but +// people should upgrade to 8.9.x anyways. require_once $drupalRoot . "/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit{$major}/TestCompatibilityTrait.php"; -class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit7\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); +class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit{$major}\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); From 659023299ed32748eee9dacef625ecd95db6e82f Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 26 Apr 2021 14:13:19 -0500 Subject: [PATCH 41/64] Refactor Gitflow Actions. Try to be clear about copy & paste steps. We could share jobs, but these run faster. Removed Behat mentions since we aren't using it. Updated the local composer.json repository config to add names and split it up to be easier to read. --- .github/workflows/canary__webform_module.yml | 55 ++++++++++ ...l => functional_test__rector_examples.yml} | 44 ++++---- .../workflows/local_package_run_rector.yml | 100 ------------------ .../packagist_package_run_rector.yml | 50 --------- .github/workflows/phpstan.yml | 16 --- .../workflows/static_analysis__phpstan.yml | 24 +++++ .../{phpunit.yml => unit_tests__phpunit.yml} | 16 ++- 7 files changed, 117 insertions(+), 188 deletions(-) create mode 100644 .github/workflows/canary__webform_module.yml rename .github/workflows/{local_package_functional_tests.yml => functional_test__rector_examples.yml} (57%) delete mode 100644 .github/workflows/local_package_run_rector.yml delete mode 100644 .github/workflows/packagist_package_run_rector.yml delete mode 100644 .github/workflows/phpstan.yml create mode 100644 .github/workflows/static_analysis__phpstan.yml rename .github/workflows/{phpunit.yml => unit_tests__phpunit.yml} (54%) diff --git a/.github/workflows/canary__webform_module.yml b/.github/workflows/canary__webform_module.yml new file mode 100644 index 00000000..3a2ec22d --- /dev/null +++ b/.github/workflows/canary__webform_module.yml @@ -0,0 +1,55 @@ +name: canary__webform_module +# There are some non-related errors. So this run acts as a canary +# that we manually review to shake loose errors. + +# This test will run on every pull request, and on every commit on any branch +on: [push, pull_request] + +jobs: + run_rector_on_webform: + name: Check webform module as a canary +# START: SHARED SETUP + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v2 +# END: SHARED SETUP +# START: SHARED DRUPAL INSTALL SETUP + - name: Setup Drupal + run: | + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction + cd ~/drupal + composer config minimum-stability dev + composer config prefer-stable true + composer config preferred-install dist + composer config repositories.drupal composer https://packages.drupal.org/8 + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies + # We add a local repository `repositories.0` which takes precendence over the packagist repository that is automatically added. + - name: Install Drupal Rector + run: | + cd ~/drupal + composer config repositories.drupal-rector "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" + composer require palantirnet/drupal-rector:@dev --no-progress + - name: Install Drupal Rector Config + run: | + cd ~/drupal + cp vendor/palantirnet/drupal-rector/rector.php . +# END: SHARED DRUPAL INSTALL SETUP + - name: Include webform and its conditionally supported dependencies + run: | + cd ~/drupal + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/bootstrap drupal/webform + - run: | + # Run Rector + cd ~/drupal + vendor/bin/rector process web/modules/contrib/webform --debug + # @todo: remove when PHPStan doesn't choke on WebformLikert doc block + continue-on-error: true diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/functional_test__rector_examples.yml similarity index 57% rename from .github/workflows/local_package_functional_tests.yml rename to .github/workflows/functional_test__rector_examples.yml index 9dedc749..52550f86 100644 --- a/.github/workflows/local_package_functional_tests.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -1,13 +1,13 @@ -name: local_package_functional_tests +name: functional_test__rector_examples # This test will run on every pull request, and on every commit on any branch -on: - [push, pull_request] +on: [push, pull_request] jobs: - functional_tests: - name: Run functional tests using Behat - runs-on: ubuntu-latest + run_functional_test: + name: Run functional test +# START: SHARED SETUP + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 @@ -16,7 +16,11 @@ jobs: coverage: none # disable xdebug, pcov tools: composer:v2 extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v2 +# END: SHARED SETUP +# START: SHARED DRUPAL INSTALL SETUP - name: Setup Drupal run: | COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction @@ -24,27 +28,24 @@ jobs: composer config minimum-stability dev composer config prefer-stable true composer config preferred-install dist - composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" - composer config repositories.1 composer https://packages.drupal.org/8 + composer config repositories.drupal composer https://packages.drupal.org/8 COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - - name: Install drupal-rector + # We add a local repository `repositories.0` which takes precendence over the packagist repository that is automatically added. + - name: Install Drupal Rector run: | cd ~/drupal + composer config repositories.drupal-rector "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" composer require palantirnet/drupal-rector:@dev --no-progress - - - name: Copy rector config + - name: Install Drupal Rector Config run: | cd ~/drupal cp vendor/palantirnet/drupal-rector/rector.php . - cat rector.php - +# END: SHARED DRUPAL INSTALL SETUP - name: Prepare rector_examples folder in the drupal modules directory run: | cd ~/drupal mkdir -p web/modules/custom - mv vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - ls -la web/modules/custom/rector_examples - + cp vendor/palantirnet/drupal-rector/rector_examples web/modules/custom # dry-run is expected to return exit code 1 if there are changes, which we are expecting to happen, here. - name: Run rector against Drupal (dry-run) run: | @@ -54,4 +55,11 @@ jobs: run: | cd ~/drupal vendor/bin/rector process web/modules/custom/rector_examples --debug - - run: diff -rubB rector_examples_updated ~/drupal/web/modules/custom/rector_examples + # diff options: + # -r: recursive + # -u: show the joined context, like git diff + # -b: ignore whitespace + # -B: ignore lines that are only whitespace + - name: Check that the updated examples match expectations + run: | + diff -rubB rector_examples_updated ~/drupal/web/modules/custom/rector_examples diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml deleted file mode 100644 index 419d7a62..00000000 --- a/.github/workflows/local_package_run_rector.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: local_package_run_rector - -# This test will run on every pull request, and on every commit on any branch -on: - [push, pull_request] - -jobs: - run_rector_on_rector_examples_module: - name: rector_examples (drupal/${{ matrix.dev_dependencies_package }}) - runs-on: ubuntu-latest - strategy: - matrix: - drupal_version: - - "~8" - dev_dependencies_package: - # drupal/core-dev installs phpunit:7 - - "core-dev" - # drupal/core-dev-pinned installs phpunit:6 - - "core-dev-pinned" - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - tools: composer:v2 - extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - - - name: Setup Drupal - run: | - COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:${{ matrix.drupal_version }} ~/drupal --no-interaction - cd ~/drupal - composer config minimum-stability dev - composer config prefer-stable true - composer config preferred-install dist - composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" - composer config repositories.1 composer https://packages.drupal.org/8 - COMPOSER_MEMORY_LIMIT=-1 composer require drupal/${{ matrix.dev_dependencies_package }}:${{ matrix.drupal_version }} --with-all-dependencies - - name: require local druapl-rector - run: | - cd ~/drupal - composer require palantirnet/drupal-rector:@dev --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd ~/drupal - cp vendor/palantirnet/drupal-rector/rector.php . - - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd ~/drupal - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Run Rector - cd ~/drupal - vendor/bin/rector process web/modules/custom/rector_examples --debug - run_rector_on_webform: - name: webform check - runs-on: ubuntu-latest - # There are some non-related errors. So this run acts as a canary - # that we manually review to shake loose errors. - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - tools: composer:v2 - extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - - - name: Setup Drupal - run: | - COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction - cd ~/drupal - composer config minimum-stability dev - composer config prefer-stable true - composer config preferred-install dist - composer config repositories.0 "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" - composer config repositories.1 composer https://packages.drupal.org/8 - COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - # Include webform and its conditionally supported dependencies - COMPOSER_MEMORY_LIMIT=-1 composer require drupal/bootstrap drupal/webform - - name: require local druapl-rector - run: | - cd ~/drupal - composer require palantirnet/drupal-rector:@dev --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd ~/drupal - cp vendor/palantirnet/drupal-rector/rector.php . - - - run: | - # Run Rector - cd ~/drupal - vendor/bin/rector process web/modules/contrib/webform --debug - # @todo: remove when PHPStan doesn't choke on WebformLikert doc block - continue-on-error: true diff --git a/.github/workflows/packagist_package_run_rector.yml b/.github/workflows/packagist_package_run_rector.yml deleted file mode 100644 index 8af45450..00000000 --- a/.github/workflows/packagist_package_run_rector.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: packagist_package_run_rector - -# This test will run on every commit that is pushed to master -on: - push: - branches: - - master - -jobs: - create_drupal_artifact_and_run_rector: - name: Create Drupal artifact and run Rector - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - -# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started -# - name: Debugging with tmate -# uses: mxschmitt/action-tmate@v2 - - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 drupal --no-progress - - - run: | - # Install drupal-rector:dev-master from Github - cd drupal - # Set composer to get code from Github repo instead of Packagist (master does not exist on Packagist) - composer config repositories.drupal-rector '{"type": "vcs", "url": "https://github.com/palantirnet/drupal-rector.git"}' - composer require palantirnet/drupal-rector:dev-master --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd drupal - cp vendor/palantirnet/drupal-rector/rector.php . - - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd drupal - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Run Rector - cd drupal - vendor/bin/rector process web/modules/custom/rector_examples diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml deleted file mode 100644 index 75915a5d..00000000 --- a/.github/workflows/phpstan.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: phpstan -on: [push, pull_request] -jobs: - phpstan_analyze: - name: PHPStan Analyze - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - tools: composer:v2 - extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - - run: composer install - - run: vendor/bin/phpstan diff --git a/.github/workflows/static_analysis__phpstan.yml b/.github/workflows/static_analysis__phpstan.yml new file mode 100644 index 00000000..99382665 --- /dev/null +++ b/.github/workflows/static_analysis__phpstan.yml @@ -0,0 +1,24 @@ +name: static_analysis__phpstan + +# This test will run on every pull request, and on every commit on any branch +on: [push, pull_request] + +jobs: + run_static_analysis_phpstan_analyze: + name: Static analysis with PHPStan +# START: SHARED SETUP + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v2 +# END: SHARED SETUP + - run: composer install + - run: vendor/bin/phpstan diff --git a/.github/workflows/phpunit.yml b/.github/workflows/unit_tests__phpunit.yml similarity index 54% rename from .github/workflows/phpunit.yml rename to .github/workflows/unit_tests__phpunit.yml index 3fc50249..3f4c7974 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/unit_tests__phpunit.yml @@ -1,9 +1,13 @@ -name: phpunit +name: unit_tests__phpunit + +# This test will run on every pull request, and on every commit on any branch on: [push, pull_request] + jobs: - phpunit: - name: PHPUnit - runs-on: ubuntu-latest + run_unit_tests_with_phpunit: + name: Run unit tests with PHPUnit +# START: SHARED SETUP + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 @@ -12,6 +16,10 @@ jobs: coverage: none # disable xdebug, pcov tools: composer:v2 extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v2 +# END: SHARED SETUP - run: composer install - run: composer create-project drupal/recommended-project:^8.9 tests/fixtures/drupal - run: vendor/bin/phpunit From a1aa8896a40481ecf8edc61ee681954210b816e2 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 26 Apr 2021 14:20:23 -0500 Subject: [PATCH 42/64] Removed Behat automated tests. These are included directly in Github Actions. --- .gitignore | 3 - README-automated-testing.md | 18 ++-- behat.yml | 5 - composer.json | 1 - features/bootstrap/FeatureContext.php | 132 -------------------------- features/rector_examples.feature | 9 -- features/tmp/.placeholder | 0 7 files changed, 8 insertions(+), 160 deletions(-) delete mode 100644 behat.yml delete mode 100644 features/bootstrap/FeatureContext.php delete mode 100644 features/rector_examples.feature delete mode 100644 features/tmp/.placeholder diff --git a/.gitignore b/.gitignore index 9106b4b4..28e4c767 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,5 @@ /vendor /composer.lock -/features/tmp/* -!/features/tmp/.placeholder - /.phpunit.cache /tests/fixtures/drupal diff --git a/README-automated-testing.md b/README-automated-testing.md index a104d48a..500d980c 100644 --- a/README-automated-testing.md +++ b/README-automated-testing.md @@ -6,7 +6,11 @@ Github Workflow is used to test that this package can be installed. See `.github ## Rector automated functional tests using Behat -Behat (the Php version of Cucumber) is used to run automated tests. +No extra tool is used to run the functional test(s). + +PhpUnit is used to run unit tests. + +PHPStan is used for the static analysis tests. This uses Linux / MacOS commands, so they need to be run from that environment. @@ -24,18 +28,12 @@ Example setup: ... ``` -The tests are located in `features` with a simple `/features/bootstrap/FeatureContext.php` context file which handles running Rector and comparing files. - ### Setup -To run the Behat tests, you will need the setup mentioned above. See `.github/workflows/local_package.yml` for an example of how this is done. - -Then run `composer install` to install Behat in this repository's `vendor` directory. - -To run tests, run `vendor/bin/behat`. +@todo: Provide more information about PhpUnit / PHPStan. ### Adding tests -Tests should be pretty simple. By default, the main test feature `rector_examples.feature` will test the entire `rector_examples` folder and report any differences. Tests can also be made for individual files. +Tests should be pretty simple. By default, the main test will test the entire `rector_examples` folder and report any differences. Tests can also be made for individual files. -The Behat tests make a copy of the file or folder we are going to test, so you don't have to worry about overwriting files in those directories. +The functional tests make a copy of the file or folder we are going to test, so you don't have to worry about overwriting files in those directories. diff --git a/behat.yml b/behat.yml deleted file mode 100644 index 6ca9e925..00000000 --- a/behat.yml +++ /dev/null @@ -1,5 +0,0 @@ -default: - suites: - default: - contexts: - - FeatureContext diff --git a/composer.json b/composer.json index 5960fd00..68ca1560 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,6 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "behat/behat": "^3.6", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^0.12.82", "phpstan/phpstan-deprecation-rules": "^0.12.6", diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php deleted file mode 100644 index 3e32692d..00000000 --- a/features/bootstrap/FeatureContext.php +++ /dev/null @@ -1,132 +0,0 @@ -iRunDrupalRectorOnThe("$this->temporaryFolderPath/$this->testPath"); - } - - /** - * @When I run Drupal Rector on the file/folder :path - */ - public function iRunDrupalRectorOnThe($path) { - chdir('../drupal'); - - $output = NULL; - $return_value = NULL; - exec("vendor/bin/rector process $this->drupalRectorPath/$path", $output, $return_value); - - chdir($this->drupalRectorPath); - - if ($return_value !== 0) { - throw new Exception('Rector did not complete successfully.' . PHP_EOL - . 'Rector output:' . PHP_EOL - . join(PHP_EOL, $output) - ); - } - } - - /** - * @Given I create a test copy of the file/folder :path - */ - public function iCreateATestCopyOfThe($path) { - $this->testPath = $path; - - // Using Linux / MacOS commands, because they are simple and work well. - exec("rm -rf $this->temporaryFolderPath/$this->testPath"); - - // Make any necessary folders. - $path_parts = explode('/', $this->testPath); - if (count($path_parts) > 1) { - $directory_parts = $path_parts; - array_pop($directory_parts); - $directory = implode('/', $directory_parts); - - exec("mkdir -p $this->temporaryFolderPath/$directory"); - } - - exec("cp -R $this->testPath $this->temporaryFolderPath/$this->testPath"); - } - - /** - * @Then the test file/folder matches :path - */ - public function theTestMatches($path) { - // Using Linux / MacOS commands, because they are simple and work well. - $output = NULL; - $return_value = NULL; - /* - * -r: recursive - * -u: show the joined context, like git diff - * -b: ignore whitespace - * -B: ignore lines that are only whitespace - */ - exec("diff -rubB $path $this->temporaryFolderPath/$this->testPath", $output, $return_value); - - if ($return_value !== 0) { - throw new Exception('The test does not match.' . PHP_EOL . PHP_EOL - . join(PHP_EOL, $output) . PHP_EOL . PHP_EOL - ); - } - } - -} diff --git a/features/rector_examples.feature b/features/rector_examples.feature deleted file mode 100644 index bcd8f255..00000000 --- a/features/rector_examples.feature +++ /dev/null @@ -1,9 +0,0 @@ -Feature: rector_examples module - As a Drupal developer - I want rector_example deprecations to be updated by Drupal Rector - So that I don't have to update them manually - - Scenario: Verify rector_examples updates match rector_examples_updated. - Given I create a test copy of the folder "rector_examples" - When I run Drupal Rector on the test folder - Then the test folder matches "rector_examples_updated" diff --git a/features/tmp/.placeholder b/features/tmp/.placeholder deleted file mode 100644 index e69de29b..00000000 From 376c576166e4707ae9582ed1f4dc70cb86b198d4 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 26 Apr 2021 14:31:03 -0500 Subject: [PATCH 43/64] Include Symfony YAML since it's required for the PhpUnit tests. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 68ca1560..0dc0875c 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,7 @@ "phpstan/phpstan": "^0.12.82", "phpstan/phpstan-deprecation-rules": "^0.12.6", "phpunit/phpunit": "^9.5", - "rector/rector": "~0.10.0" + "rector/rector": "~0.10.0", + "symfony/yaml": "^5" } } From 95eff0c0cadd446ccd7708b1ab66bc70215aee5d Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 26 Apr 2021 14:39:17 -0500 Subject: [PATCH 44/64] Recursive copy for functional test. --- .github/workflows/functional_test__rector_examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index 52550f86..81cc60be 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -45,7 +45,7 @@ jobs: run: | cd ~/drupal mkdir -p web/modules/custom - cp vendor/palantirnet/drupal-rector/rector_examples web/modules/custom + cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom # dry-run is expected to return exit code 1 if there are changes, which we are expecting to happen, here. - name: Run rector against Drupal (dry-run) run: | From 1d9dfe263984d1e5a33e8a8d8f38c80b14df9b88 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 28 Apr 2021 15:00:55 -0500 Subject: [PATCH 45/64] Document running PHPUnit --- README-automated-testing.md | 26 +++++++++++++++++++++++++- composer.json | 9 +++++++++ phpunit.xml | 3 +-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README-automated-testing.md b/README-automated-testing.md index 500d980c..8e2a619d 100644 --- a/README-automated-testing.md +++ b/README-automated-testing.md @@ -30,10 +30,34 @@ Example setup: ### Setup -@todo: Provide more information about PhpUnit / PHPStan. +To run the base PHPUnit tests, which run unit tests against Rectors rules, just run the following: + +``` +php vendor/bin/phpunit +``` + +You will see that some tests were skipped. These are the Drupal integration tests. To run those, run the following commands: + +``` +composer run-script phpunit-drupal8-fixture +``` + +Now, when you run PHPUnit, the Drupal integration tests will run. + +``` +php vendor/bin/phpunit +``` ### Adding tests +#### Rector Rules PHPUnit tests + +We follow the same testing pattern as Rector. + +Read their wonderful documentation: https://github.com/rectorphp/rector/blob/main/docs/how_to_add_test_for_rector_rule.md + +#### Functional tests + Tests should be pretty simple. By default, the main test will test the entire `rector_examples` folder and report any differences. Tests can also be made for individual files. The functional tests make a copy of the file or folder we are going to test, so you don't have to worry about overwriting files in those directories. diff --git a/composer.json b/composer.json index 0dc0875c..7453e0ac 100644 --- a/composer.json +++ b/composer.json @@ -60,5 +60,14 @@ "phpunit/phpunit": "^9.5", "rector/rector": "~0.10.0", "symfony/yaml": "^5" + }, + "scripts": { + "phpunit-drupal8-fixture": [ + "composer create-project drupal/recommended-project:^8.9 tests/fixtures/drupal", + "composer require --dev drupal/core-dev:^8.9 --working-dir tests/fixtures/drupal" + ] + }, + "scripts-descriptions": { + "phpunit-drupal8-fixture": "Installs a Drupal 8 site for integration testing with PHPUnit" } } diff --git a/phpunit.xml b/phpunit.xml index 23cf6f69..2bb48f5f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,8 +8,7 @@ beStrictAboutTodoAnnotatedTests="true" colors="true" failOnRisky="true" - failOnWarning="true" - verbose="true"> + failOnWarning="true"> tests/src From e821abda39700bb3e38fcc1d3b8fc71f53133f06 Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 28 Apr 2021 15:06:38 -0500 Subject: [PATCH 46/64] Add documentation about PHP version --- README-automated-testing.md | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/README-automated-testing.md b/README-automated-testing.md index 8e2a619d..c4b8c39e 100644 --- a/README-automated-testing.md +++ b/README-automated-testing.md @@ -4,32 +4,15 @@ Github Workflow is used to test that this package can be installed. See `.github`. -## Rector automated functional tests using Behat +## Rector automated tests -No extra tool is used to run the functional test(s). - -PhpUnit is used to run unit tests. - -PHPStan is used for the static analysis tests. - -This uses Linux / MacOS commands, so they need to be run from that environment. - -These tests assume that this repository is installed as a local composer package. This is necessary, because we need a full Drupal site to run the Rector tests. - -Example setup: -``` -# This repository -/drupal-rector -# Drupal -/web/core -/web/index.php -# A Composer vendor directory -/vendor/bin/rector -... -``` +* PHPUnit is used to run unit tests. +* PHPStan is used for the static analysis tests. ### Setup +We are currently running our tests on PHP 7.3, you may encounter problems when running on PHP 7.4. + To run the base PHPUnit tests, which run unit tests against Rectors rules, just run the following: ``` From cd9afac8287a5ef9c70389e1dca3c8cf940ac5fe Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 15:15:13 -0500 Subject: [PATCH 47/64] Remove test fixture before trying to install them to address error. --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 7453e0ac..747dd0c6 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,7 @@ }, "scripts": { "phpunit-drupal8-fixture": [ + "rm -rf tests/fixtures/drupal", "composer create-project drupal/recommended-project:^8.9 tests/fixtures/drupal", "composer require --dev drupal/core-dev:^8.9 --working-dir tests/fixtures/drupal" ] From 91bae6f04fb97eba194305d520e5483b38b0117f Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 15:16:02 -0500 Subject: [PATCH 48/64] Instruct people to set up the test fixtures. This seems like a safer bet then getting the errors. --- README-automated-testing.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README-automated-testing.md b/README-automated-testing.md index c4b8c39e..0a20673c 100644 --- a/README-automated-testing.md +++ b/README-automated-testing.md @@ -13,23 +13,21 @@ Github Workflow is used to test that this package can be installed. See `.github We are currently running our tests on PHP 7.3, you may encounter problems when running on PHP 7.4. -To run the base PHPUnit tests, which run unit tests against Rectors rules, just run the following: +Set up Drupal integration fixtures. ``` -php vendor/bin/phpunit +composer run-script phpunit-drupal8-fixture ``` -You will see that some tests were skipped. These are the Drupal integration tests. To run those, run the following commands: +### Running tests locally ``` -composer run-script phpunit-drupal8-fixture +vendor/bin/phpunit ``` -Now, when you run PHPUnit, the Drupal integration tests will run. +If you did not set up the Drupal integration fixtures, this will produce errors and skip a few of the Drupal integration tests. These errors can be ignored, or you can set up the integration as described above. -``` -php vendor/bin/phpunit -``` +`DrupalRector\Tests\DrupalIntegrationTest::testIntegration` ... `OutOfBoundsException: Package "rector/rector" is not installed` ### Adding tests From dc2a835e6e35a2cedd5b99731f355644c6186fe5 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 15:17:36 -0500 Subject: [PATCH 49/64] Document pieces of the DrupalIntegrationTest. Add some comments on parts that were not immediately obvious to me. --- tests/src/DrupalIntegrationTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index ac1f4935..3aede26e 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -15,6 +15,9 @@ final class DrupalIntegrationTest extends TestCase { + /** + * Check that the integration test fixtures have been set up. + */ protected function setUp(): void { parent::setUp(); @@ -31,6 +34,8 @@ protected function setUp(): void } /** + * Test that certain Drupal Rector rules are run on certain files. + * * @dataProvider integrationData */ public function testIntegration(string $source, array $applied_rules) @@ -54,6 +59,7 @@ public function testIntegration(string $source, array $applied_rules) $command = $application->find('process'); $commandTester = new CommandTester($command); + // Capture the output of the command. ob_start(); $commandTester->execute([ 'source' => $source, @@ -65,8 +71,14 @@ public function testIntegration(string $source, array $applied_rules) 'verbosity' => OutputInterface::VERBOSITY_DEBUG ]); $output = json_decode(ob_get_clean()); + + // Check that there are no errors produced. self::assertObjectNotHasAttribute('errors', $output, var_export($output, true)); + + // Check that there is a list of file_diffs. self::assertObjectHasAttribute('file_diffs', $output); + + // Check that the rule we expect to apply is reported as applied. self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); } From 6ed284e3bf2f1c8b39a6c2aee06ffc7a1e087cae Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 15:22:24 -0500 Subject: [PATCH 50/64] Update test badges. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 16d3b4ef..137d120f 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Automate fixing deprecated Drupal code. ## Status -![local_package_functional_tests](https://github.com/palantirnet/drupal-rector/workflows/local_package_functional_tests/badge.svg) -![local_package_run_rector](https://github.com/palantirnet/drupal-rector/workflows/local_package_run_rector/badge.svg) -![packagist_package_run_rector](https://github.com/palantirnet/drupal-rector/workflows/packagist_package_run_rector/badge.svg) +![Functional test: Rector examples](https://github.com/palantirnet/drupal-rector/workflows/functional_test__rector_examples/badge.svg) +![Static analysis: PhpStan](https://github.com/palantirnet/drupal-rector/workflows/static_analysis__phpstan/badge.svg) +![Unit test: PHPUnit](https://github.com/palantirnet/drupal-rector/workflows/unit_tests__php_unit/badge.svg) ## Introduction From 010904d430069a0f226fc88852abec165df72ccc Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 15:39:19 -0500 Subject: [PATCH 51/64] Add todo for automated functional test. --- README-automated-testing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README-automated-testing.md b/README-automated-testing.md index 0a20673c..1785e254 100644 --- a/README-automated-testing.md +++ b/README-automated-testing.md @@ -39,6 +39,8 @@ Read their wonderful documentation: https://github.com/rectorphp/rector/blob/mai #### Functional tests +@todo Describe how to run a functional test locally. Right now, it can only be done as part of the Github Action. + Tests should be pretty simple. By default, the main test will test the entire `rector_examples` folder and report any differences. Tests can also be made for individual files. The functional tests make a copy of the file or folder we are going to test, so you don't have to worry about overwriting files in those directories. From 48a6b0d6b3f3b60d217c8760009f130da51a2311 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 15:41:01 -0500 Subject: [PATCH 52/64] Remove skip option since it doesn't have any values. --- config/drupal-8/drupal-8-all-deprecations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php index 7308790b..914e7494 100644 --- a/config/drupal-8/drupal-8-all-deprecations.php +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -9,7 +9,6 @@ $containerConfigurator->import(__DIR__ . '/drupal-8.*'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::SKIP, []); $parameters->set(Option::BOOTSTRAP_FILES, [ __DIR__ . '/../drupal-phpunit-bootstrap-file.php' ]); From d67c9d82274f2f6ce247bd83293cf066ebab2233 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 16:39:38 -0500 Subject: [PATCH 53/64] Revert dev tools updates. Trying to see if this may work with just the rector changes. --- .editorconfig | 4 - .../local_package_functional_tests.yml | 59 +++++++ .../workflows/local_package_run_rector.yml | 48 ++++++ .../packagist_package_run_rector.yml | 51 ++++++ .gitignore | 4 +- README-automated-testing.md | 47 +++-- behat.yml | 5 + composer.json | 27 +-- features/bootstrap/FeatureContext.php | 163 ++++++++++++++++++ features/deprecation-index.feature | 15 ++ features/rector_examples.feature | 9 + features/tmp/.placeholder | 0 phpstan.neon | 6 - phpunit.xml | 24 --- tests/config/rector-phpunit.php | 32 ---- tests/fixtures/.gitignore | 1 - tests/src/DeprecationIndexTest.php | 27 --- tests/src/DrupalIntegrationTest.php | 104 ----------- .../DatetimeStorageTimezoneRectorTest.php | 37 ---- .../config/configured_rule.php | 12 -- .../fixture/fixture.php.inc | 21 --- 21 files changed, 375 insertions(+), 321 deletions(-) create mode 100644 .github/workflows/local_package_functional_tests.yml create mode 100644 .github/workflows/local_package_run_rector.yml create mode 100644 .github/workflows/packagist_package_run_rector.yml create mode 100644 behat.yml create mode 100644 features/bootstrap/FeatureContext.php create mode 100644 features/deprecation-index.feature create mode 100644 features/rector_examples.feature create mode 100644 features/tmp/.placeholder delete mode 100644 phpstan.neon delete mode 100644 phpunit.xml delete mode 100644 tests/config/rector-phpunit.php delete mode 100644 tests/fixtures/.gitignore delete mode 100644 tests/src/DeprecationIndexTest.php delete mode 100644 tests/src/DrupalIntegrationTest.php delete mode 100644 tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php delete mode 100644 tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php delete mode 100644 tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc diff --git a/.editorconfig b/.editorconfig index 49864369..e1b987c7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,3 @@ insert_final_newline = true [composer.{json,lock}] indent_size = 4 - -[*.neon] -indent_size = 4 -indent_style = tab diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml new file mode 100644 index 00000000..c3bee15d --- /dev/null +++ b/.github/workflows/local_package_functional_tests.yml @@ -0,0 +1,59 @@ +name: local_package_functional_tests + +# This test will run on every pull request, and on every commit on any branch +on: + [push, pull_request] + +jobs: + functional_tests: + name: Run functional tests using Behat + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + extensions: "intl" + + # This is copied from `local_package_run_rector`. + - run: | + # Download the latest Drupal core project and all its dependencies + composer create-project drupal/recommended-project:~8 ../drupal --no-progress + mv ../drupal/* .. + + # This is copied from `local_package_run_rector`. + - run: | + # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) + cd .. + composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' + composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress + + # This is copied from `local_package_run_rector`. + - run: | + # Prepare rector config files with Drupal specific settings + cd .. + cp vendor/palantirnet/drupal-rector/rector.yml . + + # This is copied from `local_package_run_rector`. + # This seems needed for the autoloading to work. + - run: | + # Prepare rector_examples folder in the drupal modules directory + cd .. + mkdir -p web/modules/custom + cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. + + - run: | + # Install phpunit/phpunit on the Drupal site since it's needed for some of our examples. + cd .. + composer require phpunit/phpunit:~7.5 + + - run: | + # Install local packages, including Behat + composer install + + # - uses: mxschmitt/action-tmate@v2 + + - run: | + # Run Behat + vendor/bin/behat diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml new file mode 100644 index 00000000..8ee9d0e3 --- /dev/null +++ b/.github/workflows/local_package_run_rector.yml @@ -0,0 +1,48 @@ +name: local_package_run_rector + +# This test will run on every pull request, and on every commit on any branch +on: + [push, pull_request] + +jobs: + run_rector_on_rector_examples_module: + name: Run Drupal Rector + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + extensions: "intl" + +# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started +# - name: Debugging with tmate +# uses: mxschmitt/action-tmate@v2 + + - run: | + # Download the latest Drupal core project and all its dependencies + composer create-project drupal/recommended-project:~8 ../drupal --no-progress + mv ../drupal/* .. + + - run: | + # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) + cd .. + composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' + composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress + + - run: | + # Prepare rector config files with Drupal specific settings + cd .. + cp vendor/palantirnet/drupal-rector/rector.yml . + + - run: | + # Prepare rector_examples folder in the drupal modules directory + cd .. + mkdir -p web/modules/custom + cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. + + - run: | + # Run Rector + cd .. + vendor/bin/rector process web/modules/custom/rector_examples diff --git a/.github/workflows/packagist_package_run_rector.yml b/.github/workflows/packagist_package_run_rector.yml new file mode 100644 index 00000000..6cdf85b5 --- /dev/null +++ b/.github/workflows/packagist_package_run_rector.yml @@ -0,0 +1,51 @@ +name: packagist_package_run_rector + +# This test will run on every pull request, and on every commit that is pushed to master +on: + pull_request: null + push: + branches: + - master + +jobs: + create_drupal_artifact_and_run_rector: + name: Create Drupal artifact and run Rector + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + extensions: "intl" + +# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started +# - name: Debugging with tmate +# uses: mxschmitt/action-tmate@v2 + + - run: | + # Download the latest Drupal core project and all its dependencies + composer create-project drupal/recommended-project:~8 drupal --no-progress + + - run: | + # Install drupal-rector:dev-master from Github + cd drupal + # Set composer to get code from Github repo instead of Packagist (master does not exist on Packagist) + composer config repositories.drupal-rector '{"type": "vcs", "url": "https://github.com/palantirnet/drupal-rector.git"}' + composer require palantirnet/drupal-rector:dev-master --no-progress + + - run: | + # Prepare rector config files with Drupal specific settings + cd drupal + cp vendor/palantirnet/drupal-rector/rector.yml . + + - run: | + # Prepare rector_examples folder in the drupal modules directory + cd drupal + mkdir -p web/modules/custom + cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. + + - run: | + # Run Rector + cd drupal + vendor/bin/rector process web/modules/custom/rector_examples diff --git a/.gitignore b/.gitignore index 28e4c767..f861eff1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,5 @@ /vendor /composer.lock -/.phpunit.cache -/tests/fixtures/drupal +/features/tmp/* +!/features/tmp/.placeholder diff --git a/README-automated-testing.md b/README-automated-testing.md index 1785e254..a104d48a 100644 --- a/README-automated-testing.md +++ b/README-automated-testing.md @@ -4,43 +4,38 @@ Github Workflow is used to test that this package can be installed. See `.github`. -## Rector automated tests +## Rector automated functional tests using Behat -* PHPUnit is used to run unit tests. -* PHPStan is used for the static analysis tests. +Behat (the Php version of Cucumber) is used to run automated tests. -### Setup - -We are currently running our tests on PHP 7.3, you may encounter problems when running on PHP 7.4. - -Set up Drupal integration fixtures. - -``` -composer run-script phpunit-drupal8-fixture -``` +This uses Linux / MacOS commands, so they need to be run from that environment. -### Running tests locally +These tests assume that this repository is installed as a local composer package. This is necessary, because we need a full Drupal site to run the Rector tests. +Example setup: ``` -vendor/bin/phpunit +# This repository +/drupal-rector +# Drupal +/web/core +/web/index.php +# A Composer vendor directory +/vendor/bin/rector +... ``` -If you did not set up the Drupal integration fixtures, this will produce errors and skip a few of the Drupal integration tests. These errors can be ignored, or you can set up the integration as described above. +The tests are located in `features` with a simple `/features/bootstrap/FeatureContext.php` context file which handles running Rector and comparing files. -`DrupalRector\Tests\DrupalIntegrationTest::testIntegration` ... `OutOfBoundsException: Package "rector/rector" is not installed` - -### Adding tests - -#### Rector Rules PHPUnit tests +### Setup -We follow the same testing pattern as Rector. +To run the Behat tests, you will need the setup mentioned above. See `.github/workflows/local_package.yml` for an example of how this is done. -Read their wonderful documentation: https://github.com/rectorphp/rector/blob/main/docs/how_to_add_test_for_rector_rule.md +Then run `composer install` to install Behat in this repository's `vendor` directory. -#### Functional tests +To run tests, run `vendor/bin/behat`. -@todo Describe how to run a functional test locally. Right now, it can only be done as part of the Github Action. +### Adding tests -Tests should be pretty simple. By default, the main test will test the entire `rector_examples` folder and report any differences. Tests can also be made for individual files. +Tests should be pretty simple. By default, the main test feature `rector_examples.feature` will test the entire `rector_examples` folder and report any differences. Tests can also be made for individual files. -The functional tests make a copy of the file or folder we are going to test, so you don't have to worry about overwriting files in those directories. +The Behat tests make a copy of the file or folder we are going to test, so you don't have to worry about overwriting files in those directories. diff --git a/behat.yml b/behat.yml new file mode 100644 index 00000000..6ca9e925 --- /dev/null +++ b/behat.yml @@ -0,0 +1,5 @@ +default: + suites: + default: + contexts: + - FeatureContext diff --git a/composer.json b/composer.json index 747dd0c6..542310cf 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,7 @@ "ast" ], "require": { - "rector/rector-prefixed": "~0.10.0", - "webflo/drupal-finder": "^1.2" + "rector/rector-prefixed": "~0.10.0" }, "license": "MIT", "authors": [ @@ -29,18 +28,10 @@ } ], "autoload": { - "files": [ - "drupal-phpunit-hack.php" - ], "psr-4": { "DrupalRector\\": "src" } }, - "autoload-dev": { - "psr-4": { - "DrupalRector\\Tests\\": "tests/src" - } - }, "config": { "optimize-autoloader": true, "update-with-dependencies": true, @@ -54,21 +45,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^0.12.82", - "phpstan/phpstan-deprecation-rules": "^0.12.6", - "phpunit/phpunit": "^9.5", - "rector/rector": "~0.10.0", + "behat/behat": "^3.6", "symfony/yaml": "^5" - }, - "scripts": { - "phpunit-drupal8-fixture": [ - "rm -rf tests/fixtures/drupal", - "composer create-project drupal/recommended-project:^8.9 tests/fixtures/drupal", - "composer require --dev drupal/core-dev:^8.9 --working-dir tests/fixtures/drupal" - ] - }, - "scripts-descriptions": { - "phpunit-drupal8-fixture": "Installs a Drupal 8 site for integration testing with PHPUnit" } } diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php new file mode 100644 index 00000000..511b8a53 --- /dev/null +++ b/features/bootstrap/FeatureContext.php @@ -0,0 +1,163 @@ +iRunDrupalRectorOnThe("$this->temporaryFolderPath/$this->testPath"); + } + + /** + * @When I run Drupal Rector on the file/folder :path + */ + public function iRunDrupalRectorOnThe($path) { + chdir('..'); + + $output = NULL; + $return_value = NULL; + exec("vendor/bin/rector process $this->drupalRectorPath/$path", $output, $return_value); + + chdir($this->drupalRectorPath); + + if ($return_value !== 0) { + throw new Exception('Rector did not complete successfully.' . PHP_EOL + . 'Rector output:' . PHP_EOL + . join(PHP_EOL, $output) + ); + } + } + + /** + * @Given I create a test copy of the file/folder :path + */ + public function iCreateATestCopyOfThe($path) { + $this->testPath = $path; + + // Using Linux / MacOS commands, because they are simple and work well. + exec("rm -rf $this->temporaryFolderPath/$this->testPath"); + + // Make any necessary folders. + $path_parts = explode('/', $this->testPath); + if (count($path_parts) > 1) { + $directory_parts = $path_parts; + array_pop($directory_parts); + $directory = implode('/', $directory_parts); + + exec("mkdir -p $this->temporaryFolderPath/$directory"); + } + + exec("cp -R $this->testPath $this->temporaryFolderPath/$this->testPath"); + } + + /** + * @Then the test file/folder matches :path + */ + public function theTestMatches($path) { + // Using Linux / MacOS commands, because they are simple and work well. + $output = NULL; + $return_value = NULL; + /* + * -r: recursive + * -u: show the joined context, like git diff + * -b: ignore whitespace + * -B: ignore lines that are only whitespace + */ + exec("diff -rubB $path $this->temporaryFolderPath/$this->testPath", $output, $return_value); + + if ($return_value !== 0) { + throw new Exception('The test does not match.' . PHP_EOL . PHP_EOL + . join(PHP_EOL, $output) . PHP_EOL . PHP_EOL + ); + } + } + + /** + * @When I examine the :file file + */ + public function iExamineTheFile($file) { + $this->examinedFileContents = file_get_contents($file); + + if ($this->examinedFileContents === FALSE) { + throw new Exception("The file $file could not be read."); + } + } + + /** + * @Then The file is valid YAML + */ + public function theFileIsValidYaml() { + try { + $parsed_data = Yaml::parse($this->examinedFileContents); + } + catch (ParseException $exception) { + throw new Exception("The YAML was not valid. This is often caused by unescaped quotes. Please use `'` to escape a single quote.\n\n{$exception->getMessage()}"); + } + } + + /** + * @Then The file only uses ASCII characters. + */ + public function theFileOnlyHasASCIICharacters() { + if (mb_detect_encoding($this->examinedFileContents, 'ASCII', TRUE) === FALSE) { + throw new Exception('The file contains non ASCII characters. Please make sure `\` and spaces are only using ASCII characters.'); + } + } +} diff --git a/features/deprecation-index.feature b/features/deprecation-index.feature new file mode 100644 index 00000000..cac25508 --- /dev/null +++ b/features/deprecation-index.feature @@ -0,0 +1,15 @@ +Feature: deprecation-index.yml + As a Drupal developer + I want the deprecation-index.yml file to parse cleanly + So that other systems can reference this file + + # Most often, quotes are not escaped. + Scenario: deprecation-index.yml is valid YAML + When I examine the "deprecation-index.yml" file + Then The file is valid YAML + + # Unicode characters sometimes get added when copy & pasting. + # They are not intended and don't match as easily. + Scenario: deprecation-index.yml only uses ASCII characters + When I examine the "deprecation-index.yml" file + Then The file only uses ASCII characters. diff --git a/features/rector_examples.feature b/features/rector_examples.feature new file mode 100644 index 00000000..bcd8f255 --- /dev/null +++ b/features/rector_examples.feature @@ -0,0 +1,9 @@ +Feature: rector_examples module + As a Drupal developer + I want rector_example deprecations to be updated by Drupal Rector + So that I don't have to update them manually + + Scenario: Verify rector_examples updates match rector_examples_updated. + Given I create a test copy of the folder "rector_examples" + When I run Drupal Rector on the test folder + Then the test folder matches "rector_examples_updated" diff --git a/features/tmp/.placeholder b/features/tmp/.placeholder new file mode 100644 index 00000000..e69de29b diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 440f6abd..00000000 --- a/phpstan.neon +++ /dev/null @@ -1,6 +0,0 @@ -parameters: - level: 0 - paths: - - config - - src - - rector.php diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 2bb48f5f..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - tests/src - tests/fixtures - - - - - src - - - diff --git a/tests/config/rector-phpunit.php b/tests/config/rector-phpunit.php deleted file mode 100644 index 78d36416..00000000 --- a/tests/config/rector-phpunit.php +++ /dev/null @@ -1,32 +0,0 @@ -import(__DIR__ . '/../../config/drupal-8/drupal-8-all-deprecations.php'); - - $drupalRoot = __DIR__ . '/../fixtures/drupal/web'; - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTOLOAD_PATHS, [ - $drupalRoot . '/core', - $drupalRoot . '/modules', - $drupalRoot . '/profiles', - ]); - - $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); - $parameters->set(Option::AUTO_IMPORT_NAMES, true); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - $parameters->set(Option::IMPORT_DOC_BLOCKS, false); - - $parameters->set('drupal_rector_notices_as_comments', true); -}; diff --git a/tests/fixtures/.gitignore b/tests/fixtures/.gitignore deleted file mode 100644 index 4d59665d..00000000 --- a/tests/fixtures/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/MutatedTestCase.php diff --git a/tests/src/DeprecationIndexTest.php b/tests/src/DeprecationIndexTest.php deleted file mode 100644 index 21163958..00000000 --- a/tests/src/DeprecationIndexTest.php +++ /dev/null @@ -1,27 +0,0 @@ -provide(); - }; - $bootstrapConfigs = $callable(); - - $rectorContainerFactory = new RectorContainerFactory(); - $container = $rectorContainerFactory->createFromBootstrapConfigs($bootstrapConfigs); - - /** @var ConsoleApplication $application */ - $application = $container->get(ConsoleApplication::class); - $command = $application->find('process'); - $commandTester = new CommandTester($command); - - // Capture the output of the command. - ob_start(); - $commandTester->execute([ - 'source' => $source, - '--dry-run' => true, - '--output-format' => 'json', - ], [ - 'capture_stderr_separately' => true, - 'decorated' => true, - 'verbosity' => OutputInterface::VERBOSITY_DEBUG - ]); - $output = json_decode(ob_get_clean()); - - // Check that there are no errors produced. - self::assertObjectNotHasAttribute('errors', $output, var_export($output, true)); - - // Check that there is a list of file_diffs. - self::assertObjectHasAttribute('file_diffs', $output); - - // Check that the rule we expect to apply is reported as applied. - self::assertEquals($applied_rules, $output->file_diffs[0]->applied_rectors); - } - - public function integrationData(): \Generator { - yield [ - __DIR__ . '/../../rector_examples/datetime_date_storage_format.php', - [DatetimeDateStorageFormatRector::class] - ]; - yield [ - __DIR__ . '/../../rector_examples/src/FileCreateDirectoryNoUseStatement.php', - [FileCreateDirectoryRector::class] - ]; - yield [ - __DIR__ . '/../../rector_examples/drupal_set_message.php', - [DrupalSetMessageRector::class] - ]; - yield [ - __DIR__ . '/../../rector_examples/test/src/Functional/BrowserTestBaseGetMock.php', - [BrowserTestBaseGetMockRector::class] - ]; - } - -} diff --git a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php deleted file mode 100644 index d9f2c058..00000000 --- a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/DatetimeStorageTimezoneRectorTest.php +++ /dev/null @@ -1,37 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/fixture'); - } - - public function provideConfigFilePath(): string - { - // must be implemented - return __DIR__ . '/config/configured_rule.php'; - } - -} diff --git a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php deleted file mode 100644 index a6a0a21d..00000000 --- a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/config/configured_rule.php +++ /dev/null @@ -1,12 +0,0 @@ -services(); - - $services->set(DatetimeStorageTimezoneRector::class); -}; diff --git a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc b/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc deleted file mode 100644 index d10ece7c..00000000 --- a/tests/src/Rector/Deprecation/DatetimeStorageTimezoneRector/fixture/fixture.php.inc +++ /dev/null @@ -1,21 +0,0 @@ - ------ - From a57d96ca0d0d21471eabb94150afb6ad115b319d Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 16:55:20 -0500 Subject: [PATCH 54/64] Update Github Actions workflows. Remove ones missed in the last commit and update the functional test. --- .github/workflows/canary__webform_module.yml | 55 ----------------- .../functional_test__rector_examples.yml | 27 +++------ .../local_package_functional_tests.yml | 59 ------------------- .../workflows/local_package_run_rector.yml | 48 --------------- .../packagist_package_run_rector.yml | 51 ---------------- .../workflows/static_analysis__phpstan.yml | 24 -------- .github/workflows/unit_tests__phpunit.yml | 25 -------- README.md | 2 - 8 files changed, 9 insertions(+), 282 deletions(-) delete mode 100644 .github/workflows/canary__webform_module.yml delete mode 100644 .github/workflows/local_package_functional_tests.yml delete mode 100644 .github/workflows/local_package_run_rector.yml delete mode 100644 .github/workflows/packagist_package_run_rector.yml delete mode 100644 .github/workflows/static_analysis__phpstan.yml delete mode 100644 .github/workflows/unit_tests__phpunit.yml diff --git a/.github/workflows/canary__webform_module.yml b/.github/workflows/canary__webform_module.yml deleted file mode 100644 index 3a2ec22d..00000000 --- a/.github/workflows/canary__webform_module.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: canary__webform_module -# There are some non-related errors. So this run acts as a canary -# that we manually review to shake loose errors. - -# This test will run on every pull request, and on every commit on any branch -on: [push, pull_request] - -jobs: - run_rector_on_webform: - name: Check webform module as a canary -# START: SHARED SETUP - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - tools: composer:v2 - extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started - # - name: Debugging with tmate - # uses: mxschmitt/action-tmate@v2 -# END: SHARED SETUP -# START: SHARED DRUPAL INSTALL SETUP - - name: Setup Drupal - run: | - COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction - cd ~/drupal - composer config minimum-stability dev - composer config prefer-stable true - composer config preferred-install dist - composer config repositories.drupal composer https://packages.drupal.org/8 - COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies - # We add a local repository `repositories.0` which takes precendence over the packagist repository that is automatically added. - - name: Install Drupal Rector - run: | - cd ~/drupal - composer config repositories.drupal-rector "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" - composer require palantirnet/drupal-rector:@dev --no-progress - - name: Install Drupal Rector Config - run: | - cd ~/drupal - cp vendor/palantirnet/drupal-rector/rector.php . -# END: SHARED DRUPAL INSTALL SETUP - - name: Include webform and its conditionally supported dependencies - run: | - cd ~/drupal - COMPOSER_MEMORY_LIMIT=-1 composer require drupal/bootstrap drupal/webform - - run: | - # Run Rector - cd ~/drupal - vendor/bin/rector process web/modules/contrib/webform --debug - # @todo: remove when PHPStan doesn't choke on WebformLikert doc block - continue-on-error: true diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index 81cc60be..b1a3c149 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -41,25 +41,16 @@ jobs: cd ~/drupal cp vendor/palantirnet/drupal-rector/rector.php . # END: SHARED DRUPAL INSTALL SETUP - - name: Prepare rector_examples folder in the drupal modules directory - run: | - cd ~/drupal - mkdir -p web/modules/custom - cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - # dry-run is expected to return exit code 1 if there are changes, which we are expecting to happen, here. - - name: Run rector against Drupal (dry-run) + - name: Install PHPUnit in the Drupal site since it is required for some of the rules run: | cd ~/drupal - vendor/bin/rector process web/modules/custom/rector_examples --dry-run --debug || if (($? == 1)); then true; else false; fi - - name: Run rector against Drupal + composer require phpunit/phpunit:~7.5 --no-progress + - name: Prepare rector_examples folder in the drupal modules directory run: | cd ~/drupal - vendor/bin/rector process web/modules/custom/rector_examples --debug - # diff options: - # -r: recursive - # -u: show the joined context, like git diff - # -b: ignore whitespace - # -B: ignore lines that are only whitespace - - name: Check that the updated examples match expectations - run: | - diff -rubB rector_examples_updated ~/drupal/web/modules/custom/rector_examples + mkdir -p web/modules/custom + cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom + - name: Install local dependencies, including Behat. + run: composer install + - name: Run Behat tests + run: vendor/bin/behat diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml deleted file mode 100644 index c3bee15d..00000000 --- a/.github/workflows/local_package_functional_tests.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: local_package_functional_tests - -# This test will run on every pull request, and on every commit on any branch -on: - [push, pull_request] - -jobs: - functional_tests: - name: Run functional tests using Behat - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - - # This is copied from `local_package_run_rector`. - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 ../drupal --no-progress - mv ../drupal/* .. - - # This is copied from `local_package_run_rector`. - - run: | - # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) - cd .. - composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' - composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress - - # This is copied from `local_package_run_rector`. - - run: | - # Prepare rector config files with Drupal specific settings - cd .. - cp vendor/palantirnet/drupal-rector/rector.yml . - - # This is copied from `local_package_run_rector`. - # This seems needed for the autoloading to work. - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd .. - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Install phpunit/phpunit on the Drupal site since it's needed for some of our examples. - cd .. - composer require phpunit/phpunit:~7.5 - - - run: | - # Install local packages, including Behat - composer install - - # - uses: mxschmitt/action-tmate@v2 - - - run: | - # Run Behat - vendor/bin/behat diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml deleted file mode 100644 index 8ee9d0e3..00000000 --- a/.github/workflows/local_package_run_rector.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: local_package_run_rector - -# This test will run on every pull request, and on every commit on any branch -on: - [push, pull_request] - -jobs: - run_rector_on_rector_examples_module: - name: Run Drupal Rector - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - -# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started -# - name: Debugging with tmate -# uses: mxschmitt/action-tmate@v2 - - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 ../drupal --no-progress - mv ../drupal/* .. - - - run: | - # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) - cd .. - composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' - composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd .. - cp vendor/palantirnet/drupal-rector/rector.yml . - - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd .. - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Run Rector - cd .. - vendor/bin/rector process web/modules/custom/rector_examples diff --git a/.github/workflows/packagist_package_run_rector.yml b/.github/workflows/packagist_package_run_rector.yml deleted file mode 100644 index 6cdf85b5..00000000 --- a/.github/workflows/packagist_package_run_rector.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: packagist_package_run_rector - -# This test will run on every pull request, and on every commit that is pushed to master -on: - pull_request: null - push: - branches: - - master - -jobs: - create_drupal_artifact_and_run_rector: - name: Create Drupal artifact and run Rector - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - -# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started -# - name: Debugging with tmate -# uses: mxschmitt/action-tmate@v2 - - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 drupal --no-progress - - - run: | - # Install drupal-rector:dev-master from Github - cd drupal - # Set composer to get code from Github repo instead of Packagist (master does not exist on Packagist) - composer config repositories.drupal-rector '{"type": "vcs", "url": "https://github.com/palantirnet/drupal-rector.git"}' - composer require palantirnet/drupal-rector:dev-master --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd drupal - cp vendor/palantirnet/drupal-rector/rector.yml . - - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd drupal - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Run Rector - cd drupal - vendor/bin/rector process web/modules/custom/rector_examples diff --git a/.github/workflows/static_analysis__phpstan.yml b/.github/workflows/static_analysis__phpstan.yml deleted file mode 100644 index 99382665..00000000 --- a/.github/workflows/static_analysis__phpstan.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: static_analysis__phpstan - -# This test will run on every pull request, and on every commit on any branch -on: [push, pull_request] - -jobs: - run_static_analysis_phpstan_analyze: - name: Static analysis with PHPStan -# START: SHARED SETUP - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - tools: composer:v2 - extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started - # - name: Debugging with tmate - # uses: mxschmitt/action-tmate@v2 -# END: SHARED SETUP - - run: composer install - - run: vendor/bin/phpstan diff --git a/.github/workflows/unit_tests__phpunit.yml b/.github/workflows/unit_tests__phpunit.yml deleted file mode 100644 index 3f4c7974..00000000 --- a/.github/workflows/unit_tests__phpunit.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: unit_tests__phpunit - -# This test will run on every pull request, and on every commit on any branch -on: [push, pull_request] - -jobs: - run_unit_tests_with_phpunit: - name: Run unit tests with PHPUnit -# START: SHARED SETUP - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - tools: composer:v2 - extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv - # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started - # - name: Debugging with tmate - # uses: mxschmitt/action-tmate@v2 -# END: SHARED SETUP - - run: composer install - - run: composer create-project drupal/recommended-project:^8.9 tests/fixtures/drupal - - run: vendor/bin/phpunit diff --git a/README.md b/README.md index 137d120f..d7a07f7e 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ Automate fixing deprecated Drupal code. ## Status ![Functional test: Rector examples](https://github.com/palantirnet/drupal-rector/workflows/functional_test__rector_examples/badge.svg) -![Static analysis: PhpStan](https://github.com/palantirnet/drupal-rector/workflows/static_analysis__phpstan/badge.svg) -![Unit test: PHPUnit](https://github.com/palantirnet/drupal-rector/workflows/unit_tests__php_unit/badge.svg) ## Introduction From 2a1da721b3a9fa51e9bcd7a9723fffbd72bba103 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 16:58:46 -0500 Subject: [PATCH 55/64] DEBUG ENABLED --- .github/workflows/functional_test__rector_examples.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index b1a3c149..e0b08a99 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -52,5 +52,8 @@ jobs: cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - name: Install local dependencies, including Behat. run: composer install + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + - name: Debugging with tmate + uses: mxschmitt/action-tmate@v2 - name: Run Behat tests run: vendor/bin/behat From a4b21b1a9d2eddeb7be9f9864f4e0e53368fb105 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 17:28:29 -0500 Subject: [PATCH 56/64] Remove more pieces that have to do with PhpUnit. --- composer.json | 3 +- config/drupal-8/drupal-8-all-deprecations.php | 3 - config/drupal-phpunit-bootstrap-file.php | 183 ------------------ drupal-phpunit-hack.php | 39 ---- 4 files changed, 2 insertions(+), 226 deletions(-) delete mode 100644 config/drupal-phpunit-bootstrap-file.php delete mode 100644 drupal-phpunit-hack.php diff --git a/composer.json b/composer.json index 542310cf..5349b9ed 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "ast" ], "require": { - "rector/rector-prefixed": "~0.10.0" + "rector/rector-prefixed": "~0.10.0", + "webflo/drupal-finder": "^1.2" }, "license": "MIT", "authors": [ diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php index 914e7494..4c8fb42c 100644 --- a/config/drupal-8/drupal-8-all-deprecations.php +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -9,7 +9,4 @@ $containerConfigurator->import(__DIR__ . '/drupal-8.*'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::BOOTSTRAP_FILES, [ - __DIR__ . '/../drupal-phpunit-bootstrap-file.php' - ]); }; diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php deleted file mode 100644 index b2bbc30a..00000000 --- a/config/drupal-phpunit-bootstrap-file.php +++ /dev/null @@ -1,183 +0,0 @@ -parameterProvider; -if ($parameterProvider === NULL) { - throw new ShouldNotHappenException('We were unable to access the parameter provider from the BootstrapFilesIncluder.'); -} - -$autoloadPaths = $parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS); -if (count($autoloadPaths) === 0) { - throw new \RuntimeException('No autoload paths were specified.'); -} - -$drupalFinder = new DrupalFinder(); -$drupalFinder->locateRoot($autoloadPaths[0]); -$drupalRoot = $drupalFinder->getDrupalRoot(); -$drupalVendorRoot = $drupalFinder->getVendorDir(); - -if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) { - throw new \RuntimeException("Unable to detect Drupal at $drupalRoot"); -} - -/** - * Finds all valid extension directories recursively within a given directory. - * - * @param string $scan_directory - * The directory that should be recursively scanned. - * - * @return array - * An associative array of extension directories found within the scanned - * directory, keyed by extension name. - */ -function drupal_phpunit_find_extension_directories($scan_directory) { - $extensions = []; - $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); - foreach ($dirs as $dir) { - if (strpos($dir->getPathname(), '.info.yml') !== FALSE) { - // Cut off ".info.yml" from the filename for use as the extension name. We - // use getRealPath() so that we can scan extensions represented by - // directory aliases. - $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo() - ->getRealPath(); - } - } - return $extensions; -} - -/** - * Returns directories under which contributed extensions may exist. - * - * @param string $root - * (optional) Path to the root of the Drupal installation. - * - * @return array - * An array of directories under which contributed extensions may exist. - */ -function drupal_phpunit_contrib_extension_directory_roots($root) { - $paths = [ - $root . '/core/modules', - $root . '/core/profiles', - $root . '/modules', - $root . '/profiles', - $root . '/themes', - ]; - $sites_path = $root . '/sites'; - // Note this also checks sites/../modules and sites/../profiles. - foreach (scandir($sites_path) as $site) { - if ($site[0] === '.' || $site === 'simpletest') { - continue; - } - $path = "$sites_path/$site"; - $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL; - $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL; - $paths[] = is_dir("$path/themes") ? realpath("$path/themes") : NULL; - } - return array_filter($paths, 'file_exists'); -} - -/** - * Registers the namespace for each extension directory with the autoloader. - * - * @param array $dirs - * An associative array of extension directories, keyed by extension name. - * - * @return array - * An associative array of extension directories, keyed by their namespace. - */ -function drupal_phpunit_get_extension_namespaces($dirs) { - $suite_names = ['Unit', 'Kernel', 'Functional', 'Build', 'FunctionalJavascript']; - $namespaces = []; - foreach ($dirs as $extension => $dir) { - if (is_dir($dir . '/src')) { - // Register the PSR-4 directory for module-provided classes. - $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src'; - } - $test_dir = $dir . '/tests/src'; - if (is_dir($test_dir)) { - foreach ($suite_names as $suite_name) { - $suite_dir = $test_dir . '/' . $suite_name; - if (is_dir($suite_dir)) { - // Register the PSR-4 directory for PHPUnit-based suites. - $namespaces['Drupal\\Tests\\' . $extension . '\\' . $suite_name . '\\'][] = $suite_dir; - } - } - // Extensions can have a \Drupal\extension\Traits namespace for - // cross-suite trait code. - $trait_dir = $test_dir . '/Traits'; - if (is_dir($trait_dir)) { - $namespaces['Drupal\\Tests\\' . $extension . '\\Traits\\'][] = $trait_dir; - } - } - } - return $namespaces; -} - - -/** - * Populate class loader with additional namespaces for tests. - * - * We run this in a function to avoid setting the class loader to a global - * that can change. This change can cause unpredictable false positives for - * phpunit's global state change watcher. The class loader can be retrieved from - * composer at any time by requiring autoload.php. - */ -function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { - - /** @var \Composer\Autoload\ClassLoader $loader */ - $loader = require $vendorRoot . '/autoload.php'; - - // Start with classes in known locations. - $loader->add('Drupal\\BuildTests', $drupalRoot . '/core/tests'); - $loader->add('Drupal\\Tests', $drupalRoot . '/core/tests'); - $loader->add('Drupal\\TestSite', $drupalRoot . '/core/tests'); - $loader->add('Drupal\\KernelTests', $drupalRoot . '/core/tests'); - $loader->add('Drupal\\FunctionalTests', $drupalRoot . '/core/tests'); - $loader->add('Drupal\\FunctionalJavascriptTests', $drupalRoot . '/core/tests'); - $loader->add('Drupal\\TestTools', $drupalRoot . '/core/tests'); - - if (!isset($GLOBALS['namespaces'])) { - // Scan for arbitrary extension namespaces from core and contrib. - $extension_roots = drupal_phpunit_contrib_extension_directory_roots($drupalRoot); - - $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots); - $dirs = array_reduce($dirs, 'array_merge', []); - $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs); - } - foreach ($GLOBALS['namespaces'] as $prefix => $paths) { - $loader->addPsr4($prefix, $paths); - } - - return $loader; -} - -// Do class loader population. -drupal_phpunit_populate_class_loader($drupalRoot, $drupalVendorRoot); - -// Determines the major version of PHPUnit. -$major = 7; -if (class_exists(Version::class)) { - $major = (int) explode('.', Version::id())[0]; -} -if ($major > 7) { - $major = 7; -} -// @todo This was added in 8.8.x, which means 8.7.x would fail on this but -// people should upgrade to 8.9.x anyways. -require_once $drupalRoot . "/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit{$major}/TestCompatibilityTrait.php"; -class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit{$major}\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); diff --git a/drupal-phpunit-hack.php b/drupal-phpunit-hack.php deleted file mode 100644 index b20ee383..00000000 --- a/drupal-phpunit-hack.php +++ /dev/null @@ -1,39 +0,0 @@ -findFile('PHPUnit\Framework\TestCase'); -if (!$alteredFile) { - return; -} -$phpunit_dir = dirname($alteredFile, 3); -// Mutate TestCase code to make it compatible with Drupal 8 and 9 tests. -$alteredCode = file_get_contents($alteredFile); -$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode); -$alteredCode = str_replace("__DIR__ . '/../Util/", "'$phpunit_dir/src/Util/", $alteredCode); -// Only write when necessary. -$filename = __DIR__ . '/tests/fixtures/MutatedTestCase.php'; - -if (!file_exists($filename) || md5_file($filename) !== md5($alteredCode)) { - file_put_contents($filename, $alteredCode); -} -include $filename; From 8298f58fdaec8bf2c2f539cc5a6697e31ff3e6dc Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 17:28:49 -0500 Subject: [PATCH 57/64] Get funcitonal test working with config file. --- features/behat-rector.php | 31 +++++++++++++++++++++++++++ features/bootstrap/FeatureContext.php | 12 +---------- 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 features/behat-rector.php diff --git a/features/behat-rector.php b/features/behat-rector.php new file mode 100644 index 00000000..3cdfc2b3 --- /dev/null +++ b/features/behat-rector.php @@ -0,0 +1,31 @@ +import(__DIR__ . '/../config/drupal-8/drupal-8-all-deprecations.php'); + + $parameters = $containerConfigurator->parameters(); + + $drupalFinder = new DrupalFinder(); + $drupalFinder->locateRoot(__DIR__); + $drupalRoot = $drupalFinder->getDrupalRoot(); + $parameters->set(Option::AUTOLOAD_PATHS, [ + $drupalRoot . '/core', + $drupalRoot . '/modules', + $drupalRoot . '/profiles', + $drupalRoot . '/themes' + ]); + + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + $parameters->set(Option::IMPORT_DOC_BLOCKS, false); + + $parameters->set('drupal_rector_notices_as_comments', true); +}; diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 511b8a53..ddd91235 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -20,13 +20,6 @@ class FeatureContext implements Context { */ protected $temporaryFolderPath = 'features/tmp'; - /** - * The Drupal Rector path. - * - * @var string - */ - protected $drupalRectorPath = 'drupal-rector/'; - /** * The path to the test file or folder. * @@ -69,13 +62,10 @@ public function iRunDrupalRectorOnTheTest() { * @When I run Drupal Rector on the file/folder :path */ public function iRunDrupalRectorOnThe($path) { - chdir('..'); $output = NULL; $return_value = NULL; - exec("vendor/bin/rector process $this->drupalRectorPath/$path", $output, $return_value); - - chdir($this->drupalRectorPath); + exec("vendor/bin/rector process --config=features/behat-rector.php $path", $output, $return_value); if ($return_value !== 0) { throw new Exception('Rector did not complete successfully.' . PHP_EOL From d8d83a14677878b4f8634c2a3e0b811ca20efa68 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 17:34:15 -0500 Subject: [PATCH 58/64] Remove debug. --- .github/workflows/functional_test__rector_examples.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index e0b08a99..b1a3c149 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -52,8 +52,5 @@ jobs: cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - name: Install local dependencies, including Behat. run: composer install - # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started - - name: Debugging with tmate - uses: mxschmitt/action-tmate@v2 - name: Run Behat tests run: vendor/bin/behat From cb77631cc74506689c4c715f8b4d1cf52137aed0 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 17:37:34 -0500 Subject: [PATCH 59/64] Enable debug. --- .github/workflows/functional_test__rector_examples.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index b1a3c149..e0b08a99 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -52,5 +52,8 @@ jobs: cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - name: Install local dependencies, including Behat. run: composer install + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + - name: Debugging with tmate + uses: mxschmitt/action-tmate@v2 - name: Run Behat tests run: vendor/bin/behat From a1101a5f9d40dfaf12cb7813ac92a0a45b28a08b Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 18:10:43 -0500 Subject: [PATCH 60/64] Have the Github Actions workflow mimic the sandbox. /drupal-rector /web --- .../functional_test__rector_examples.yml | 16 +++++++--------- features/bootstrap/FeatureContext.php | 12 +++++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index e0b08a99..626382f8 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -23,8 +23,9 @@ jobs: # START: SHARED DRUPAL INSTALL SETUP - name: Setup Drupal run: | - COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ~/drupal --no-interaction - cd ~/drupal + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ../drupal --no-interaction + cd .. + mv drupal/* . composer config minimum-stability dev composer config prefer-stable true composer config preferred-install dist @@ -33,27 +34,24 @@ jobs: # We add a local repository `repositories.0` which takes precendence over the packagist repository that is automatically added. - name: Install Drupal Rector run: | - cd ~/drupal + cd .. composer config repositories.drupal-rector "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" composer require palantirnet/drupal-rector:@dev --no-progress - name: Install Drupal Rector Config run: | - cd ~/drupal + cd .. cp vendor/palantirnet/drupal-rector/rector.php . # END: SHARED DRUPAL INSTALL SETUP - name: Install PHPUnit in the Drupal site since it is required for some of the rules run: | - cd ~/drupal + cd .. composer require phpunit/phpunit:~7.5 --no-progress - name: Prepare rector_examples folder in the drupal modules directory run: | - cd ~/drupal + cd .. mkdir -p web/modules/custom cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - name: Install local dependencies, including Behat. run: composer install - # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started - - name: Debugging with tmate - uses: mxschmitt/action-tmate@v2 - name: Run Behat tests run: vendor/bin/behat diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index ddd91235..511b8a53 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -20,6 +20,13 @@ class FeatureContext implements Context { */ protected $temporaryFolderPath = 'features/tmp'; + /** + * The Drupal Rector path. + * + * @var string + */ + protected $drupalRectorPath = 'drupal-rector/'; + /** * The path to the test file or folder. * @@ -62,10 +69,13 @@ public function iRunDrupalRectorOnTheTest() { * @When I run Drupal Rector on the file/folder :path */ public function iRunDrupalRectorOnThe($path) { + chdir('..'); $output = NULL; $return_value = NULL; - exec("vendor/bin/rector process --config=features/behat-rector.php $path", $output, $return_value); + exec("vendor/bin/rector process $this->drupalRectorPath/$path", $output, $return_value); + + chdir($this->drupalRectorPath); if ($return_value !== 0) { throw new Exception('Rector did not complete successfully.' . PHP_EOL From b80475428c11a280676593769eb5ef471f9265e8 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 18:15:01 -0500 Subject: [PATCH 61/64] debug again... --- .github/workflows/functional_test__rector_examples.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index 626382f8..a413e3c4 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -53,5 +53,8 @@ jobs: cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - name: Install local dependencies, including Behat. run: composer install + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + - name: Debugging with tmate + uses: mxschmitt/action-tmate@v2 - name: Run Behat tests run: vendor/bin/behat From 58539fed322ffa3365d1285664eb42b78f20e85d Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 18:28:59 -0500 Subject: [PATCH 62/64] Add back the fix for not finding classes. --- config/drupal-8/drupal-8-all-deprecations.php | 4 + config/drupal-phpunit-bootstrap-file.php | 183 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 config/drupal-phpunit-bootstrap-file.php diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php index 4c8fb42c..ce83191b 100644 --- a/config/drupal-8/drupal-8-all-deprecations.php +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -9,4 +9,8 @@ $containerConfigurator->import(__DIR__ . '/drupal-8.*'); $parameters = $containerConfigurator->parameters(); + + $parameters->set(Option::BOOTSTRAP_FILES, [ + __DIR__ . '/../drupal-phpunit-bootstrap-file.php' + ]); }; diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php new file mode 100644 index 00000000..b2bbc30a --- /dev/null +++ b/config/drupal-phpunit-bootstrap-file.php @@ -0,0 +1,183 @@ +parameterProvider; +if ($parameterProvider === NULL) { + throw new ShouldNotHappenException('We were unable to access the parameter provider from the BootstrapFilesIncluder.'); +} + +$autoloadPaths = $parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS); +if (count($autoloadPaths) === 0) { + throw new \RuntimeException('No autoload paths were specified.'); +} + +$drupalFinder = new DrupalFinder(); +$drupalFinder->locateRoot($autoloadPaths[0]); +$drupalRoot = $drupalFinder->getDrupalRoot(); +$drupalVendorRoot = $drupalFinder->getVendorDir(); + +if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) { + throw new \RuntimeException("Unable to detect Drupal at $drupalRoot"); +} + +/** + * Finds all valid extension directories recursively within a given directory. + * + * @param string $scan_directory + * The directory that should be recursively scanned. + * + * @return array + * An associative array of extension directories found within the scanned + * directory, keyed by extension name. + */ +function drupal_phpunit_find_extension_directories($scan_directory) { + $extensions = []; + $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); + foreach ($dirs as $dir) { + if (strpos($dir->getPathname(), '.info.yml') !== FALSE) { + // Cut off ".info.yml" from the filename for use as the extension name. We + // use getRealPath() so that we can scan extensions represented by + // directory aliases. + $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo() + ->getRealPath(); + } + } + return $extensions; +} + +/** + * Returns directories under which contributed extensions may exist. + * + * @param string $root + * (optional) Path to the root of the Drupal installation. + * + * @return array + * An array of directories under which contributed extensions may exist. + */ +function drupal_phpunit_contrib_extension_directory_roots($root) { + $paths = [ + $root . '/core/modules', + $root . '/core/profiles', + $root . '/modules', + $root . '/profiles', + $root . '/themes', + ]; + $sites_path = $root . '/sites'; + // Note this also checks sites/../modules and sites/../profiles. + foreach (scandir($sites_path) as $site) { + if ($site[0] === '.' || $site === 'simpletest') { + continue; + } + $path = "$sites_path/$site"; + $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL; + $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL; + $paths[] = is_dir("$path/themes") ? realpath("$path/themes") : NULL; + } + return array_filter($paths, 'file_exists'); +} + +/** + * Registers the namespace for each extension directory with the autoloader. + * + * @param array $dirs + * An associative array of extension directories, keyed by extension name. + * + * @return array + * An associative array of extension directories, keyed by their namespace. + */ +function drupal_phpunit_get_extension_namespaces($dirs) { + $suite_names = ['Unit', 'Kernel', 'Functional', 'Build', 'FunctionalJavascript']; + $namespaces = []; + foreach ($dirs as $extension => $dir) { + if (is_dir($dir . '/src')) { + // Register the PSR-4 directory for module-provided classes. + $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src'; + } + $test_dir = $dir . '/tests/src'; + if (is_dir($test_dir)) { + foreach ($suite_names as $suite_name) { + $suite_dir = $test_dir . '/' . $suite_name; + if (is_dir($suite_dir)) { + // Register the PSR-4 directory for PHPUnit-based suites. + $namespaces['Drupal\\Tests\\' . $extension . '\\' . $suite_name . '\\'][] = $suite_dir; + } + } + // Extensions can have a \Drupal\extension\Traits namespace for + // cross-suite trait code. + $trait_dir = $test_dir . '/Traits'; + if (is_dir($trait_dir)) { + $namespaces['Drupal\\Tests\\' . $extension . '\\Traits\\'][] = $trait_dir; + } + } + } + return $namespaces; +} + + +/** + * Populate class loader with additional namespaces for tests. + * + * We run this in a function to avoid setting the class loader to a global + * that can change. This change can cause unpredictable false positives for + * phpunit's global state change watcher. The class loader can be retrieved from + * composer at any time by requiring autoload.php. + */ +function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { + + /** @var \Composer\Autoload\ClassLoader $loader */ + $loader = require $vendorRoot . '/autoload.php'; + + // Start with classes in known locations. + $loader->add('Drupal\\BuildTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\Tests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\TestSite', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\KernelTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\FunctionalTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\FunctionalJavascriptTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\TestTools', $drupalRoot . '/core/tests'); + + if (!isset($GLOBALS['namespaces'])) { + // Scan for arbitrary extension namespaces from core and contrib. + $extension_roots = drupal_phpunit_contrib_extension_directory_roots($drupalRoot); + + $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots); + $dirs = array_reduce($dirs, 'array_merge', []); + $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs); + } + foreach ($GLOBALS['namespaces'] as $prefix => $paths) { + $loader->addPsr4($prefix, $paths); + } + + return $loader; +} + +// Do class loader population. +drupal_phpunit_populate_class_loader($drupalRoot, $drupalVendorRoot); + +// Determines the major version of PHPUnit. +$major = 7; +if (class_exists(Version::class)) { + $major = (int) explode('.', Version::id())[0]; +} +if ($major > 7) { + $major = 7; +} +// @todo This was added in 8.8.x, which means 8.7.x would fail on this but +// people should upgrade to 8.9.x anyways. +require_once $drupalRoot . "/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit{$major}/TestCompatibilityTrait.php"; +class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit{$major}\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); From a4288ea74a2f3cd96e7fbf5ace82364f74080787 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 18:29:58 -0500 Subject: [PATCH 63/64] Remove debug... --- .github/workflows/functional_test__rector_examples.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index a413e3c4..626382f8 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -53,8 +53,5 @@ jobs: cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom - name: Install local dependencies, including Behat. run: composer install - # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started - - name: Debugging with tmate - uses: mxschmitt/action-tmate@v2 - name: Run Behat tests run: vendor/bin/behat From 0e3acf51bcebb2fd448a4f6391696f2f57cdcf12 Mon Sep 17 00:00:00 2001 From: Daniel Montgomery Date: Mon, 3 May 2021 18:33:48 -0500 Subject: [PATCH 64/64] Remove Behat config since it isn't used. --- features/behat-rector.php | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 features/behat-rector.php diff --git a/features/behat-rector.php b/features/behat-rector.php deleted file mode 100644 index 3cdfc2b3..00000000 --- a/features/behat-rector.php +++ /dev/null @@ -1,31 +0,0 @@ -import(__DIR__ . '/../config/drupal-8/drupal-8-all-deprecations.php'); - - $parameters = $containerConfigurator->parameters(); - - $drupalFinder = new DrupalFinder(); - $drupalFinder->locateRoot(__DIR__); - $drupalRoot = $drupalFinder->getDrupalRoot(); - $parameters->set(Option::AUTOLOAD_PATHS, [ - $drupalRoot . '/core', - $drupalRoot . '/modules', - $drupalRoot . '/profiles', - $drupalRoot . '/themes' - ]); - - $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); - $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); - $parameters->set(Option::AUTO_IMPORT_NAMES, true); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - $parameters->set(Option::IMPORT_DOC_BLOCKS, false); - - $parameters->set('drupal_rector_notices_as_comments', true); -};