Skip to content

Commit

Permalink
Replace absolute bin calls with composer exec
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen authored Jan 11, 2022
1 parent bd40b13 commit 5e5d8a7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 24 deletions.
3 changes: 3 additions & 0 deletions bin/test-drupal-project
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 0 additions & 10 deletions lib/file_system_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
4 changes: 1 addition & 3 deletions lib/stages/deprecation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions lib/stages/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '[^ ]+$')
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/stages/prepare_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions lib/stages/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 5e5d8a7

Please sign in to comment.