Skip to content

Add PHPUnit unit tests for plugin classes (0% → 98% line coverage) - #1

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787085337-phpunit-tests
Open

Add PHPUnit unit tests for plugin classes (0% → 98% line coverage)#1
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787085337-phpunit-tests

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

The repo had no tests at all — coverage of src/ was 0%. This adds a PHPUnit suite that runs without a WordPress installation, covering all four classes (Plugin, Frontend, Admin, REST): 47 tests, 100% of classes/methods and 97.8% of lines (the only uncovered lines are the exit in each ABSPATH guard).

Instead of pulling in WP test scaffolding, tests/wp-stubs.php defines the ~40 WP functions the plugin calls plus WP_Query/WP_Error doubles, and WPStub records every call so tests can assert on registration side effects:

new REST( $pluginStub );
$call = WPStub::firstCall( 'register_rest_route' ); // ['doneproject/v1', '/hello', [...]]

Most of the coverage weight is Frontend, where the interesting logic lives — the two private helpers are exercised via reflection: get_first_image_src_from_content (no img, single/double quoted src, first-of-many) and generate_content_image_thumbnail across every branch: remote URL passthrough, missing local file, query-string stripping, cached thumb reuse (no editor call), wp_mkdir_p failure, wp_get_image_editor returning WP_Error, and save() failure. Thumbnail tests write real files into a temp uploads dir so file_exists/md5_file behave as in production.

Two supporting fixes:

  • composer.json PSR-4 prefix was over-escaped ("DoneProject\\\\" → literal DoneProject\\), so Composer autoloading never resolved the classes; corrected to "DoneProject\\" and added autoload-dev for DoneProject\Tests\ plus composer test scripts.
  • .gitignore now excludes /vendor/, /composer.lock, .phpunit.result.cache.

Also adds a Tests GitHub Actions workflow running the suite on PHP 7.4/8.1/8.3 (composer update per version, hence no committed lock) and a README section on running tests/coverage.

Link to Devin session: https://app.devin.ai/sessions/15517074725a4224986972cd3c154942
Requested by: @liikane

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@liikane liikane self-assigned this Aug 18, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

1 participant