Skip to content

Tests: Add unit test coverage for WP_Plugin_Dependencies::get_circular_dependencies() - #14584

Closed
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/plugin-dependencies-circular
Closed

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/plugin-dependencies-circular

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Adds tests for WP_Plugin_Dependencies::get_circular_dependencies() and WP_Plugin_Dependencies::check_for_circular_dependencies(), which find plugins whose requirements form a loop. The existing hasCircularDependency.php tests only check whether a plugin has a circular dependency; the pairs and slugs that the methods store and the admin notice lists had no tests.

The tests set the dependencies read from the plugin headers through the class's static properties, which the shared test case resets. They cover:

  • stored pairs being returned without checking again;
  • an empty array before the dependencies are read, without storing anything;
  • no pairs for a chain without a loop or a dependency that is not installed;
  • the exact pairs and slugs for a plugin that requires itself (alone or next to another dependency), two plugins that require each other, and three plugins in a loop.

The loop cases assert the pairs in order, and the slugs as a set.

This is a test-only change; no production code is modified.

Testing Instructions

  1. Run the tests on single site:
    npm run test:php -- --filter Tests_Admin_WPPluginDependencies_GetCircularDependencies
  2. Run them on multisite:
    npm run test:php -- --filter Tests_Admin_WPPluginDependencies_GetCircularDependencies -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter Tests_Admin_WPPluginDependencies_GetCircularDependencies --order-by=random
  4. Run the plugins group:
    npm run test:php -- --group plugins
  5. Run PHPCS on the test file:
    node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/plugin-dependencies/getCircularDependencies.php

Trac ticket: https://core.trac.wordpress.org/ticket/65819

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Brainstorming edge-case scenarios and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.

@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review October 20, 2026 21:27
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused test-only changes match the existing implementation and isolation helpers, with no unresolved findings.

No open issues 🎉

What changed in this PR

Adds unit tests for WordPress plugin dependency cycle detection without changing production code.

Changes:

  • Tests cached results and unread dependencies.
  • Verifies stored pairs and slugs for self-dependencies and multi-plugin loops.
  • Covers dependency chains without loops and missing dependencies.
File Description
tests/​phpunit/​tests/​admin/​plugin-dependencies/​getCircularDependencies.php Adds cycle-detection tests using shared state-isolation helpers.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit-tests audit found no landing blockers. The affected classes passed individually and together across three randomized seeds on single-site and multisite, with no failures or skips. PHPCS passed.

Optional follow-up: parameterize the cached-dependencies case with an empty cached array while retaining cyclic input. That would protect the empty-cache boundary without adding a separate test.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 20, 2026
Test `WP_Plugin_Dependencies::get_circular_dependencies()` and `WP_Plugin_Dependencies::check_for_circular_dependencies()` for cached results, acyclic dependencies, missing plugins, and dependency cycles.

Developed in: #14584

Props huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64666 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 20, 2026
Test `WP_Plugin_Dependencies::get_circular_dependencies()` and `WP_Plugin_Dependencies::check_for_circular_dependencies()` for cached results, acyclic dependencies, missing plugins, and dependency cycles.

Developed in: WordPress/wordpress-develop#14584

Props huzaifaalmesbah.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64666


git-svn-id: http://core.svn.wordpress.org/trunk@63816 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

3 participants