Add PHPUnit unit tests for plugin classes (0% → 98% line coverage) - #1
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Add PHPUnit unit tests for plugin classes (0% → 98% line coverage)#1devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theexitin eachABSPATHguard).Instead of pulling in WP test scaffolding,
tests/wp-stubs.phpdefines the ~40 WP functions the plugin calls plusWP_Query/WP_Errordoubles, andWPStubrecords every call so tests can assert on registration side effects: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) andgenerate_content_image_thumbnailacross every branch: remote URL passthrough, missing local file, query-string stripping, cached thumb reuse (no editor call),wp_mkdir_pfailure,wp_get_image_editorreturningWP_Error, andsave()failure. Thumbnail tests write real files into a temp uploads dir sofile_exists/md5_filebehave as in production.Two supporting fixes:
composer.jsonPSR-4 prefix was over-escaped ("DoneProject\\\\"→ literalDoneProject\\), so Composer autoloading never resolved the classes; corrected to"DoneProject\\"and addedautoload-devforDoneProject\Tests\pluscomposer testscripts..gitignorenow excludes/vendor/,/composer.lock,.phpunit.result.cache.Also adds a
TestsGitHub Actions workflow running the suite on PHP 7.4/8.1/8.3 (composer updateper 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