From 5e5d8a7330fd520b8f834ea30d5928ec26c4859e Mon Sep 17 00:00:00 2001 From: Daniel Bosen Date: Tue, 11 Jan 2022 13:41:25 +0100 Subject: [PATCH] Replace absolute bin calls with composer exec --- bin/test-drupal-project | 3 +++ lib/file_system_helper.sh | 10 ---------- lib/stages/deprecation.sh | 4 +--- lib/stages/install.sh | 6 +++--- lib/stages/prepare_build.sh | 6 +++--- lib/stages/run_tests.sh | 10 +++++----- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/bin/test-drupal-project b/bin/test-drupal-project index 27e5d20..c1aaf90 100755 --- a/bin/test-drupal-project +++ b/bin/test-drupal-project @@ -88,6 +88,9 @@ done DRUPAL_TESTING_TEST_STAGE=${DRUPAL_TESTING_TEST_STAGE:-run_tests} SCRIPT_DIR=$(get_script_dir) +# Reset COMPOSER_BIN_DIR, otherwise composer exec will not work as expected in composer versions > 2.2.2 +unset COMPOSER_BIN_DIR + ### Source required files ### # shellcheck source=/dev/null source "${SCRIPT_DIR}/../configuration.sh" diff --git a/lib/file_system_helper.sh b/lib/file_system_helper.sh index 840a337..123b55e 100755 --- a/lib/file_system_helper.sh +++ b/lib/file_system_helper.sh @@ -20,16 +20,6 @@ get_distribution_docroot() { fi } -get_composer_bin_directory() { - if [[ ! -f "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"/composer.json ]]; then - exit 1 - fi - - local composer_bin_dir=${DRUPAL_TESTING_COMPOSER_BIN_DIR:-$(jq -er '.config."bin-dir" // "vendor/bin"' "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"/composer.json)} - - echo "${composer_bin_dir}" -} - get_project_location() { local docroot local project_type_test_location="" diff --git a/lib/stages/deprecation.sh b/lib/stages/deprecation.sh index 7a0296c..5e28bf1 100644 --- a/lib/stages/deprecation.sh +++ b/lib/stages/deprecation.sh @@ -5,17 +5,15 @@ _stage_deprecation() { printf "Checking for deprecations.\n\n" local project_location - local composer_bin_dir project_location=$(get_project_location) - composer_bin_dir=$(get_composer_bin_directory) if [ ! -f "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}/phpstan.neon" ]; then cp phpstan.neon "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" fi cd "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" || exit - "${composer_bin_dir}/phpstan" analyse --memory-limit "${PHPSTAN_MEMORY_LIMIT}" "${project_location}" + composer exec phpstan -- analyse --memory-limit "${PHPSTAN_MEMORY_LIMIT}" "${project_location}" cd - || exit fi } diff --git a/lib/stages/install.sh b/lib/stages/install.sh index b282ab3..bf0be0f 100644 --- a/lib/stages/install.sh +++ b/lib/stages/install.sh @@ -5,15 +5,13 @@ _stage_install() { printf "Installing project\n\n" local docroot - local composer_bin_dir local drush local installed_version local major_version local minor_version docroot=$(get_distribution_docroot) - composer_bin_dir=$(get_composer_bin_directory) - drush="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}/${composer_bin_dir}/drush --root=${docroot}" + drush="composer exec -- drush --root=${docroot}" cd "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" || exit installed_version=$(composer show 'drupal/core' | grep 'versions' | grep -o -E '[^ ]+$') @@ -31,11 +29,13 @@ _stage_install() { echo "\$config_directories = [ CONFIG_SYNC_DIRECTORY => '${DRUPAL_TESTING_CONFIG_SYNC_DIRECTORY}' ];" >>"${sites_directory}/settings.php" fi + cd "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" || exit if [ "${DRUPAL_TESTING_INSTALL_FROM_CONFIG}" = true ]; then ${drush} --verbose --db-url="${SIMPLETEST_DB}" --sites-subdir="${DRUPAL_TESTING_SITES_DIRECTORY}" --yes --existing-config site-install else ${drush} --verbose --db-url="${SIMPLETEST_DB}" --sites-subdir="${DRUPAL_TESTING_SITES_DIRECTORY}" --yes site-install "${DRUPAL_TESTING_TEST_PROFILE}" "${DRUPAL_TESTING_INSTALLATION_FORM_VALUES}" fi + cd - || exit if [[ ${DRUPAL_TESTING_TEST_DUMP_FILE} != "" ]]; then cd "${docroot}" || exit diff --git a/lib/stages/prepare_build.sh b/lib/stages/prepare_build.sh index aa60383..964171e 100644 --- a/lib/stages/prepare_build.sh +++ b/lib/stages/prepare_build.sh @@ -39,13 +39,13 @@ _stage_prepare_build() { # Require phpstan. if [ "${DRUPAL_TESTING_TEST_DEPRECATION}" = true ]; then - composer require mglaman/phpstan-drupal:^1.1 --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" - composer require phpstan/phpstan-deprecation-rules:^1.0 --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" + composer require mglaman/phpstan-drupal:^1.1 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" + composer require phpstan/phpstan-deprecation-rules:^1.0 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" fi # Paratest. if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then - composer require brianium/paratest:^6.3 --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" + composer require brianium/paratest:^6.3 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" fi # Reorder repositories, to make sure, local path is first. diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index 427f46d..95b5ad8 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -4,17 +4,15 @@ _stage_run_tests() { printf "Running tests\n\n" local docroot - local composer_bin_dir local test_location docroot=$(get_distribution_docroot) - composer_bin_dir=$(get_composer_bin_directory) test_location=$(get_project_location) local test_selection="" - local phpunit=${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}/${composer_bin_dir}/phpunit" --debug" + local phpunit="composer exec -- phpunit --debug" if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then - phpunit=${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}/${composer_bin_dir}/paratest" -p "${DRUPAL_TESTING_PARALLEL_TESTING_PROCESSES} + phpunit="composer exec -- paratest -p "${DRUPAL_TESTING_PARALLEL_TESTING_PROCESSES} if [ "${DRUPAL_TESTING_PARALLEL_TESTING_PER_FUNCTION}" = true ]; then phpunit=${phpunit}" -f" fi @@ -52,7 +50,9 @@ _stage_run_tests() { test_selection="${test_selection} --filter ${DRUPAL_TESTING_TEST_FILTER}" fi - local runtest="php ${phpunit} --verbose --configuration ${docroot}/core ${test_selection} ${test_location}" + local runtest="${phpunit} --verbose --configuration ${docroot}/core ${test_selection} ${test_location}" + cd "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" || exit eval "${runtest}" || exit 1 + cd - || exit }