@@ -80,80 +80,52 @@ jobs:
8080 sudo apt-get update
8181 sudo apt-get install -y subversion jq bc
8282
83- # Robust PHPUnit installation with enhanced error handling
84- - name : Verify and Install PHPUnit
83+ # Simplified PHPUnit installation with better error handling
84+ - name : Install Dependencies
8585 run : |
86- echo "Installing PHPUnit for PHP ${{ matrix.php }}"
86+ echo "Installing dependencies for PHP ${{ matrix.php }}"
8787
88- # Define PHP version for easier conditions
89- PHP_VERSION="${{ matrix.php }}"
88+ # Clear composer cache to avoid using corrupted cache
89+ composer clear-cache
9090
9191 # Remove any existing lock file to ensure clean install
9292 rm -f composer.lock
9393
94- # Setup environment information for debugging
94+ # Define PHP version for easier conditions
95+ PHP_VERSION="${{ matrix.php }}"
96+
97+ # Display PHP version for debugging
9598 echo "::notice::Debugging environment variables:"
9699 echo "PHP Version: $PHP_VERSION"
97100 php -v
98101
99- # Configure platform version in composer.json for better dependency resolution
100- cp composer.json composer.json.backup
102+ # Try composer update before installing PHPUnit
103+ composer update --no-progress --ignore-platform-reqs || {
104+ echo "::error::Composer update failed. Attempting direct installation..."
105+ # Try direct installation if update fails
106+ composer install --no-progress --ignore-platform-reqs || {
107+ echo "::error::Dependency installation failed. Debugging composer state:"
108+ composer diagnose
109+ # Try with --no-plugins as a last resort
110+ echo "Trying installation with --no-plugins flag"
111+ composer install --no-progress --ignore-platform-reqs --no-plugins || exit 1
112+ }
113+ }
101114
102- # For PHP 8.x, use PHPUnit 9.5
103- if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
104- echo "::notice::Using PHPUnit 9.5 for PHP $PHP_VERSION"
105-
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
110-
111- # Add PHP 8 specific test script if needed
112- if [[ "$PHP_VERSION" == "8.2" ]]; then
113- jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json > composer.json.tmp3
114- mv composer.json.tmp3 composer.json
115- fi
116-
117- # Install using direct require for more reliable installation
118- echo "::notice::Installing PHPUnit via direct require for PHP $PHP_VERSION"
115+ # Attempt PHPUnit installation if necessary
116+ if [ ! -f "vendor/bin/phpunit" ]; then
117+ echo "PHPUnit not found, attempting to install specific version..."
119118 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
123- composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
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"
127- exit 1
128- }
129- }
130- else
131- # For PHP 7.x, use PHPUnit 7.5
132- echo "::notice::Using PHPUnit 7.5 for PHP $PHP_VERSION"
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"
145- exit 1
146- }
119+ echo "::error::PHPUnit installation failed. Debugging composer error logs:"
120+ composer diagnose || echo "Composer diagnose command failed"
121+ exit 1
147122 }
148123 fi
149124
150- # Clean up temporary files
151- rm -f composer.json.tmp* composer.json.backup
152-
153125 # Verify PHPUnit installation
154126 if [ ! -f "vendor/bin/phpunit" ]; then
155127 echo "::error::PHPUnit installation unsuccessful. Cannot continue with tests."
156- ls -la vendor || echo "vendor directory not found or empty"
128+ ls -la vendor/bin || echo "vendor/bin directory not found or empty"
157129 exit 1
158130 fi
159131
@@ -186,67 +158,114 @@ jobs:
186158 # Make the install script executable
187159 chmod +x bin/install-wp-tests.sh
188160
161+ # Create and fix permissions for /tmp directory
162+ sudo mkdir -p /tmp/wordpress-tests-lib
163+ sudo chmod 1777 /tmp
164+ sudo chmod 1777 /tmp/wordpress-tests-lib
165+
166+ # Define variables for WordPress version
167+ WP_VERSION="${{ matrix.wordpress }}"
168+
189169 # Run the script with detailed logging
190- echo "Installing WordPress test environment for version ${{ matrix.wordpress }} ..."
191- bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 ${{ matrix.wordpress }} || {
170+ echo "Installing WordPress test environment for version $WP_VERSION ..."
171+ bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 $WP_VERSION || {
192172 echo "::error::Failed to setup WordPress test environment. Showing detailed error information:"
193173 find /tmp -name "wordpress-tests-lib-install-*.log" -exec cat {} \; 2>/dev/null || echo "No install logs found."
194- exit 1
174+ ls -la /tmp/wordpress-tests-lib || echo "/tmp/wordpress-tests-lib directory not found"
175+
176+ # Try one more time with explicitly created directory
177+ echo "Retrying WordPress test environment setup..."
178+ bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 $WP_VERSION || {
179+ echo "::error::Failed to setup WordPress test environment on second attempt."
180+ exit 1
181+ }
195182 }
196183
197184 # Verify the test environment was created successfully
198- if [ ! -d "/tmp/wordpress-tests-lib" ] || [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
199- echo "::error::WordPress test environment setup failed. Missing required files."
185+ if [ ! -d "/tmp/wordpress-tests-lib" ]; then
186+ echo "::error::WordPress test directory not created."
187+ exit 1
188+ fi
189+
190+ if [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
191+ echo "::error::WordPress test functions file missing."
192+ ls -la /tmp/wordpress-tests-lib/includes/ || echo "Includes directory not found or empty"
200193 exit 1
201194 fi
202195
203- echo "WordPress test environment successfully set up."
196+ # Check WordPress core installation
197+ if [ ! -d "/tmp/wordpress" ]; then
198+ echo "::error::WordPress core directory not created."
199+ exit 1
200+ fi
201+
202+ echo "WordPress test environment successfully set up:"
203+ ls -la /tmp/wordpress-tests-lib/
204204
205205 - name : Run tests
206206 if : steps.check-test-env.outputs.test_env_ready == 'true'
207207 run : |
208- if [ -f "vendor/bin/phpunit" ]; then
209- # Get the PHPUnit version
210- PHPUNIT_VERSION=$(vendor/bin/phpunit --version | grep -oP '\d+\.\d+' | head -1)
211- echo "Detected PHPUnit version: $PHPUNIT_VERSION"
212-
213- # Define PHP version variable for use in conditions
214- PHP_VERSION="${{ matrix.php }}"
208+ if [ ! -f "vendor/bin/phpunit" ]; then
209+ echo "::error::PHPUnit executable not found in vendor/bin directory."
210+ ls -la vendor/bin || echo "vendor/bin directory not found"
211+ exit 1
212+ fi
213+
214+ # Get the PHPUnit version
215+ PHPUNIT_VERSION=$(vendor/bin/phpunit --version | grep -oP '\d+\.\d+' | head -1 || echo "unknown")
216+ echo "Detected PHPUnit version: $PHPUNIT_VERSION"
217+
218+ # Define PHP version variable for use in conditions
219+ PHP_VERSION="${{ matrix.php }}"
220+
221+ # Ensure we have proper error reporting for tests
222+ export WP_TESTS_PHPUNIT_POLYFILLS_PATH=$(pwd)/vendor/yoast/phpunit-polyfills
223+
224+ # Check WordPress test environment
225+ echo "Verifying WordPress test environment..."
226+ if [ ! -d "/tmp/wordpress-tests-lib" ] || [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
227+ echo "::error::WordPress test environment verification failed. Missing required files."
228+ exit 1
229+ fi
230+
231+ # PHP 8.x specific handling
232+ if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
233+ echo "Running tests with PHP $PHP_VERSION compatibility mode"
215234
216- # Set up the command based on PHP and PHPUnit versions
217- if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
218- echo "::notice::Running tests with PHPUnit for PHP $PHP_VERSION"
219-
220- # For PHP 8.x, check if it's PHPUnit 9.x
221- if [[ $(echo "$PHPUNIT_VERSION >= 9.0" | bc -l) -eq 1 ]]; then
222- # PHPUnit 9.x on PHP 8.x - safest approach
223- echo "::notice::Using PHPUnit 9.x safe execution mode"
224-
225- # Try running tests directly without any extra flags
226- vendor/bin/phpunit || {
227- echo "::warning::Test execution failed. Running individual test files..."
228- EXIT_CODE=0
229- # Try to run each test file individually to isolate issues
230- for TEST_FILE in tests/test-*.php; do
231- echo "Testing file: $TEST_FILE"
232- vendor/bin/phpunit "$TEST_FILE" || EXIT_CODE=1
233- done
234- # Return the combined exit code
235- exit $EXIT_CODE
236- }
237- else
238- # PHPUnit < 9.0 on PHP 8.x - potentially problematic
239- echo "::warning::Running PHPUnit version less than 9.0 on PHP 8.x - using compatibility mode"
240- # Run with our compatibility layer which should handle the errors
241- XDEBUG_MODE=coverage vendor/bin/phpunit
242- fi
235+ # For PHP 8.x, we'll use our custom run-phpunit.php script
236+ if [ -f "run-phpunit.php" ]; then
237+ php run-phpunit.php || {
238+ echo "::warning::Tests failed with run-phpunit.php, trying individual test files..."
239+ EXIT_CODE=0
240+ # Try to run each test file individually to isolate issues
241+ for TEST_FILE in tests/test-*.php; do
242+ echo "Testing file: $TEST_FILE"
243+ php run-phpunit.php "$TEST_FILE" || EXIT_CODE=1
244+ done
245+ exit $EXIT_CODE
246+ }
243247 else
244- # PHP 7.x with PHPUnit 7.x - standard execution
245- echo "::notice::Running tests with PHPUnit for PHP $PHP_VERSION"
246- vendor/bin/phpunit
248+ # Fallback if custom script is missing - suppress deprecation warnings
249+ php -d error_reporting=E_ALL^E_DEPRECATED vendor/bin/phpunit || {
250+ echo "::warning::Tests failed with standard execution, trying individual test files..."
251+ EXIT_CODE=0
252+ for TEST_FILE in tests/test-*.php; do
253+ echo "Testing file: $TEST_FILE"
254+ php -d error_reporting=E_ALL^E_DEPRECATED vendor/bin/phpunit "$TEST_FILE" || EXIT_CODE=1
255+ done
256+ exit $EXIT_CODE
257+ }
247258 fi
248259 else
249- echo "::error::PHPUnit executable not found in vendor/bin directory."
250- ls -la vendor/bin || echo "vendor/bin directory not found"
251- exit 1
260+ # Standard execution for PHP 7.x
261+ echo "Running tests with PHP $PHP_VERSION standard mode"
262+ vendor/bin/phpunit || {
263+ echo "::warning::Tests failed with standard execution, trying individual test files..."
264+ EXIT_CODE=0
265+ for TEST_FILE in tests/test-*.php; do
266+ echo "Testing file: $TEST_FILE"
267+ vendor/bin/phpunit "$TEST_FILE" || EXIT_CODE=1
268+ done
269+ exit $EXIT_CODE
270+ }
252271 fi
0 commit comments