Skip to content

test(polylang): boot Polylang in the test bootstrap so its suite runs - #18

Merged
nlemoine merged 1 commit into
mainfrom
fix/polylang-test-bootstrap
Jun 3, 2026
Merged

test(polylang): boot Polylang in the test bootstrap so its suite runs#18
nlemoine merged 1 commit into
mainfrom
fix/polylang-test-bootstrap

Conversation

@nlemoine

@nlemoine nlemoine commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Problem

Coverage reports src/Integration/Polylang/ at 0%. Every PolylangTest silently skips via markTestSkipped('Polylang is not installed.'), because function_exists('PLL') is false during the test run even though the plugin is installed.

Root cause

Polylang 3.7+ loads its API (PLL() and the pll_* functions, in src/api.php) only from Polylang::init_context(). init() reaches init_context() only when it detects a context — admin, REST, or frontend with languages defined.

Under PHPUnit there is no request context, and languages are created per test (after Refresh_Database rolls them back), so at bootstrap init() sees an empty context, returns before requiring src/api.php, and PLL() is never defined. The existing bootstrap call (new \Polylang(); ->init();) is therefore a no-op for loading the API.

This surfaced after Polylang updated past its loader refactor (composer allows ^3.4; 3.8.4 is installed).

Fix

Force a frontend context through Polylang's own pll_context filter so init_context() runs and loads the API. This completes the original intent — TestCase::setPolylangDefaultLanguage() already recreates languages per test, assuming Polylang booted once at bootstrap.

Verification

  • src/Integration/Polylang/ coverage: 0% → ~79% (88/112 statements); all six classes now exercised.
  • PLUGINS=polylang … --testsuite=plugin-integration: 43 passed, 0 failures, no Polylang skips — un-skipping surfaced no real bugs.
  • phpcs and PHPStan clean on tests/bootstrap.php.
  • The change is guarded by $isPolylang, so non-Polylang suites are unaffected.

Polylang 3.7+ requires src/api.php (which defines PLL() and the pll_* API) only from init_context(), and init() reaches init_context() only when it detects a context: admin, REST, or frontend-with-languages. Under PHPUnit there is no request context and languages are created per test (after Refresh_Database rolls them back), so init() saw an empty context, returned before loading the API, and PLL() stayed undefined. Every PolylangTest then skipped via markTestSkipped, leaving src/Integration/Polylang at 0% coverage.

Force a frontend context through the pll_context filter so init_context() runs and loads the API. The whole PolylangTest suite now executes (0 -> ~79% line coverage on the Polylang integration).
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.42%. Comparing base (bc8219b) to head (e33aaec).

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #18      +/-   ##
============================================
+ Coverage     79.86%   87.42%   +7.55%     
  Complexity      494      494              
============================================
  Files            31       31              
  Lines          1336     1336              
============================================
+ Hits           1067     1168     +101     
+ Misses          269      168     -101     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nlemoine
nlemoine merged commit 332fc5f into main Jun 3, 2026
33 checks passed
@nlemoine
nlemoine deleted the fix/polylang-test-bootstrap branch June 3, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants