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

Created on 4 August 2023, over 1 year ago
Updated 6 March 2024, 10 months ago

Problem/Motivation

As a developer contributing to Drupal modules and working on multiple merge requests or issues, setting up a development environment for each change can be time-consuming. This becomes even more challenging when breaking down each small change into its own separate issue.

While there are various methods in the Drupal community to add development tools to modules, one preferred approach is using Lando with Drupal installed within containers. This setup allows for easy isolation and reproducibility of development environments. By bind mounting the project from the local filesystem into the container, the developer can interact with the project's files seamlessly, without cluttering the local filesystem with unnecessary files.

This issue aims to provide step-by-step instructions on how to set up a development environment using Lando and Drupal within containers. Following these steps will enable developers to efficiently work on individual issues and merge requests while maintaining a clean and isolated development environment. The result is a streamlined development workflow that saves time and enhances productivity.

We should include common development tools like:

PHPUnit: A PHP testing framework used for writing and executing unit tests. Unit tests verify the correctness of individual components and prevent bugs in the codebase. PHPUnit provides various testing functionalities and assertion methods to create comprehensive test suites.

PHPStan: A static analysis tool for PHP that identifies errors, type mismatches, and other issues without executing the code. It uses PHPDoc annotations and type inference to provide accurate type information, helping developers catch bugs early and improve code quality.

PHPCS (PHP CodeSniffer): This tool enforces coding standards by checking PHP code against predefined rules (e.g., PSR-1, PSR-2, Drupal coding standards). It reports violations, ensuring code consistency and readability, and can be integrated into the development workflow.

PHPCBF (PHP Code Beautifier and Fixer): Part of PHP CodeSniffer, PHPCBF automatically fixes coding standard violations identified by PHPCS. It reformats code to adhere to specified standards, saving developers time and effort in manual fixes and maintaining a consistent code style.

In summary, these tools are essential for modern PHP development, as they ensure code quality, catch errors early, enforce coding standards, and streamline the development process.

Proposed resolution

I recommend a .lando.yml file similar to the following one

name: config_distro
recipe: drupal10
config:
  php: '8.1'
  via: apache:2.4
  webroot: web
  database: mariadb:10.4
  xdebug: false
services:
  database:
    type: compose
    services:
      image: mariadb:10.4
      command: docker-entrypoint.sh mariadbd
      restart: always
      ports:
        - '3306'
      environment:
        MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 'true'
        MARIADB_DATABASE: drupal10
        MYSQL_DATABASE: drupal10
        MARIADB_USER: drupal10
        MARIADB_PASSWORD: drupal10
  appserver:
    overrides:
      environment:
        SIMPLETEST_DB: 'mysql://drupal10:drupal10@database/drupal10'
        SIMPLETEST_BASE_URL: 'http://appserver'
      volumes:
        # Don't share our host working directory as /app. We want /app empty for composer.
        - /app
        # Instead share our host working directory as a standalone package.
        - .:/usr/local/config_distro
    build:
      # 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
tooling:
  # Provide a command to install Drupal.
  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
  # Provide Drush tooling to automatically know the Drupal root.
  drush:
    service: appserver
    cmd: /app/vendor/bin/drush --root=/app/web
  phpcs:
    service: appserver
    cmd: /app/vendor/bin/phpcs -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/config_distro
  # Provide PHPCBF tooling to fix coding standards.
  phpcbf:
    service: appserver
    cmd: /app/vendor/bin/phpcbf -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/config_distro
  # Provide phpstan tooling to check for code quality and deprecated code.
  phpstan:
    service: appserver
    cmd: /app/vendor/bin/phpstan analyse --configuration web/modules/contrib/config_distro/phpstan.neon web/modules/contrib/config_distro
  # Provide phpunit tooling to run unit tests.
  phpunit:
    service: appserver
    cmd: /app/vendor/bin/phpunit --configuration /app/web/core/phpunit.xml.dist --bootstrap /app/web/core/tests/bootstrap.php /app/web/modules/contrib/config_distro
Feature request
Status

Needs review

Version

2.0

Component

Miscellaneous

Created by

🇺🇸United States trackleft2 Tucson, AZ 🇺🇸

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024