@@ -78,84 +78,68 @@ jobs:
7878 - name : Install SVN and jq
7979 run : |
8080 sudo apt-get update
81- sudo apt-get install -y subversion jq
81+ sudo apt-get install -y subversion jq bc
8282
83- - name : Install Composer dependencies
84- uses : ramsey/composer-install@v3
85- with :
86- composer-options : " --prefer-dist --no-progress"
87- continue-on-error : true
88-
89- - name : Verify Composer installation
83+ # Robust PHPUnit installation
84+ - name : Verify and Install PHPUnit
9085 run : |
91- # Clean start - remove composer.lock to avoid cached dependency issues
92- rm -f composer.lock
93-
94- # Add bc command needed for version comparison
95- sudo apt-get install -y bc
86+ echo "Installing PHPUnit for PHP ${{ matrix.php }}"
9687
97- # Define PHP version variable for use in conditions
88+ # Define PHP version for easier conditions
9889 PHP_VERSION="${{ matrix.php }}"
9990
100- # Determine what PHPUnit version to use
101- if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
102- echo "::notice::Using PHP $PHP_VERSION, configuring for PHPUnit 9.x"
103- # Use jq to update phpunit requirement in composer.json
104- cp composer.json composer.json.bak
105- jq '.["require-dev"]["phpunit/phpunit"] = "^9.0"' composer.json.bak > composer.json
106-
107- # Also update yoast/phpunit-polyfills to latest
108- jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json > composer.json.tmp
109- mv composer.json.tmp composer.json
110- else
111- echo "::notice::Using PHP $PHP_VERSION, keeping PHPUnit 7.5.x"
112- # No change needed for PHP 7.x
113- fi
91+ # Remove any existing lock file to ensure clean install
92+ rm -f composer.lock
11493
115- # Write a custom composer.json for PHP 8.2 to handle specific requirements
116- if [[ "$PHP_VERSION" == "8.2" ]]; then
117- echo "::notice::Using PHP 8.2, creating specialized composer configuration"
118-
119- # Start with a copy of the existing composer.json
120- cp composer.json composer.json.original
121-
122- # Update dependencies for PHP 8.2 compatibility
123- jq '.["require-dev"]["phpunit/phpunit"] = "^9.5"' composer.json.original > composer.json.tmp
124- jq '.["require-dev"]["yoast/phpunit-polyfills"] = "^2.0"' composer.json.tmp > composer.json.tmp2
94+ # For PHP 8.x, use PHPUnit 9.5
95+ if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
96+ echo "::notice::Using PHPUnit 9.5 for PHP $PHP_VERSION"
12597
126- # Set platform config
127- jq '.config.platform.php = "8.1.99"' composer.json.tmp2 > composer.json.tmp3
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
128102
129- # Add PHP 8 specific test script
130- jq '.scripts["test:php8"] = "php run-phpunit.php"' composer.json.tmp3 > composer.json
103+ # Add PHP 8 specific test script if needed
104+ 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
107+ fi
131108
132- # Clean up tmp files
133- rm -f composer.json.tmp*
134- rm -f composer.json.original
135- fi
136-
137- # Install dependencies based on PHP version
138- echo "::notice::Installing Composer dependencies for PHP $PHP_VERSION"
139- if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
140- composer update --no-progress --ignore-platform-reqs
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
113+ composer require --dev phpunit/phpunit:^9.5 yoast/phpunit-polyfills:^2.0 --no-progress --ignore-platform-reqs || {
114+ echo "::error::PHPUnit installation failed"
115+ exit 1
116+ }
117+ }
141118 else
142- composer update --no-progress
119+ # For PHP 7.x, use PHPUnit 7.5
120+ 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"
126+ exit 1
127+ }
128+ }
143129 fi
144130
145- # Check if installation was successful
146- if [ ! -d "vendor" ] || [ ! -f "vendor/bin/phpunit" ]; then
147- echo "::error::Failed to install PHPUnit. Trying a direct approach."
148- rm -rf vendor
149- if [[ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" || "$PHP_VERSION" == "8.2" ]]; then
150- composer require --dev yoast/phpunit-polyfills:^2.0 phpunit/phpunit:^9.5 --ignore-platform-reqs --no-progress
151- else
152- composer require --dev yoast/phpunit-polyfills:^1.0 phpunit/phpunit:^7.5 --no-progress
153- fi
131+ # Clean up temporary files
132+ rm -f composer.json.tmp* composer.json.backup
133+
134+ # Verify PHPUnit installation
135+ if [ ! -f "vendor/bin/phpunit" ]; then
136+ echo "::error::PHPUnit installation unsuccessful."
137+ exit 1
154138 fi
155139
156- # Verify PHPUnit version
140+ # Show installed PHPUnit version
157141 echo "Installed PHPUnit version:"
158- vendor/bin/phpunit --version || echo "PHPUnit seems to be missing or broken "
142+ vendor/bin/phpunit --version || echo "PHPUnit seems to be installed but not working properly "
159143
160144 - name : Check Test Environment
161145 id : check-test-env
@@ -170,26 +154,33 @@ jobs:
170154 echo "test_env_ready=true" >> $GITHUB_OUTPUT
171155 fi
172156
157+ # Enhanced WordPress Test Environment Setup
173158 - name : Setup WordPress Test Environment
174159 if : steps.check-test-env.outputs.test_env_ready == 'true'
175160 run : |
176- if mysql -u root -h 127.0.0.1 -e "USE wordpress_test;" 2>/dev/null; then
177- echo "Database 'wordpress_test' already exists. Dropping it first."
178- mysql -u root -h 127.0.0.1 -e "DROP DATABASE wordpress_test;"
179- fi
180-
181- # Create the database explicitly to avoid potential issues
182- mysql -u root -h 127.0.0.1 -e "CREATE DATABASE IF NOT EXISTS wordpress_test;"
161+ # Ensure database exists and is clean
162+ echo "Setting up test database..."
163+ mysql -u root -h 127.0.0.1 -e "DROP DATABASE IF EXISTS wordpress_test;"
164+ mysql -u root -h 127.0.0.1 -e "CREATE DATABASE wordpress_test;"
183165
184166 # Make the install script executable
185167 chmod +x bin/install-wp-tests.sh
186168
187- # Install WordPress test environment
169+ # Run the script with detailed logging
170+ echo "Installing WordPress test environment for version ${{ matrix.wordpress }}..."
188171 bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 ${{ matrix.wordpress }} || {
189- echo "::warning ::Failed to setup WordPress test environment. Showing detailed error information:"
190- cat /tmp/ wordpress-tests-lib-install-*.log 2>/dev/null || echo "No install logs found."
172+ echo "::error ::Failed to setup WordPress test environment. Showing detailed error information:"
173+ find /tmp -name " wordpress-tests-lib-install-*.log" -exec cat {} \; 2>/dev/null || echo "No install logs found."
191174 exit 1
192175 }
176+
177+ # Verify the test environment was created successfully
178+ if [ ! -d "/tmp/wordpress-tests-lib" ] || [ ! -f "/tmp/wordpress-tests-lib/includes/functions.php" ]; then
179+ echo "::error::WordPress test environment setup failed. Missing required files."
180+ exit 1
181+ fi
182+
183+ echo "WordPress test environment successfully set up."
193184
194185 - name : Run tests
195186 if : steps.check-test-env.outputs.test_env_ready == 'true'
0 commit comments