P2.9: convert tests to exercise real Craft APIs instead of synthetic event objects#115
Draft
sjelfull wants to merge 1 commit into
Draft
P2.9: convert tests to exercise real Craft APIs instead of synthetic event objects#115sjelfull wants to merge 1 commit into
sjelfull wants to merge 1 commit into
Conversation
Owner
Author
This was referenced Apr 28, 2026
Draft
This was referenced May 14, 2026
49bb901 to
fe6c741
Compare
a5ae4c9 to
e761f6e
Compare
fe6c741 to
49bb901
Compare
This was referenced May 15, 2026
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.
P2.9: convert 24 tests to real Craft API calls
Replaces synthetic event triggers with real Craft API calls across 5 test files. Previously, tests like
SchemaEventsTestwould fireCraft::$app->getDb()->trigger(DbEvent::EVENT_AFTER_OPEN)directly — which exercises the handler's listener but not the actual Craft code path that fires the event. This branch rewires those tests to call the real API (Craft::$app->getEntries()->saveSection(),Craft::$app->getRoutes()->saveRoute(), etc.) so the full production code path runs.The conversion surfaced 3 real bugs that synthetic tests had been hiding: (1) user permissions are lowercased before persist, so assertions need to match lowercase; (2) section saves require pre-saved entry types attached to the section model; (3)
Routes::saveRoute()returns a UID string, not a bool. All three are now correctly handled in the tests. Some tests are intentionally kept handler-direct with explanatory comments:PluginEventsTest(no fixture plugin to install),UserEventsTest(no real session in headless test environment),DatabaseEventsTest(real backups are slow and have filesystem side effects).What changed
tests/Pest.php(+40 LOC) — adds_audit_register_listeners_for_tests(), a reflection-based helper that registers handler listeners without going through the full plugin bootstrap. Used by tests that call real Craft APIs but need the audit listeners wired up.tests/Feature/SchemaEventsTest.php— largest change (+108/-98): all schema-change tests now callCraft::$app->getDb()->createTable()etc. instead of triggering events directly.tests/Feature/UserSecurityEventsTest.php(+71/-38) — login/logout/password tests use realCraft::$app->getUsers()calls.tests/Feature/PermissionEventsTest.php(+55/-63) — permission grant/revoke tests use realCraft::$app->getUserPermissions()calls; fixes the lowercase-permissions bug.tests/Feature/RouteEventsTest.php(+30/-24) — route tests useCraft::$app->getRoutes()->saveRoute(); fixes the UID-not-bool return.tests/Feature/PluginEventsTest.php(+18/-3) — adds why-comment explaining handler-direct approach.tests/Feature/UserEventsTest.php(+11/-1) — adds why-comment for headless session limitation.tests/Feature/DatabaseEventsTest.php(+14) — adds why-comment for backup side effects.tests/Unit/ProjectConfigTrackerTest.php(+26) — adds real project-config round-trip coverage.Tests
Stacked on
p2.8-comment-cleanup(#114)