Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHPUnit testing setup for PHP 7.3. #121

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# Ignore Drupal's file directory
/web/sites/*/files/

# Ignore SimpleTest multi-site environment.
# Ignore testing directories.
/web/sites/simpletest
/web/tmp

# Ignore files generated by PhpStorm
/.idea/
Expand Down
23 changes: 13 additions & 10 deletions .lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ tooling:
npm:
description: Runs npm commands
service: node
phpunit:
service: appserver
cmd: "php /app/vendor/bin/phpunit -c /app/phpunit.xml"
xdebug-on:
service: appserver
description: Enables xdebug for nginx
Expand All @@ -41,19 +44,19 @@ services:
appserver:
build:
- composer install
run_as_root:
- /app/.lando/phpunit.sh
overrides:
environment:
HASH_SALT: notsosecurehash
# chrome:
# type: compose
# services:
# image: selenium/standalone-chrome
# user: root
# ports:
# - "4444:4444"
# volumes:
# - /dev/shm:/dev/shm
# command: /opt/bin/entry_point.sh
SIMPLETEST_BASE_URL: "http://appserver_nginx"
SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite"
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'
chrome:
type: compose
services:
image: drupalci/webdriver-chromedriver:production
command: chromedriver --log-path=/tmp/chromedriver.log --verbose --whitelisted-ips=
# elasticsearch:
# type: compose
# meUser: elasticsearch
Expand Down
15 changes: 15 additions & 0 deletions .lando/phpunit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -exu

# Configure PHPUnit tests for the Lando environment.
# @see: https://agile.coop/blog/drupal-phpunit-tests-lando/

cp -n web/core/phpunit.xml.dist phpunit.xml
sed -i 's|tests\/bootstrap\.php|/app/web/core/tests/bootstrap.php|g' phpunit.xml

# Update SQLIte version for PHPUnit.
# @see: https://www.drupal.org/project/drupal/issues/3107155#comment-13523654.
# @see: https://www.drupal.org/node/3119118
echo "deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse" >> /etc/apt/sources.list
apt-get update
apt-get -y install sqlite3/focal --allow-unauthenticated
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ This project template is an opinionated fork of the popular [Drupal-composer tem
## Getting started

- Click "[Use this template](https://github.com/wunderio/drupal-project/generate)" to generate a new project
- Select correct owner
- Name the project as `client-COUNTRYCODE-CLIENT-PROJECT`
- Make the repository private (unless the project is public)
- Select correct owner
- Name the project as `client-COUNTRYCODE-CLIENT-PROJECT`
- Make the repository private (unless the project is public)
- Clone project and modify project details
- `composer.json` name
- `silta/silta.yml`
- See [values](https://github.com/wunderio/charts/blob/master/drupal/values.yaml) options to override.
- `composer.json` name
- `silta/silta.yml`
- See [values](https://github.com/wunderio/charts/blob/master/drupal/values.yaml) options to override.
- Log in to CircleCI using your Github account and add the new project using existing config.

For additional instructions, please see the [Silta documentation](https://github.com/wunderio/silta).
Expand Down Expand Up @@ -44,3 +44,15 @@ For additional instructions, please see the [Silta documentation](https://github

- [Updating Drupal core](https://www.drupal.org/docs/8/update/update-core-via-composer).
- [Altering scaffold files](https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold#toc_4) (`robots.txt`, `.htaccess` etc.).

### Testing

The [PHPUnit](https://phpunit.de/) test framework is predefined in this project. Use `lando phpunit` to run PHPUnit commands. Change `phpunit.xml` as needed and commit it to the GIT. See more at [web/core/tests/README.md](web/core/tests/README.md).

#### Core testing examples

Following examples are taken from <https://agile.coop/blog/drupal-phpunit-tests-lando/>:

- Functional (browser) test: `lando phpunit web/core/modules/color/tests/src/Functional/ColorConfigSchemaTest.php`
- JavaScript test: `lando phpunit web/core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php`
- Kernel test: `lando phpunit web/core/modules/help/tests/src/Kernel/HelpEmptyPageTest.php`
15 changes: 0 additions & 15 deletions phpunit.xml.dist

This file was deleted.