Skip to content

Fix test suite isolation by cleaning up registered theme directories and cache in teardown #895

Open

Description

@CookieDarb

Running the full PHPUnit test suite (npm run test:unit:php) produces 1 error and 5 failures across Test_Create_Block_Theme_Api and Test_Create_Block_Theme_Fonts, even though both test classes pass completely when run in isolation.

This happens because CBT_Theme_Locale_UnitTestCase (tests/CbtThemeLocale/base.php) and CBT_Theme_Readme_UnitTestCase (tests/CbtThemeReadme/base.php) register a custom test theme directory via register_theme_directory() in set_up(), but do not restore the global $wp_theme_directories array or call wp_clean_themes_cache() in tear_down().

Steps to Reproduce

  1. Run CBT_Theme_Locale_EscapeAttribute immediately followed by Test_Create_Block_Theme_Api:

    npm run test:unit:php:base -- --filter "CBT_Theme_Locale_EscapeAttribute|Test_Create_Block_Theme_Api"
  2. Observe 2 failures in Test_Create_Block_Theme_Api.

  3. Run Test_Create_Block_Theme_Api alone:

    npm run test:unit:php:base -- --filter Test_Create_Block_Theme_Api
  4. Observe that all tests pass.

Expected Behaviour

Tests should run in clean isolation. Base test cases that register custom theme directories should restore $wp_theme_directories and call wp_clean_themes_cache() in tear_down() so subsequent test suites are not polluted.

Actual Behaviour

Custom theme directories remain in the global $wp_theme_directories array and theme caches remain stale. Subsequent tests that dynamically create themes on disk fail to resolve them, leading to 1 error and 5 failures during full suite runs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions