Skip to content

Commit 60a3bb1

Browse files
authored
Fixed instrumentation unit tests executed with the distro loaded (#22) (#24)
* Removing unnecessary static analysis tools, lowering php8.2+ depenency
1 parent dafc44c commit 60a3bb1

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

tools/build/test_otel_unit_tests.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ match_packages() {
9999
done
100100
}
101101

102+
get_package_version() {
103+
local pkg_name=$1
104+
local version=$(jq -r --arg pkg "$pkg_name" '.require[$pkg]' "$OPT_COMPOSER_FILE")
105+
106+
if [[ -z "$version" || "$version" == "null" ]]; then
107+
echo "::error::Package $pkg_name not found in composer.json" >&2
108+
return 1
109+
fi
110+
111+
echo "$pkg_name:$version"
112+
}
113+
102114
setup_composer_project() {
103115
echo "::group::Installing composer project"
104116
composer ${OPT_QUIET} init -n --name "opentelemetry-php-distro/otel-tests"
@@ -175,20 +187,34 @@ echo "::endgroup::"
175187

176188
FAILURE=false
177189

190+
semconv_package=$(get_package_version "open-telemetry/sem-conv")
191+
sdk_package=$(get_package_version "open-telemetry/sdk")
192+
178193
for package in "${MATCHED_PACKAGES[@]}"; do
179194
vendor_dir="${OPT_WORKINGDIR}/vendor/$package"
180195

181196
echo "Preparing PHPUnit tests for package in directory: $vendor_dir"
182197

183198
cd $vendor_dir
184199
echo "::group::Installing $package dependencies"
200+
rm composer.lock
201+
185202
composer ${OPT_QUIET} config --no-plugins allow-plugins.php-http/discovery false
186203
composer ${OPT_QUIET} config allow-plugins.tbachert/spi true
187-
composer ${OPT_QUIET} install --dev --ignore-platform-req php
204+
205+
echo "Removing static analysis tools to avoid conflicts with tests"
206+
207+
composer ${OPT_QUIET} require php:^8.1 --no-update
208+
composer ${OPT_QUIET} remove --dev -n --no-update phan/phan phpstan/phpstan phpstan/phpstan-phpunit psalm/plugin-phpunit vimeo/psalm friendsofphp/php-cs-fixer
209+
composer ${OPT_QUIET} require -n --no-update "$semconv_package" "$sdk_package"
210+
211+
echo "Installing $package with version constraints from composer.json"
212+
composer ${OPT_QUIET} install
213+
188214
echo "::endgroup::"
189215

190216
echo "::group::🚀 Running $package tests 🚀"
191-
./vendor/bin/phpunit --debug --log-junit ${OPT_REPORTS_DESTINATION_PATH}/$package.xml
217+
./vendor/bin/phpunit --verbose --debug --log-junit ${OPT_REPORTS_DESTINATION_PATH}/$package.xml
192218

193219
if [[ $? -ne 0 ]]; then
194220
echo "::error::PHPUnit tests failed for package $package"

0 commit comments

Comments
 (0)