From 004aa86c09810d6a56781165af334055c3d7ddf5 Mon Sep 17 00:00:00 2001 From: antoine Date: Mon, 31 Oct 2022 13:44:45 +0100 Subject: [PATCH 1/2] Allow COMPOSER_FLAGS env. variable --- run-build-functions.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 9a8944d5..e026de75 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -76,6 +76,7 @@ mkdir -p $NETLIFY_CACHE_DIR/.cargo : ${NPM_FLAGS=""} : ${PNPM_FLAGS=""} : ${BUNDLER_FLAGS=""} +: ${COMPOSER_FLAGS=""} # Feature flags are a comma-separated list. # The following logic relies on the fact that feature flags cannot currently @@ -748,7 +749,7 @@ install_dependencies() { if [ -f composer.json ] then restore_home_cache ".composer" "composer dependencies" - composer install + composer install ${COMPOSER_FLAGS:+$COMPOSER_FLAGS} fi install_go $installGoVersion From d0edef55adffbea877cb94d52732ca636561a81e Mon Sep 17 00:00:00 2001 From: antoine Date: Thu, 8 Dec 2022 17:50:38 +0100 Subject: [PATCH 2/2] Add composer tests --- run-build-functions.sh | 6 +++- tests/php/composer.bats | 35 +++++++++++++++++++++ tests/php/fixtures/simple-php/composer.json | 4 +++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/php/composer.bats create mode 100644 tests/php/fixtures/simple-php/composer.json diff --git a/run-build-functions.sh b/run-build-functions.sh index e026de75..b0216427 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -281,6 +281,10 @@ run_npm() { export PATH=$(npm bin):$PATH } +run_composer() { + composer install ${COMPOSER_FLAGS:+$COMPOSER_FLAGS} +} + install_node() { local defaultNodeVersion=$1 local featureFlags=$2 @@ -749,7 +753,7 @@ install_dependencies() { if [ -f composer.json ] then restore_home_cache ".composer" "composer dependencies" - composer install ${COMPOSER_FLAGS:+$COMPOSER_FLAGS} + run_composer fi install_go $installGoVersion diff --git a/tests/php/composer.bats b/tests/php/composer.bats new file mode 100644 index 00000000..e73925cf --- /dev/null +++ b/tests/php/composer.bats @@ -0,0 +1,35 @@ +#!/usr/bin/env bats + +load "../helpers.sh" + +load '../../node_modules/bats-support/load' +load '../../node_modules/bats-assert/load' +load '../../node_modules/bats-file/load' + +setup() { + TMP_DIR=$(setup_tmp_dir) + set_fixture_as_repo 'simple-php' "$TMP_DIR" + + # Load functions + load '../../run-build-functions.sh' +} + +teardown() { + rm -rf "$TMP_DIR" + # Return to original dir + cd - || return +} + +@test 'composer install' { + run run_composer + assert_success + assert_output --partial "(including require-dev)" +} + +@test 'composer install with flags' { + COMPOSER_FLAGS="--no-dev" + + run run_composer + assert_success + refute_output --partial "(including require-dev)" +} \ No newline at end of file diff --git a/tests/php/fixtures/simple-php/composer.json b/tests/php/fixtures/simple-php/composer.json new file mode 100644 index 00000000..e5c748f9 --- /dev/null +++ b/tests/php/fixtures/simple-php/composer.json @@ -0,0 +1,4 @@ +{ + "name": "fixture/simple-php", + "require": {} +}