Skip to content

test: Search PHPUnit tests#213

Open
Kallyan01 wants to merge 23 commits into
mainfrom
test/search-phpunit-tests
Open

test: Search PHPUnit tests#213
Kallyan01 wants to merge 23 commits into
mainfrom
test/search-phpunit-tests

Conversation

@Kallyan01
Copy link
Copy Markdown
Collaborator

@Kallyan01 Kallyan01 commented May 8, 2026

What

Added Search Module PHPUnit test cases.

Why

Improves development workflow by enabling faster and more reliable validation of REST functionality, reducing repetitive manual testing efforts.

Related Issue(s):

How

AI Disclosure

Hybrid approach = Written by Me + Copilot (Claude Opus 4.6, GPT 5.3) + Audited by me

Testing Instructions

npm run wp-env:test -- start --xdebug=coverage    

npm run test:php -- tests/php/Unit/Modules/Search

Screenshots

Additional Info

Checklist

  • I have read the Contribution Guidelines.
  • I have read the Development Guidelines.
  • I have added necessary tests to cover my changes.
  • I have updated the project documentation as needed.
  • My code has detailed inline documentation.
  • My code is tested to the best of my abilities.
  • My code passes all lints, tests, and checks.
Open WordPress Playground Preview

Copilot AI review requested due to automatic review settings May 8, 2026 06:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds PHPUnit unit tests for the Search module’s WordPress integration points and for the Algolia Index wrapper, helping validate hook registration and several “remote post” mapping behaviors.

Changes:

  • Add SearchTest covering hook registration and selected behaviors for permalinks, author fields, term links, and rendered block rewriting.
  • Add IndexTest covering error returns when prerequisites are missing and verifying Index::get_index() caching behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
tests/php/Unit/Modules/Search/SearchTest.php Introduces unit tests for OneSearch\Modules\Search\Search behaviors (hooks, mapping, block output).
tests/php/Unit/Modules/Search/IndexTest.php Introduces unit tests for OneSearch\Modules\Search\Index error handling and caching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/php/Unit/Modules/Search/SearchTest.php Outdated
Comment thread tests/php/Unit/Modules/Search/SearchTest.php
Comment thread tests/php/Unit/Modules/Search/SearchTest.php Outdated
Comment thread tests/php/Unit/Modules/Search/SearchTest.php
Comment thread tests/php/Unit/Modules/Search/IndexTest.php
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread tests/php/Unit/Modules/Search/SettingsTest.php
Comment thread tests/php/Unit/Modules/Search/WatcherTest.php Outdated
Copy link
Copy Markdown
Member

@sabbir1991 sabbir1991 left a comment

Choose a reason for hiding this comment

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

Please review the coverage HTML again and check the functions are fully covered which test you have written

Comment thread tests/php/Unit/Modules/Search/IndexTest.php
Comment thread tests/php/Unit/Modules/Search/SearchTest.php
Comment thread tests/php/Unit/Modules/Search/SearchTest.php
Comment thread tests/php/Unit/Modules/Search/SearchTest.php
@Kallyan01 Kallyan01 requested a review from sabbir1991 May 12, 2026 13:13
sabbir1991
sabbir1991 previously approved these changes May 12, 2026
Copy link
Copy Markdown
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Great first pass! 🙌 Especially a fan of daab8dc before I even asked ;-)

Just some minor cleanup and trying to cover the few areas the coverage report missed. We'll be refactoring soon though, so if something I asked for isn't easily testable, lmk and maybe we'll skip it.

Comment thread tests/php/Unit/Modules/Search/IndexTest.php Outdated
Comment thread tests/php/Unit/Modules/Search/IndexTest.php
Comment thread tests/php/Unit/Modules/Search/SearchTest.php Outdated
Comment thread tests/php/Unit/Modules/Search/SearchTest.php Outdated
Comment thread tests/php/Unit/Modules/Search/SearchTest.php
Comment thread tests/php/Unit/Modules/Search/SettingsTest.php
Comment thread tests/php/Unit/Modules/Search/SettingsTest.php
Comment thread tests/php/Unit/Modules/Search/WatcherTest.php
@Kallyan01 Kallyan01 requested a review from justlevine May 21, 2026 20:27
/**
* Returns true when index_all_posts is called with no post types and valid credentials.
*/
public function test_index_all_posts_returns_true_with_valid_credentials_and_no_post_types(): void {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we need one more successful index_all_posts with 101 posts, so it triggers ::generate_post_batches(), but I'm on the fence.

@Kallyan01 thoughts?

image.png

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added the case, I think it's a good testcase to add.

Copy link
Copy Markdown
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

These look good!

I'm wondering if it's worth it for you to do one more pass through the coverage report, and see if there's some more low-hanging you can catch here, e.g. from a brand site, w. author info, composite scores, > 100 posts, etc. Still outcome based, nothing that requires elaborate stubbing.

Alternatively, we can skip them now add the coverage to the areas that we refactor, the missing areas aren't particularly important for back-compat, just catching unintentional breaks...

@Kallyan01 can you take a look at the report and let me know which - if any - you think are worth doing now vs later?

@Kallyan01
Copy link
Copy Markdown
Collaborator Author

These look good!

I'm wondering if it's worth it for you to do one more pass through the coverage report, and see if there's some more low-hanging you can catch here, e.g. from a brand site, w. author info, composite scores, > 100 posts, etc. Still outcome based, nothing that requires elaborate stubbing.

Alternatively, we can skip them now add the coverage to the areas that we refactor, the missing areas aren't particularly important for back-compat, just catching unintentional breaks...

@Kallyan01 can you take a look at the report and let me know which - if any - you think are worth doing now vs later?

Sure, I've started looking into it, I'll let you know if I find something.

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.

4 participants