You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -71,7 +71,7 @@ description: Adds a new GitHub event type case to the switch block in `web/githu
71
71
6.**Add a test fixture** under `tests/events/<event_name>/`:
72
72
-`payload.json` — raw GitHub webhook payload (copy from GitHub delivery logs or docs)
73
73
-`type.txt` — event name only, e.g. `your_event` (no trailing newline needed; `trim()` is applied)
74
-
-Note: `expected.bin` / `discord.json` are consumed by `IrcConverter`/`DiscordConverter` tests, not by `web/github.php` — add them only if those converters also need updating.
74
+
-`expected_text.txt` — expected chat message text; run `vendor/bin/phpunit tests/GithubMessageBuilderTest.php`, capture actual output, write to file
75
75
76
76
7.**Run quality checks** to verify no syntax errors or style violations:
77
77
```bash
@@ -94,20 +94,20 @@ description: Adds a new GitHub event type case to the switch block in `web/githu
3. Created `tests/events/milestone/payload.json` and `tests/events/milestone/type.txt`containing `milestone`.
110
+
3. Created `tests/events/milestone/payload.json`, `tests/events/milestone/type.txt`(`milestone`), and `tests/events/milestone/expected_text.txt`.
111
111
4. Ran `vendor/bin/phpstan analyse` — no errors.
112
112
113
113
**Result:**`milestone` events POST to Rocket Chat and Teams with action, linked title, and optional description preview.
@@ -122,4 +122,4 @@ description: Adds a new GitHub event type case to the switch block in `web/githu
122
122
123
123
-**Event still hits `default:`**: The `$EventType` string comes from the `X-GitHub-Event` header. Verify your `case` string matches exactly (lowercase, underscores) — e.g. `'pull_request'` not `'pullRequest'`.
124
124
125
-
-**`SendToChat` returns `false` silently**: The channel key `'notifications'` must exist in both `$chatChannels['rocketchat']` and `$chatChannels['teams']` in `src/config.php`. If the URL is missing, curl will fail with HTTP 0.
125
+
-**`SendToChat` returns `false` silently**: The channel key `'notifications'` must exist in both `$chatChannels['rocketchat']` and `$chatChannels['teams']` in `src/config.php`. If the URL is missing, curl will fail with HTTP 0.
description: Creates a new test event fixture directory under tests/events/{event_name}/ with payload.json, type.txt, expected.bin, and discord.json. Use when user says 'add test for X event', 'create fixture', 'test event payload', or needs to add files to tests/events/. Do NOT use for modifying existing fixtures or writing unit tests that don't involve GitHub webhook payloads.
3
+
description: Creates a new test event fixture directory under tests/events/{event_name}/ with payload.json, type.txt, and expected_text.txt. Use when user says 'add test for X event', 'create fixture', 'test event payload', or needs to add files to tests/events/. Do NOT use for modifying existing fixtures or writing unit tests that don't involve GitHub webhook payloads.
4
4
---
5
5
# Add Test Fixture
6
6
7
7
## Critical
8
8
9
-
- Every fixture directory requires **all four files** — `EventTest.php:64` calls `file_get_contents` on all four unconditionally; missing any will cause a fatal test error:
9
+
- Every fixture directory requires **three files** — `GithubMessageBuilderTest.php` reads all three; missing any will cause a fatal test error:
10
10
```
11
11
tests/events/deployment/type.txt
12
12
tests/events/deployment/payload.json
13
-
tests/events/deployment/expected.bin
14
-
tests/events/deployment/discord.json
13
+
tests/events/deployment/expected_text.txt
15
14
```
16
-
-`expected.bin` contains IRC color codes (non-printable bytes) — **never hand-write it**. Use the generation workflow in Step 4.
17
-
- The value in `tests/events/deployment/type.txt` must match the `X-GitHub-Event` header value exactly (e.g. `push`, `pull_request`, `ping`) — no trailing newline issues; `EventTest.php:61` trims it.
15
+
-`expected_text.txt` contains plain-text chat message output — **generate it by running the test harness**, not by hand.
16
+
- The value in `tests/events/deployment/type.txt` must match the `X-GitHub-Event` header value exactly (e.g. `push`, `pull_request`, `ping`) — no trailing newline issues; the test trims it.
18
17
19
18
## Instructions
20
19
21
20
1.**Create the fixture directory.**
22
-
```bash
23
-
mkdir tests/events/deployment
24
-
```
25
21
Use the GitHub event name as the directory name (e.g. `deployment`, `workflow_dispatch`). For action variants, append `_{action}` (e.g. `pull_request_merged`, `issue_closed`). Verify no existing directory with that name exists under `tests/events/`.
Content is the bare event type only — no action suffix, no newline required (the test trims it). Matches the value GitHub sends in the `X-GitHub-Event` HTTP header.
25
+
Write `deployment` to `tests/events/deployment/type.txt`.
32
26
33
27
3.**Write the payload file.**
34
-
Save a real GitHub webhook payload to `tests/events/deployment/payload.json`. Mirror the formatting of existing fixtures — tabs for indentation, escaped forward-slashes (`\/`), `JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES` style:
28
+
Save a real GitHub webhook payload to `tests/events/deployment/payload.json`. Mirror the formatting of existing fixtures — tabs for indentation, `JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES` style:
35
29
```json
36
30
{
37
31
"action": "created",
@@ -55,24 +49,17 @@ description: Creates a new test event fixture directory under tests/events/{even
55
49
```
56
50
Must print `0`.
57
51
58
-
4.**Generate the binary and Discord files using the test harness.**
59
-
In `tests/EventTest.php`, uncomment the two generation lines (lines 27 and 38):
4.**Generate `expected_text.txt` using the test suite.**
53
+
Run the tests — the new fixture will fail and print the actual output. Use that output as the content of `expected_text.txt`, then re-run to confirm it passes:
This writes the real IRC-formatted output (with color codes) to `tests/events/deployment/expected.bin` and the Discord embed to `tests/events/deployment/discord.json`. **Re-comment both lines immediately after**; leaving them uncommented will overwrite all fixtures on every test run.
All tests must pass. If the new fixture is listed as a failure, inspect the generated `tests/events/deployment/expected.bin` content and compare against `web/github.php`'s handler for that event type.
62
+
All tests must pass.
76
63
77
64
## Examples
78
65
@@ -82,19 +69,14 @@ description: Creates a new test event fixture directory under tests/events/{even
3. Write `tests/events/deployment/payload.json` with a real GitHub deployment payload
85
-
4.Uncomment lines 27 & 38 in `tests/EventTest.php`, run `vendor/bin/phpunit tests/EventTest.php`, re-comment
86
-
5.Verify `tests/events/deployment/expected.bin` and `tests/events/deployment/discord.json` were written and tests pass
72
+
4.Run `vendor/bin/phpunit tests/GithubMessageBuilderTest.php`, capture actual output, write to `tests/events/deployment/expected_text.txt`
73
+
5.Re-run tests to verify they pass
87
74
88
-
**Result:**`tests/events/deployment/` contains all four files; `vendor/bin/phpunit tests/EventTest.php` exits green.
75
+
**Result:**`tests/events/deployment/` contains all three files; `vendor/bin/phpunit tests/GithubMessageBuilderTest.php` exits green.
89
76
90
77
## Common Issues
91
78
92
-
-**`file_get_contents(...): Failed to open stream`** — one of the four required files is missing. Check `tests/events/deployment/` contains `tests/events/deployment/type.txt`, `tests/events/deployment/payload.json`, `tests/events/deployment/expected.bin`, `tests/events/deployment/discord.json`.
93
-
-**`assertEquals failed: expected '' got '[10GitHub-WebHook]...'`** — `tests/events/deployment/expected.bin` is empty or was hand-written without IRC codes. Re-run Step 4 generation.
94
-
-**`json_decode` returns null for `discord.json`** — `tests/events/deployment/discord.json` was hand-written with invalid JSON. Re-run Step 4 or validate:
-**New fixture not picked up by test runner** — confirm the directory is directly under `tests/events/` (not nested). `EventTest.php:51` uses a single-level `DirectoryIterator`.
79
+
-**`file_get_contents(...): Failed to open stream`** — one of the three required files is missing. Check `tests/events/deployment/` contains `type.txt`, `payload.json`, `expected_text.txt`.
80
+
-**`assertEquals failed`** — `expected_text.txt` content doesn't match actual output. Re-run the test, capture actual output, update the file.
81
+
-**New fixture not picked up by test runner** — confirm the directory is directly under `tests/events/` (not nested). The test uses a single-level `DirectoryIterator`.
100
82
-**`GetEventType()` assertion fails** — `tests/events/deployment/type.txt` contains extra whitespace or wrong casing. The value must exactly match the GitHub `X-GitHub-Event` header (all lowercase, underscores, e.g. `pull_request` not `Pull-Request`).
Accumulated patterns and anti-patterns from development sessions.
4
+
Auto-managed by [caliber](https://github.com/caliber-ai-org/ai-setup) — do not edit manually.
5
+
6
+
-**[gotcha:project]** The existing test files (`tests/EventTest.php`, `tests/IgnoredActionsThrowTest.php`, `tests/UnknownActionTest.php`, `tests/IgnoredEventTest.php`) all reference `IrcConverter` and `DiscordConverter` classes that no longer exist in `src/` — running `vendor/bin/phpunit` produces 61 errors about missing classes. These tests are stale and need to be rewritten against `GithubWebhook` directly.
7
+
-**[fix:project]**`vendor/bin/phpunit` fails with "No such file or directory" if `vendor/` is not present — always run `composer install` first. The vendor directory is gitignored and absent after a fresh clone.
8
+
-**[gotcha:project]**`composer.json` has no `autoload`, `autoload-dev`, or `scripts` sections — there is no PSR-4 autoloader and no `composer test` shortcut. Classes (`GithubWebhook`, `IgnoredEventException`, etc.) are loaded via manual `require` statements. Tests must bootstrap these manually or via a PHPUnit bootstrap file.
9
+
-**[pattern:project]** Real GitHub webhook payloads live in `log/` as JSON files with structure `{"repo": "...", "event": "...", "data": {...payload...}}`. The `data` key holds the raw webhook payload — use these as authoritative source material when creating new fixtures under `tests/events/`.
10
+
-**[gotcha:project]** In the `push` event handler, `$Msg['alias']` is set from `$Message['head_commit']['author']['name']` (commit author name), **not**`$Message['pusher']['name']`. These differ when CI or bots push commits authored by a human. Code that compares commit authors against the pusher must use `$Msg['alias']`, not `$Message['pusher']['name']`.
0 commit comments