diff --git a/composer.json b/composer.json index 580feedb06c6bc7f34ec69180fde1c902933d765..eb2d0c1a58d117162f1b7a6934f0e6195079b230 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,15 @@ }, "scripts": { "phpcbf": "scripts/phpcbf.sh", - "phpcs": "scripts/phpcs.sh" + "phpcs": "scripts/phpcs.sh", + "test": [ + "Composer\\Config::disableProcessTimeout", + "scripts/phpunit.sh" + ] }, "scripts-descriptions": { "phpcbf": "Automatically fixes standards violations where possible.", - "phpcs": "Checks code for standards compliance." + "phpcs": "Checks code for standards compliance.", + "test": "Runs PHPUnit tests." } } diff --git a/scripts/phpcbf.sh b/scripts/phpcbf.sh index fd81e057ac47c6f3c0d4d2295ff8d3c5b3cb890e..0575ea6aefeee23c0e70b2450de88b6edff09e88 100755 --- a/scripts/phpcbf.sh +++ b/scripts/phpcbf.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # NAME -# phpcbf.sh - Automatically fixe standards violations where possible. +# phpcbf.sh - Automatically fixes standards violations where possible. # # SYNOPSIS # bash phpcbf.sh @@ -15,7 +15,7 @@ cd "$(dirname "$0")" || exit 0; -## Find PHPCBF in Drupal core. Check up to three directories up. +# Find PHPCBF in Drupal core. Check up to three directories up. DIR=$(pwd) for i in {0..3}; do DIR=$(dirname "$DIR") diff --git a/scripts/phpcs.sh b/scripts/phpcs.sh index 6d3219ae6d080d21a7d219c0111c93510de86db9..8ffb58ffec798d91043df60006aabfb95bc68f8e 100755 --- a/scripts/phpcs.sh +++ b/scripts/phpcs.sh @@ -15,7 +15,7 @@ cd "$(dirname "$0")" || exit 0; -## Find PHPCS in Drupal core. Check up to three directories up. +# Find PHPCS in Drupal core. Check up to three directories up. DIR=$(pwd) for i in {0..3}; do DIR=$(dirname "$DIR") diff --git a/scripts/phpunit.sh b/scripts/phpunit.sh new file mode 100755 index 0000000000000000000000000000000000000000..4a58223074bce09a24afba595ef2cd4e4b5c8c5a --- /dev/null +++ b/scripts/phpunit.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# NAME +# phpunit.sh - Runs PHPUnit tests. +# +# SYNOPSIS +# bash phpunit.sh +# +# DESCRIPTION +# Run all Automatic Updates PHPUnit tests. +# +# It is assumed that this module is inside a Drupal core installation, in +# modules or modules/contrib. See setup_local_dev.sh. + +cd "$(dirname "$0")" || exit 0; + +# Find PHPUnit in Drupal core. Check up to three directories up. +DIR=$(pwd) +for i in {0..3}; do + DIR=$(dirname "$DIR") + PHPUNIT_BIN="$DIR/vendor/bin/phpunit" + PHPUNIT_CONFIG="$DIR/core/phpunit.xml" + if test -f "$PHPUNIT_BIN"; then + break + fi +done + +# Exit if PHPUnit can't be found. +if test ! -f "$PHPUNIT_BIN"; then + echo "Could not find PHPUnit. Are you inside a Drupal site's 'modules' directory?" + exit 1 +fi + +# Exit if PHPUnit can't be found. +if test ! -f "$PHPUNIT_CONFIG"; then + echo "Could not find PHPUnit configuration. See setup_local_dev.sh." + exit 1 +fi + +# Run PHPUnit on the module directory. +php "$PHPUNIT_BIN" \ + -c "$PHPUNIT_CONFIG" \ + "$(cd .. && pwd)"