8080 sudo apt-get update
8181 sudo apt-get install -y subversion jq bc
8282
83- # Robust PHPUnit installation
83+ # Robust PHPUnit installation with enhanced error handling
8484 - name : Verify and Install PHPUnit
8585 run : |
8686 echo "Installing PHPUnit for PHP ${{ matrix.php }}"
@@ -91,38 +91,57 @@ jobs:
9191 # Remove any existing lock file to ensure clean install
9292 rm -f composer.lock
9393
94+ # Setup environment information for debugging
95+ echo "::notice::Debugging environment variables:"
96+ echo "PHP Version: $PHP_VERSION"
97+ php -v
98+
99+ # Configure platform version in composer.json for better dependency resolution
100+ cp composer.json composer.json.backup
101+
94102 # For PHP 8.x, use PHPUnit 9.5
95103 if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
96104 echo "::notice::Using PHPUnit 9.5 for PHP $PHP_VERSION"
97105
98- # Create a compatible composer.json for PHP 8.x
99- cp composer.json composer.json.backup
100- jq '.["require-dev"]["phpunit/phpunit"] = "^9.5"' composer.json.backup > composer.json.tmp1
101- jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json.tmp1 > composer.json
106+ # Configure platform and dependencies using multiple jq commands instead of heredoc
107+ jq '.config.platform.php = "8.0.0"' composer.json.backup > composer.json.tmp1
108+ jq '.["require-dev"]["phpunit/phpunit"] = "^9.5"' composer.json.tmp1 > composer.json.tmp2
109+ jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json.tmp2 > composer.json
102110
103111 # Add PHP 8 specific test script if needed
104112 if [[ "$PHP_VERSION" == "8.2" ]]; then
105- jq '.config.platform.php = "8.1.99 "' composer.json > composer.json.tmp2
106- jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json.tmp2 > composer.json
113+ jq '.scripts["test:php8"] = "php run-phpunit.php "' composer.json > composer.json.tmp3
114+ mv composer.json.tmp3 composer.json
107115 fi
108116
109- # Install using the modified composer.json
110- composer update --no-progress --ignore-platform-reqs || {
111- echo "::warning::Composer update failed, trying direct require"
112- rm -rf vendor
117+ # Install using direct require for more reliable installation
118+ echo "::notice::Installing PHPUnit via direct require for PHP $PHP_VERSION"
119+ composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
120+ echo "::error::PHPUnit installation failed. Retrying with fallback method..."
121+ # Fallback: try removing composer.lock and trying again
122+ rm -f composer.lock
113123 composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
114- echo "::error::PHPUnit installation failed"
124+ echo "::error::PHPUnit installation failed on retry as well. Debugging composer error logs:"
125+ cat composer.lock 2>/dev/null || echo "composer.lock not generated"
126+ composer diagnose || echo "Composer diagnose command failed"
115127 exit 1
116128 }
117129 }
118130 else
119131 # For PHP 7.x, use PHPUnit 7.5
120132 echo "::notice::Using PHPUnit 7.5 for PHP $PHP_VERSION"
121- composer update --no-progress || {
122- echo "::warning::Composer update failed, trying direct require"
123- rm -rf vendor
124- composer require --dev phpunit/phpunit:^7.5 yoast/phpunit-polyfills:^1.0 --no-progress || {
125- echo "::error::PHPUnit installation failed"
133+
134+ # Configure platform
135+ jq '.config.platform.php = "7.4.0"' composer.json.backup > composer.json
136+
137+ # Install using direct require for more reliable installation
138+ composer require --dev phpunit/phpunit:^7.5 yoast/phpunit-polyfills:^1.0 --no-progress || {
139+ echo "::warning::PHPUnit installation failed. Retrying with fallback method..."
140+ # Fallback: try removing composer.lock and trying again
141+ rm -f composer.lock
142+ composer require --dev phpunit/phpunit:^7.5 yoast/phpunit-polyfills:^1.0 --no-progress --ignore-platform-reqs || {
143+ echo "::error::PHPUnit installation failed on retry as well. Debugging composer error logs:"
144+ composer diagnose || echo "Composer diagnose command failed"
126145 exit 1
127146 }
128147 }
@@ -133,7 +152,8 @@ jobs:
133152
134153 # Verify PHPUnit installation
135154 if [ ! -f "vendor/bin/phpunit" ]; then
136- echo "::error::PHPUnit installation unsuccessful."
155+ echo "::error::PHPUnit installation unsuccessful. Cannot continue with tests."
156+ ls -la vendor || echo "vendor directory not found or empty"
137157 exit 1
138158 fi
139159
0 commit comments