diff --git a/.lando.yml b/.lando.yml new file mode 100644 index 0000000..74402e1 --- /dev/null +++ b/.lando.yml @@ -0,0 +1,70 @@ +name: drupal-core-development-project +recipe: drupal11 +config: + composer_version: 2 + webroot: web + # To use XDebug, set the following to `true`, then run `lando rebuild` + # In VS Code, install the extension https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug + # A .vscode/launch.json file needs to be present, along with a php.ini file. + # See https://docs.lando.dev/guides/lando-with-vscode.html + # and https://gist.github.com/MatthieuScarset/0c3860def9ff1f0b84e32f618c740655 + xdebug: false +services: + pma: + type: phpmyadmin + hosts: + - database + chrome: + type: compose + services: + image: drupalci/webdriver-chromedriver:production + command: chromedriver --log-path=/tmp/chromedriver.log --no-sandbox --headless --verbose --whitelisted-ips= --allowed-origins=* + appserver: + scanner: false + build: + - mkdir -p $LANDO_WEBROOT/sites/simpletest/browser_output + - cp web/sites/default/default.settings.php web/sites/default/settings.php + - echo '\r\n$databases["default"]["default"] = [ + \r\n "database" => "drupal11", + \r\n "username" => "drupal11", + \r\n "password" => "drupal11", + \r\n "prefix" => "", + \r\n "host" => "database", + \r\n "port" => "3306", + \r\n "isolation_level" => "READ COMMITTED", + \r\n "driver" => "mysql", + \r\n "namespace" => "Drupal\\mysql\\Driver\\Database\\mysql", + \r\n "autoload" => "core/modules/mysql/src/Driver/Database/mysql/", + \r\n];' >> web/sites/default/settings.php + - echo '\r\n$settings["hash_salt"] = "1234567890";' >> web/sites/default/settings.php + overrides: + # Changes only take effect after `lando rebuild` + environment: + # See https://agile.coop/blog/drupal-phpunit-tests-lando/ + # Based on https://github.com/lando/lando/pull/1092/files + # See also https://github.com/lando/lando/issues/360 + SYMFONY_DEPRECATIONS_HELPER: 'disabled' + SIMPLETEST_DB: 'mysql://drupal11:drupal11@database/drupal11' + BROWSERTEST_OUTPUT_BASE_URL: 'http://drupal-core-development-project.lndo.site' + # Note: SIMPLETEST_BASE_URL must currently be defined in the phpunit.xml file + # --disable-dev-shm-usage is needed to allow iframed content, such + # as Layout Builder iFrame Modals + # --no-sandbox is needed to run. If absent, the message will be + # 'The test wasn't able to connect to your webdriver instance.' + # goog:chromeOptions is new as of Drupal 10.3 + # w3c:false is needed per #3240792 + MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","goog:chromeOptions":{"w3c":false, "args":["--disable-gpu","--headless", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://chrome:9515"]' +tooling: + composer: + service: appserver + description: Run composer commands + cmd: + - php -d memory_limit=-1 /usr/local/bin/composer + test: + service: appserver + description: Run all PHPUnit tests + cmd: + - sh .lando/test.sh + drush: + service: appserver + cmd: drush --root=/app --uri=https://drupal-core-development-project.lndo.site diff --git a/.lando/phpunit.xml b/.lando/phpunit.xml new file mode 100644 index 0000000..22de0b5 --- /dev/null +++ b/.lando/phpunit.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + ./tests/TestSuites/UnitTestSuite.php + + + ./tests/TestSuites/KernelTestSuite.php + + + ./tests/TestSuites/FunctionalTestSuite.php + + + ./tests/TestSuites/FunctionalJavascriptTestSuite.php + + + ./tests/TestSuites/BuildTestSuite.php + + + + + ./includes + ./lib + ./modules + ../modules + ../sites + + + ./modules/*/src/Tests + ./modules/*/tests + ../modules/*/src/Tests + ../modules/*/tests + ../modules/*/*/src/Tests + ../modules/*/*/tests + ./lib/** + ./modules/** + ../modules/** + + + \ No newline at end of file diff --git a/.lando/test.sh b/.lando/test.sh new file mode 100644 index 0000000..1fc6ef4 --- /dev/null +++ b/.lando/test.sh @@ -0,0 +1,11 @@ +# We need to add drupal/core-dev for PHPUnit +# We do this in a check here so as not to run `composer require` +# every time we want to run tests. +if ! grep -q "drupal/core-dev" composer.json; then + echo "Adding core tooling. This may take a moment..."; + composer require "drupal/core-dev" +fi +mkdir -p /app/web/sites/simpletest/browser_output +chmod 777 /app/web/sites/simpletest/browser_output +# Now we actually run the command... +/app/vendor/bin/phpunit -c /app/.lando/phpunit.xml --stop-on-failure --stop-on-error --display-deprecations --testdox $1 diff --git a/README.md b/README.md index 69d22fa..29504bc 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,25 @@ following changes to the installation instructions for that addon: To run PHPUnit tests, you will need to tweak the DDEV phpunit command until https://github.com/justafish/ddev-drupal-core-dev/pull/37 is fixed. +## Usage with Lando +This repository includes tooling for use with [Lando](https://lando.dev/): + +``` +## Spin up the containers +lando start + +## Use drush commands like site:install and user:login +lando drush si -y +lando drush uli + +## Add contrib modules +lando composer require drupal/linkit + +## Run PHPUnit tests (including FunctionalJavascript!) +## lando test +lando test web/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php +``` + ## Installing other packages You can install any Composer package as you would with a normal project. This diff --git a/composer.json b/composer.json index 13fcd29..c988763 100644 --- a/composer.json +++ b/composer.json @@ -42,11 +42,12 @@ ], "require": { "composer/installers": "^1.9 | ^2", - "drupal/core-composer-scaffold": "*", - "drupal/drupal": "*", "drupal/core": "*", + "drupal/core-composer-scaffold": "*", "drupal/core-dev": "*", "drupal/core-recommended": "*", + "drupal/drupal": "*", + "drupal/module_builder": "^4.1", "drush/drush": "^13", "phpspec/prophecy-phpunit": "*", "symfony/var-dumper": "*" @@ -57,12 +58,14 @@ "sort-packages": true, "allow-plugins": { "composer/installers": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "drupal/core-composer-scaffold": true, "drupal/core-project-message": true, + "drupal/core-recipe-unpack": true, "drupal/core-vendor-hardening": true, - "drupal/core-composer-scaffold": true, "php-http/discovery": true, "phpstan/extension-installer": true, - "dealerdirect/phpcodesniffer-composer-installer": true + "tbachert/spi": true } }, "scripts": { @@ -119,5 +122,8 @@ "type:drupal-custom-theme" ] } + }, + "require-dev": { + "palantirnet/drupal-rector": "^0.21.0" } }