Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rector 0.10 #134

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
17b36a4
composer: update rector to 0.8
TomasVotruba Sep 12, 2020
9732bf1
switch configs from YML to PHP
TomasVotruba Sep 12, 2020
e1e09b0
drop duplicated info in editorconfig
TomasVotruba Sep 12, 2020
b6ad9c8
Add phpstan and rector dev trunk
mglaman Mar 24, 2021
4964e07
Merge branch 'rector-08' into rector-0.10
mglaman Mar 24, 2021
c043b05
Add back EntityDeleteMultipleRector
mglaman Mar 24, 2021
e02f8cc
Update rule definitions for Rector 0.10
mglaman Mar 24, 2021
541584c
Fix remaining usages of Option::EXCLUDE_PATHS
mglaman Mar 24, 2021
f29c567
PHPStan workflow to catch unused calls.
mglaman Mar 24, 2021
669038d
Add PHPUnit and initial test
mglaman Mar 28, 2021
7c81ed4
Update local packages flow
mglaman Mar 28, 2021
ece4915
Handle ~/drupal in specific workflow
mglaman Mar 28, 2021
d763416
Normalize GitHub flows
mglaman Mar 28, 2021
f72dfaa
Add PHPUnit flow, move deprecation-index tests to PHPUnit
mglaman Mar 29, 2021
dcb66ff
Move away from Behat and to specific commands
mglaman Mar 29, 2021
41e9587
Must add php suffix
mglaman Mar 29, 2021
6a58e12
Run with debug, remove duplicated core discovery
mglaman Mar 29, 2021
c1d9e48
Add missing 8.4 deprecation Rector rules config
mglaman Apr 7, 2021
4f4c56a
Ensure we load the PHPUnit bootstrap for test class autoloading
mglaman Apr 7, 2021
0eb9c38
Update the integration test
mglaman Apr 7, 2021
bfacd7d
Expect dry-run exit code 1
mglaman Apr 7, 2021
3bea584
Remove phpunit bootstrap
mglaman Apr 7, 2021
1d08f2b
Update examples_updated for db_*
mglaman Apr 7, 2021
02c49a5
Fix comments: parentNode is now just parent
mglaman Apr 8, 2021
9df523a
nextNode is just next
mglaman Apr 9, 2021
f03df1b
Fix remaining diff errors
mglaman Apr 9, 2021
ee7c775
rector/rector:0.10.4 stopped returning applied rectors
mglaman Apr 9, 2021
71b077f
Use constants for accessing attribute values
mglaman Apr 15, 2021
bd16f1a
Remove include of "core/tests/bootstrap.php"
mglaman Apr 15, 2021
abd687d
0.10.6 restores ability to check file_diffs for applied rules
mglaman Apr 15, 2021
87ac7f2
Update remaining `yml` documentation
mglaman Apr 15, 2021
31e1c1c
Initial work to fix test traits autoloading
mglaman Apr 15, 2021
5146376
Make PHPUnit autoloading bootstrap file generic for all config
mglaman Apr 15, 2021
b20270b
Use webflo/drupal-finder
mglaman Apr 15, 2021
d33c4b0
Ensure test/fixtures directory
mglaman Apr 15, 2021
7d31554
Update phpstan.neon to remove old config files
mglaman Apr 15, 2021
4f498c8
Fix notice on assert for a prefixed class
mglaman Apr 16, 2021
8de2317
Run a test against webform for catching output errors
mglaman Apr 16, 2021
d66bdc7
Dynamic PhpunitVersionDependentTestCompatibilityTrait version aliasing
mglaman Apr 16, 2021
619f96a
Do not error with Webform if it fails
mglaman Apr 16, 2021
ad43a86
Run on different PHPUnit versions, fix hardcoded trait namespace
mglaman Apr 16, 2021
6590232
Refactor Gitflow Actions.
damontgomery Apr 26, 2021
a1aa889
Removed Behat automated tests.
damontgomery Apr 26, 2021
376c576
Include Symfony YAML since it's required for the PhpUnit tests.
damontgomery Apr 26, 2021
95eff0c
Recursive copy for functional test.
damontgomery Apr 26, 2021
1d9dfe2
Document running PHPUnit
mglaman Apr 28, 2021
e821abd
Add documentation about PHP version
mglaman Apr 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ insert_final_newline = true

[composer.{json,lock}]
indent_size = 4

[*.neon]
indent_size = 4
indent_style = tab
82 changes: 40 additions & 42 deletions .github/workflows/local_package_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,44 @@ jobs:
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 ..
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
- name: Install drupal-rector
run: |
cd ~/drupal
composer require palantirnet/drupal-rector:@dev --no-progress

- name: Copy rector config
run: |
cd ~/drupal
cp vendor/palantirnet/drupal-rector/rector.php .
cat rector.php

- 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 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
mv vendor/palantirnet/drupal-rector/rector_examples web/modules/custom
ls -la web/modules/custom/rector_examples
mglaman marked this conversation as resolved.
Show resolved Hide resolved

# 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 || if (($? == 1)); then true; else false; fi
- 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
85 changes: 64 additions & 21 deletions .github/workflows/local_package_run_rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,86 @@ 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
- uses: shivammathur/setup-php@v2
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

# 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
- 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
- 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 ..
cp vendor/palantirnet/drupal-rector/rector.yml .
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 ..
vendor/bin/rector process web/modules/custom/rector_examples
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.
# @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
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
5 changes: 2 additions & 3 deletions .github/workflows/packagist_package_run_rector.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,7 +36,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
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
17 changes: 17 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@

/features/tmp/*
!/features/tmp/.placeholder

/.phpunit.cache
/tests/fixtures/drupal
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,16 @@ $ 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.
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.yml`
To get started, copy the `rector.php` configuration file provided by this package:

```bash
cp vendor/palantirnet/drupal-rector/rector-config-web-dir.yml rector.yml
cp vendor/palantirnet/drupal-rector/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
```

If your document root directory is something else you will need to manually copy and edit `rector.yml`.

Replace the `web` in these paths with your document root.

```
parameters:
autoload_paths:
- 'web/core'
- 'web/core/modules'
- 'web/modules'
- 'web/profiles'
```

## Suggested workflow

Expand Down Expand Up @@ -140,7 +122,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`

Expand Down
18 changes: 16 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ast"
],
"require": {
"rector/rector-prefixed": "0.7.29"
"rector/rector-prefixed": "~0.10.0",
"webflo/drupal-finder": "^1.2"
},
"license": "MIT",
"authors": [
Expand All @@ -28,10 +29,18 @@
}
],
"autoload": {
"files": [
"drupal-phpunit-hack.php"
],
Comment on lines +32 to +34
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can dig up the live stream where I worked on this for phpstan-drupal. It's not pretty. But I have no other idea how we could possibly mimic Drupal's runtime mutation. It creates a mutated class copy into sites/simpletest and essentially overwrites the default PHPUnit one by getting it autoloaded first.

"psr-4": {
"DrupalRector\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"DrupalRector\\Tests\\": "tests/src"
}
},
"config": {
"optimize-autoloader": true,
"update-with-dependencies": true,
Expand All @@ -45,6 +54,11 @@
"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",
"phpunit/phpunit": "^9.5",
"rector/rector": "~0.10.0"
}
}
16 changes: 16 additions & 0 deletions config/drupal-8/drupal-8-all-deprecations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/drupal-8.*');

$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, []);
damontgomery marked this conversation as resolved.
Show resolved Hide resolved
$parameters->set(Option::BOOTSTRAP_FILES, [
__DIR__ . '/../drupal-phpunit-bootstrap-file.php'
]);
};
16 changes: 0 additions & 16 deletions config/drupal-8/drupal-8-all-deprecations.yml

This file was deleted.

Loading