Skip to content

Commit

Permalink
feat: initial new test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrala committed Oct 20, 2024
1 parent 5fdfdbb commit 79771ef
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/functional_test__single_rectors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

name: functional_test_single

# This test will run on every pull request, and on every commit on any branch
on:
push:
branches:
- main
pull_request:
schedule:
# Run tests every week (to check for rector changes)
- cron: '0 0 * * 0'

jobs:
run_functional_test_single:
name: Functional Test | single rectors"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
coverage: none
tools: composer:v2
extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, gd
- name: Setup Drupal
uses: bluehorndigital/[email protected]
with:
version: '^11.0'
path: ~/drupal
- name: Install Drupal Rector
run: |
cd ~/drupal
composer require palantirnet/drupal-rector:@dev --no-progress
- name: Prepare rector_examples folder in the drupal modules directory
run: |
cd ~/drupal
mkdir -p web/modules/custom
cp -R vendor/palantirnet/drupal-rector/tests/functional/* web/modules/custom
# dry-run is expected to return exit code 2 if there are changes, which we are expecting to happen, here.
# an error code of 1 represents other errors.
# @see \Rector\Core\Console\ExitCode::CHANGED_CODE
- name: Run rector against Drupal (dry-run)
run: |
cd ~/drupal
for d in web/modules/custom/*; do
if [ -d "$d" ]; then
cp ${d}/rector.php .
vendor/bin/rector process $d/fixture/module --dry-run --debug || if (($? == 2)); then true; else exit 1; fi
fi
done
- name: Run rector against Drupal
run: |
cd ~/drupal
for d in web/modules/custom/*; do
if [ -d "$d" ]; then
cp ${d}/rector.php .
vendor/bin/rector process $d/fixture/module --debug
fi
done
# 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: |
cd ~/drupal
for d in web/modules/custom/*; do
if [ -d "$d" ]; then
diff -rubB "$d/fixture/module" "$d/fixture/module_updated"
fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

function node_user_cancel($edit, UserInterface $account, $method) {
$red = 'red';
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

function node_user_cancel($edit, UserInterface $account, $method) {
$red = 'red';

// should have been updated
}

?>
28 changes: 28 additions & 0 deletions tests/functional/HookConverRector/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use DrupalFinder\DrupalFinder;
use DrupalRector\Set\Drupal10SetList;
use DrupalRector\Set\Drupal8SetList;
use DrupalRector\Set\Drupal9SetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(\DrupalRector\Rector\Convert\HookConvertRector::class);

$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(__DIR__);
$drupalRoot = $drupalFinder->getDrupalRoot();
$rectorConfig->autoloadPaths([
$drupalRoot . '/core',
$drupalRoot . '/modules',
$drupalRoot . '/profiles',
$drupalRoot . '/themes'
]);

$rectorConfig->skip(['*/upgrade_status/tests/modules/*']);
$rectorConfig->fileExtensions(['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']);
$rectorConfig->importNames(true, false);
$rectorConfig->importShortClasses(false);
};

0 comments on commit 79771ef

Please sign in to comment.