reuse existing deferred events mechanism + testing #7014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHP Unit Tests | |
| on: [ push, pull_request ] # Run on all pushes and PRs | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| UnitTests: | |
| name: PHP unit tests - PHP ${{ matrix.php }}, WP ${{ matrix.wp-version }}, WC ${{ matrix.wc-version }} | |
| runs-on: ubuntu-latest | |
| env: | |
| WP_CORE_DIR: "/tmp/wordpress/src" | |
| WP_TESTS_DIR: "/tmp/wordpress/tests/phpunit" | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: [ 7.4, 8.3 ] | |
| wp-version: [ latest ] | |
| wc-version: [ latest ] | |
| steps: | |
| - name: Install SVN | |
| run: sudo apt-get install subversion -y | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Prepare PHP | |
| uses: woocommerce/grow/prepare-php@actions-v1 | |
| with: | |
| php-version: "${{ matrix.php }}" | |
| coverage: xdebug | |
| - name: Prepare MySQL | |
| uses: woocommerce/grow/prepare-mysql@actions-v1 | |
| - name: Install WP tests | |
| run: | | |
| chmod +x ./bin/install-wp-tests.sh | |
| ./bin/install-wp-tests.sh wordpress_test root root localhost ${{ matrix.wp-version }} ${{ matrix.wc-version }} | |
| - name: Run PHP unit tests with coverage | |
| id: phpunit | |
| run: | | |
| echo "🧪 Running PHP unit tests with coverage..." | |
| # Run tests once with both verbose output and coverage generation | |
| if ./vendor/bin/phpunit --verbose --coverage-clover=coverage.xml; then | |
| echo "✅ All tests passed!" | |
| TEST_STATUS="passed" | |
| # Extract coverage summary from XML | |
| COVERAGE=$(php -r " | |
| if (file_exists('coverage.xml')) { | |
| \$xml = simplexml_load_file('coverage.xml'); | |
| \$metrics = \$xml->project->metrics; | |
| \$covered = (int)\$metrics['coveredstatements']; | |
| \$total = (int)\$metrics['statements']; | |
| \$percentage = \$total > 0 ? round((\$covered / \$total) * 100, 2) : 0; | |
| echo \$percentage; | |
| } else { | |
| echo '0'; | |
| } | |
| ") | |
| echo "coverage_summary=$COVERAGE" >> $GITHUB_OUTPUT | |
| echo "📊 Coverage: $COVERAGE%" | |
| else | |
| echo "❌ Some tests failed!" | |
| TEST_STATUS="failed" | |
| # Clean up any partial coverage file | |
| rm -f coverage.xml | |
| exit 1 | |
| fi | |
| echo "test_status=$TEST_STATUS" >> $GITHUB_OUTPUT | |
| - name: Upload coverage reports | |
| if: steps.phpunit.outputs.test_status == 'passed' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: php-coverage-report PHP - ${{ matrix.php }}, WP - ${{ matrix.wp-version }} , WC - ${{ matrix.wc-version }} | |
| path: coverage.xml | |
| retention-days: 30 | |
| - name: Check coverage threshold | |
| if: steps.phpunit.outputs.test_status == 'passed' | |
| run: | | |
| COVERAGE="${{ steps.phpunit.outputs.coverage_summary }}" | |
| MIN_THRESHOLD=35 | |
| echo "📈 Coverage: $COVERAGE%" | |
| echo "🎯 Threshold: $MIN_THRESHOLD%" | |
| if (( $(echo "$COVERAGE $MIN_THRESHOLD" | awk '{print ($1 >= $2)}') )); then | |
| echo "✅ Coverage check passed!" | |
| else | |
| echo "❌ Coverage too low. Need $MIN_THRESHOLD%, got $COVERAGE%" | |
| exit 1 | |
| fi |