Skip to content

Commit

Permalink
feat!: modernize the project for composer 2, PHP 8, Drupal 10 among o…
Browse files Browse the repository at this point in the history
…thers (#7)

* chore!: update some dependencies for composer-plugin-api compatibility.

* chore: update gitignore to ignore .idea directory.

* fix: update composer plugin for new API changes.

* fix: update use of OperationInterface API.

* fix!: update gumphp template.

* fix: remove hooks_preset grumphp config.

* chore!: bump phpunit dependency to allow for php 8 install.

* chore: remove sensiolabs/security-checker

* chore: update phpro/grumphp and dependencies

* chore!: update version of Drupal core for testing

* chore!: update version of Drupal core for testing

* fix: replace abandoned php-parallel-lint

* fix: update phpunit ref to 9.5

* chore: swap grumphp for grumphp-shim

* chore!: leave old dependencies in the dust

* feat: add security-checker

* feat: additional checks for commit messages

* feat: add securitychecker_enlightn to config

* fix: ascii art for grumphp phar

* fix: coding standards in the plugin class

* fix: update grumphp yml template

* fix: update phpunit config for Drupal 10

* fix: bump php version in travis template
  • Loading branch information
m4olivei authored Apr 26, 2023
1 parent 31ac982 commit a8e4a4c
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ composer.phar
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

# User-specific stuff:
.idea/
47 changes: 27 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
{
"name": "e0ipso/travis-drupal-module",
"type": "composer-plugin",
"description": "Library to help Travis CI setup without headaches for Drupal modules.",
"license": "GPL-2.0",
"type": "composer-plugin",
"keywords": [
"Drupal",
"Travis"
],
"homepage": "https://github.com/e0ipso/travis-drupal-module",
"license": "GPL-2.0",
"authors": [
{
"name": "Mateu Aguiló Bosch",
"email": "mateu@mateuaguilo.com"
}
],
"homepage": "https://github.com/e0ipso/travis-drupal-module",
"support": {
"issues": "https://github.com/e0ipso/travis-drupal-module/issues",
"source": "https://github.com/e0ipso/travis-drupal-module"
},
"require": {
"php": ">=7.3",
"composer-plugin-api": "^1.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"php": ">=8.1",
"composer-plugin-api": "^2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.2",
"jakub-onderka/php-parallel-lint": "^1.0",
"localheinz/composer-normalize": "^1.3",
"enlightn/security-checker": "^1.10",
"localheinz/composer-normalize": "^2.4",
"nikic/php-parser": "^4.2",
"php-parallel-lint/php-parallel-lint": "^1.0",
"phpmd/phpmd": "^2",
"phpmetrics/phpmetrics": "^2.4",
"phpro/grumphp": "^0.15.2",
"phpunit/phpunit": "^6.5",
"sensiolabs/security-checker": "^6.0",
"phpro/grumphp-shim": "^1.15",
"phpunit/phpunit": "^8.5.14 || ^9",
"squizlabs/php_codesniffer": "^3.4",
"symfony/filesystem": "~2.8 || ~3.0 || ~4.0"
"symfony/filesystem": "^6.2"
},
"require-dev": {},
"extra": {
"class": [
"TravisDrupalModule\\Composer\\TravisDrupalModulePlugin"
]
},
"autoload": {
"psr-4": {
"TravisDrupalModule\\": "src"
}
},
"support": {
"issues": "https://github.com/e0ipso/travis-drupal-module/issues",
"source": "https://github.com/e0ipso/travis-drupal-module"
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"localheinz/composer-normalize": true,
"phpro/grumphp-shim": true
}
},
"extra": {
"class": [
"TravisDrupalModule\\Composer\\TravisDrupalModulePlugin"
]
}
}
17 changes: 8 additions & 9 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
parameters:
git_dir: .
bin_dir: vendor/bin
grumphp:
additional_info: "\nVisit https://github.com/e0ipso/travis-drupal-module#readme for documentation!\n"
hooks_preset: local
stop_on_failure: false
ignore_unstaged_changes: false
hide_circumvention_tip: false
process_async_limit: 10
process_async_wait: 1000
process_timeout: 60
tasks:
yamllint: ~
Expand All @@ -20,6 +15,8 @@ parameters:
- types: ['build', 'ci', 'chore', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test']
- scopes: ['schema', 'form', 'drupal', 'api']
max_subject_width: 50
enforce_no_subject_punctuations: true
enforce_no_subject_trailing_period: true
git_branch_name:
whitelist:
- '/((build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test)\/[a-z0-9-]+|8.x-[0-9]+.x|master)/'
Expand All @@ -38,8 +35,10 @@ parameters:
blacklist: [var_dump]
metadata:
priority: 100000
securitychecker: ~
securitychecker_enlightn:
lockfile: ./composer.lock
run_always: false
phplint: ~
ascii:
failed: vendor/phpro/grumphp/resources/ascii/failed.txt
succeeded: vendor/phpro/grumphp/resources/ascii/succeeded.txt
failed: failed.txt
succeeded: succeeded.txt
38 changes: 34 additions & 4 deletions src/Composer/TravisDrupalModulePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,44 @@ final class TravisDrupalModulePlugin implements
* Apply plugin modifications to Composer
*
* @param Composer $composer The composer API.
* @param IOInterface $theIo IO interface to log to the terminal.
* @param IOInterface $io IO interface to log to the terminal.
*
* @return void
*/
public function activate(Composer $composer, IOInterface $theIo)
public function activate(Composer $composer, IOInterface $io)
{
$this->_composer = $composer;
$this->_io = $theIo;
$this->_io = $io;
}

/**
* Remove any hooks from Composer.
*
* This will be called when a plugin is deactivated before being
* uninstalled, but also before it gets upgraded to a new version so the old
* one can be deactivated and the new one activated.
*
* @param Composer $composer The composer API.
* @param IOInterface $io IO interface to log to the terminal.
*
* @return void
*/
public function deactivate(Composer $composer, IOInterface $io)
{
}

/**
* Prepare the plugin to be uninstalled.
*
* This will be called after deactivate.
*
* @param Composer $composer The composer API.
* @param IOInterface $io IO interface to log to the terminal.
*
* @return void
*/
public function uninstall(Composer $composer, IOInterface $io)
{
}

/**
Expand Down Expand Up @@ -113,7 +143,7 @@ public static function getSubscribedEvents(): array
public function postChangeInstall(PackageEvent $event)
{
$operation = $event->getOperation();
$package = $operation->getJobType() === 'update'
$package = $operation->getOperationType() === 'update'
? $operation->getTargetPackage()
: $operation->getPackage();

Expand Down
2 changes: 1 addition & 1 deletion templates/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dist: xenial
language: php
php: 7.3
php: 8.1
cache:
directories:
- "$HOME/.composer/cache/files"
Expand Down
4 changes: 2 additions & 2 deletions templates/.travis/scripts/execute-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ NO_C='\033[0m'
# Link the current module using composer. Otherwise the autoload will not have the necessary classes
# for the Unit tests.
cd ${DOCROOT}/.. || exit 2
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} ${COMPOSER} require \"phpunit/phpunit:^6.5\" --no-interaction --no-progress --no-suggest\n\n"
${COMPOSER} require "phpunit/phpunit:^6.5" --no-interaction --no-progress --no-suggest
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} ${COMPOSER} require \"phpunit/phpunit:^9.5\" --no-interaction --no-progress --no-suggest\n\n"
${COMPOSER} require "phpunit/phpunit:^9.5" --no-interaction --no-progress --no-suggest

# Execute the static code analysis tasks.
cd ${TRAVIS_BUILD_DIR} || exit 2
Expand Down
4 changes: 2 additions & 2 deletions templates/.travis/scripts/install-drupal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ ${COMPOSER} self-update
echo "-----------------------------------------------"
echo " Downloading Drupal using composer "
echo "-----------------------------------------------"
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} ${COMPOSER} create-project drupal-composer/drupal-project:8.x-dev ${DEST_DIR} --stability dev --no-interaction --no-install\n\n"
${COMPOSER} create-project drupal-composer/drupal-project:8.x-dev ${DEST_DIR} --stability dev --no-interaction --no-install
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} ${COMPOSER} create-project drupal-composer/drupal-project:10.x-dev ${DEST_DIR} --stability dev --no-interaction --no-install\n\n"
${COMPOSER} create-project drupal-composer/drupal-project:10.x-dev ${DEST_DIR} --stability dev --no-interaction --no-install

if [ $? -ne 0 ]; then
echo -e "${FG_C}${EBG_C} ERROR ${NO_C} There was a problem setting up Drupal using composer."
Expand Down
17 changes: 8 additions & 9 deletions templates/grumphp.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
parameters:
git_dir: .
bin_dir: vendor/bin
grumphp:
additional_info: "\nVisit https://github.com/e0ipso/travis-drupal-module#readme for documentation!\n"
hooks_preset: local
stop_on_failure: false
ignore_unstaged_changes: false
hide_circumvention_tip: false
process_async_limit: 10
process_async_wait: 1000
process_timeout: 60
tasks:
yamllint: ~
Expand All @@ -20,6 +15,8 @@ parameters:
- types: ['build', 'ci', 'chore', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test']
- scopes: ['schema', 'form', 'drupal', 'api']
max_subject_width: 50
enforce_no_subject_punctuations: true
enforce_no_subject_trailing_period: true
git_branch_name:
whitelist:
- '/((build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test)\/[a-z0-9-]+|8.x-[0-9]+.x|master)/'
Expand Down Expand Up @@ -59,8 +56,10 @@ parameters:
blacklist: [var_dump]
metadata:
priority: 100000
securitychecker: ~
securitychecker_enlightn:
lockfile: ./composer.lock
run_always: false
phplint: ~
ascii:
failed: vendor/phpro/grumphp/resources/ascii/failed.txt
succeeded: vendor/phpro/grumphp/resources/ascii/succeeded.txt
failed: failed.txt
succeeded: succeeded.txt
78 changes: 57 additions & 21 deletions templates/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,59 @@
https://www.drupal.org/node/2116263 for details.
-->
<!-- There is a build step in the CI that will replace 'DRUPAL_ROOT' with the actual directory. -->
<phpunit bootstrap="{DRUPAL_ROOT}/core/tests/bootstrap.php" colors="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="{DRUPAL_ROOT}/core/tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true">
<!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
result printer that links to the html output results for functional tests.
Unfortunately, this breaks the output of PHPStorm's PHPUnit runner. However, if
using the command line you can add
- -printer="\Drupal\Tests\Listeners\HtmlOutputPrinter" to use it (note there
should be no spaces between the hyphens).
-->
beStrictAboutChangesToGlobalState="true"
failOnWarning="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
cacheResult="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env name="SIMPLETEST_BASE_URL" value=""/>
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
<env name="SIMPLETEST_DB" value=""/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value="{DRUPAL_ROOT}/sites/simpletest/browser_output"/>
<!-- To disable deprecation testing completely set SYMFONY_DEPRECATIONS_HELPER value: 'disabled' -->
<!-- By default, browser tests will output links that use the base URL set
in SIMPLETEST_BASE_URL. However, if your SIMPLETEST_BASE_URL is an internal
path (such as may be the case in a virtual or Docker-based environment),
you can set the base URL used in the browser test output links to something
reachable from your host machine here. This will allow you to follow them
directly and view the output. -->
<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>

<!-- Deprecation testing is managed through Symfony's PHPUnit Bridge.
The environment variable SYMFONY_DEPRECATIONS_HELPER is used to configure
the behaviour of the deprecation tests.
See https://symfony.com/doc/current/components/phpunit_bridge.html#configuration
Drupal core's testing framework is setting this variable to its defaults.
Projects with their own requirements need to manage this variable
explicitly.
-->
<!-- To disable deprecation testing completely uncomment the next line. -->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<!-- Deprecation errors can be selectively ignored by specifying a file of
regular expression patterns for exclusion.
See https://symfony.com/doc/current/components/phpunit_bridge.html#ignoring-deprecations
Uncomment the line below to specify a custom deprecations ignore file.
NOTE: it may be required to specify the full path to the file to run tests
correctly.
-->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=.deprecation-ignore.txt"/> -->

<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
<env name="MINK_DRIVER_CLASS" value=''/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=''/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=''/>
</php>
<testsuites>
<testsuite name="unit">
Expand All @@ -40,6 +73,9 @@
<testsuite name="functional-javascript">
<file>{DRUPAL_ROOT}/core/tests/TestSuites/FunctionalJavascriptTestSuite.php</file>
</testsuite>
<testsuite name="build">
<file>{DRUPAL_ROOT}/core/tests/TestSuites/BuildTestSuite.php</file>
</testsuite>
</testsuites>
<listeners>
<listener class="\Drupal\Tests\Listeners\DrupalListener">
Expand All @@ -48,15 +84,15 @@
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<filter>
<whitelist>
<!-- Settings for coverage reports. -->
<coverage>
<include>
<directory>./src</directory>
<exclude>
<!-- By definition test classes have no tests. -->
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<!-- By definition test classes have no tests. -->
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
</phpunit>

0 comments on commit a8e4a4c

Please sign in to comment.