Skip to content

Issue #3379332 Add some development tools to this module to help make it easier to create merge requests, test changes, and get to work quickly.

During the build step within Lando this config file does the following within the appserver container:

      # Create a new Drupal project and use the module as a non-packagist repository.
      - composer create-project --dev drupal/recommended-project:10.1.x /app
      - composer config extra.enable-patching true
      - composer config extra.composer-exit-on-patch-failure true
      - composer config allow-plugins.cweagans/composer-patches true
      - composer require cweagans/composer-patches
      - composer config minimum-stability dev
      - composer config allow-plugins.phpstan/extension-installer true
      - composer require --dev drupal/core-dev:^10.1 drush/drush phpspec/prophecy-phpunit:* phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules
      - composer config repositories.localdev path /usr/local/config_distro && composer require drupal/config_distro:\*@dev

These commands are used to create and set up a new Drupal project with some specific configurations and dependencies using Composer. Each command is explained below:

composer create-project --dev drupal/recommended-project:10.1.x /app: This command creates a new Drupal project using the drupal/recommended-project template for Drupal version 10.1.x. The project will be installed in the /app directory of the appserver container.

composer config extra.enable-patching true: This command enables the patching feature for Composer. It allows applying patches to packages during the installation process.

composer config extra.composer-exit-on-patch-failure true: This command configures Composer to exit with an error code if patching fails during the installation process. It ensures that any patching issues are immediately detected and the installation process is halted.

composer config allow-plugins.cweagans/composer-patches true: This command allows the usage of the cweagans/composer-patches plugin. This plugin is used for managing patches in Composer-managed projects.

composer require cweagans/composer-patches: This command adds the cweagans/composer-patches package to the project. This package provides the functionality to manage patches for Composer packages.

composer config minimum-stability dev: This command sets the minimum stability level for Composer packages to "dev." By doing this, Composer allows the installation of packages that are in development, including alpha and beta releases.

composer config allow-plugins.phpstan/extension-installer true: This command allows the usage of the phpstan/extension-installer plugin. This plugin is used to automate the installation of PHPStan extensions.

composer require --dev drupal/core-dev:^10.1 drush/drush phpspec/prophecy-phpunit:* phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules: This command adds several packages as development dependencies to the project. The packages are:

drupal/core-dev:^10.1: Development dependencies for Drupal core version 10.1.x. drush/drush: The Drush command-line tool for Drupal. phpspec/prophecy-phpunit:*: The Prophecy-PHPUnit library. phpstan/extension-installer: The PHPStan extension installer. mglaman/phpstan-drupal: A PHPStan extension for Drupal. phpstan/phpstan-deprecation-rules: A PHPStan extension for deprecation rules. composer config repositories.localdev path /usr/local/config_distro && composer require drupal/config_distro:@Dev: This command configures a custom repository named localdev pointing to the /usr/local/config_distro directory. It then requires the drupal/config_distro package from that custom repository at the @Dev development version.

During the install step, this lando config file: Within the appserver again, install drupal, creating an admin user with the password admin and enables the config_distro module.

  install:
    service: appserver
    cmd:
      - /app/vendor/bin/drush --root=/app/web site:install --account-mail=noreply@example.com --account-name=admin --account-pass=admin --db-url=mysql://drupal10:drupal10@database:3306/drupal10 -y --verbose
      - /app/vendor/bin/drush en -y config_distro

The secret sauce here, is the bind mounting of the cloned repo into the drupal codebase allowing us to keep our local filesystems clean.

How to test

Once this lando.yml file is included in the config_distro project setup is easy if the user has lando installed. Have lando installed first https://docs.lando.dev/getting-started/installation.html

Clone repo fork and check out issue branch From within the cloned repo folder simply run

lando start && lando install

After that, running phpunit tests can be as simple as FYI It is not necessary to run lando install before running any of the tools that do not require a Drupal installation.

lando phpunit

Beautifying and fixing your code is as simple as

lando phpcbf

Using codesniffer

lando phpcs

Using PHPstan

lando phpstan

Using drush to log in to drupal.

lando drush uli -l https://config_distro.lndo.site:4433

Using composer

lando composer ...

Use git normally from the cloned repo

git status
git add <filename>
git commit -m "Commit message"
git push 

Merge request reports