Skip to content

GH#701: test(automations): write unit tests for EventTriggerHandler and NotificationDispatcher#705

Merged
superdav42 merged 2 commits intomainfrom
feature/test-event-trigger-notification
Mar 31, 2026
Merged

GH#701: test(automations): write unit tests for EventTriggerHandler and NotificationDispatcher#705
superdav42 merged 2 commits intomainfrom
feature/test-event-trigger-notification

Conversation

@superdav42
Copy link
Copy Markdown
Contributor

Summary

  • Adds PHPUnit integration/unit tests for 2 Automations classes with no prior test coverage
  • EventTriggerHandler: tests hook registration, attach_hooks (enabled/disabled/empty), execute_event_run transient handling, and completion action firing
  • NotificationDispatcher: tests channel filtering, Slack/Discord payload structure, HTTP mocking via pre_http_request filter, reply truncation, error status colors

Files changed

Test file Class under test Tests
EventTriggerHandlerTest.php EventTriggerHandler 10
NotificationDispatcherTest.php NotificationDispatcher 20

Acceptance criteria

  • Test file created for each class in tests/GratisAiAgent/Automations/
  • Each test covers constructor, main public methods, and error paths
  • PHPCS passes on all new files (zero violations)
  • No modifications to existing production code
  • HTTP calls mocked via pre_http_request filter (no live webhook calls)

Runtime Testing

Risk level: Low — test files only; no production code changes.
Testing method: self-assessed — PHPCS clean; test structure mirrors existing passing test files.

Closes #701


aidevops.sh v3.5.463 plugin for OpenCode v1.3.0 with claude-sonnet-4-6

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 55 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 55 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ad765550-6b96-4764-ba24-144add291df3

📥 Commits

Reviewing files that changed from the base of the PR and between 698a4ea and dc453f9.

📒 Files selected for processing (2)
  • tests/GratisAiAgent/Automations/EventTriggerHandlerTest.php
  • tests/GratisAiAgent/Automations/NotificationDispatcherTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test-event-trigger-notification

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ationDispatcher

Closes #701

Adds PHPUnit tests for:
- EventTriggerHandler (register hooks, attach_hooks, execute_event_run with
  transient handling, disabled/empty hook skipping, completion action firing)
- NotificationDispatcher (channel filtering, Slack/Discord payload structure,
  color coding, field content, reply truncation, HTTP mock via pre_http_request)

Tests use WP HTTP API mocking (pre_http_request filter) to avoid live webhook
calls. EventTriggerHandler tests use EventAutomations::create/delete for
isolation.
Reset static $registered_hooks and $executing properties via reflection
in tear_down() to prevent cross-test pollution. Remove init action added
by register() to avoid leaking hooks to subsequent test classes.
@superdav42 superdav42 force-pushed the feature/test-event-trigger-notification branch from a6d79a9 to dc453f9 Compare March 31, 2026 02:06
@superdav42 superdav42 merged commit 4ff0b71 into main Mar 31, 2026
11 of 12 checks passed
@superdav42
Copy link
Copy Markdown
Contributor Author

Closing Summary

What was done

  • Rebased feature/test-event-trigger-notification onto main to pick up the 14 PHPUnit test fixes from PR GH#697: fix 14 PHPUnit failures introduced by new test files #706 (the branch was behind main)
  • Added proper tear_down() cleanup in EventTriggerHandlerTest to reset static $registered_hooks and $executing properties via reflection, preventing cross-test pollution
  • Removed the init action added by register() in tearDown to avoid leaking hooks to subsequent test classes

Root cause analysis

The 14 PHPUnit failures were not caused by the new test files — they were pre-existing failures from PRs #692#696 that were fixed in PR #706 on main. The feature branch was created before that fix was merged, so it didn't have the fixes. Rebasing onto main resolved all 14 failures.

Testing evidence

  • PHPUnit (WP 6.9): PASS (1433 tests, 0 failures)
  • PHPUnit (WP trunk): PASS (1433 tests, 0 failures)
  • PHPUnit Coverage: PASS
  • PHPCS: PASS (zero violations)
  • PHPStan: PASS
  • E2E (WP trunk): PASS (224 tests)
  • E2E (WP 6.9): 1 flaky failure (FAB badge visibility + session timeout — unrelated to PHPUnit test changes)

Key decisions

  • Used reflection to reset private static properties rather than making them public or adding a reset method to production code
  • Targeted remove_action() for the specific hook+callback+priority rather than remove_all_actions() to avoid disrupting other test classes

Files changed

  • tests/GratisAiAgent/Automations/EventTriggerHandlerTest.php — added tearDown cleanup

Closes #701


aidevops.sh v3.5.466 plugin for OpenCode v1.3.0 with claude-opus-4-6 spent 21m and 11,183 tokens on this as a headless worker. Solved in 1d 18h.

@superdav42 superdav42 deleted the feature/test-event-trigger-notification branch March 31, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(automations): write unit tests for EventTriggerHandler and NotificationDispatcher

1 participant