Skip to content

fix: Handle empty API keys with no-op client#135

Merged
marandaneto merged 7 commits into
mainfrom
fix/noop-empty-api-key
May 28, 2026
Merged

fix: Handle empty API keys with no-op client#135
marandaneto merged 7 commits into
mainfrom
fix/noop-empty-api-key

Conversation

@marandaneto
Copy link
Copy Markdown
Member

Summary

  • initialize PostHog with a disabled no-op consumer when the API key is missing, null, empty, or trim-empty
  • avoid sending capture/flag requests with an empty api_key
  • add focused coverage for PostHog::init() and direct Client construction

Tests

  • ./vendor/bin/phpunit --no-coverage --filter 'testInitWithoutApiKeyConfiguresNoOpClient|testInitWithEmptyApiKeyConfiguresNoOpClient|testInitWithWhitespaceApiKeyConfiguresNoOpClient|testClientWithNullApiKeyDoesNotSendRequests|testClientWithTrimEmptyApiKeyDoesNotSendRequests' test/PostHogTest.php\n- ./vendor/bin/phpunit --no-coverage (completed with existing warnings/deprecations)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label May 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

@marandaneto marandaneto changed the title Handle empty API keys with no-op client fix: Handle empty API keys with no-op client May 28, 2026
@marandaneto marandaneto marked this pull request as ready for review May 28, 2026 10:23
@marandaneto marandaneto requested a review from a team as a code owner May 28, 2026 10:23
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 28, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
test/PostHogTest.php:247-265
**Prefer parameterised tests for identical cases**

`testInitWithEmptyApiKeyConfiguresNoOpClient` and `testInitWithWhitespaceApiKeyConfiguresNoOpClient` are identical in structure — both call `PostHog::init($apiKey, ["debug" => true])`, assert the `NoOp` consumer, and assert `capture` returns `false`. The only difference is the input value. PHPUnit's `@dataProvider` annotation would express this as a single test with two data sets, removing the duplication and making it trivially easy to add new variants. The same applies to `testClientWithNullApiKeyDoesNotSendRequests` / `testClientWithTrimEmptyApiKeyDoesNotSendRequests`, which share the same three-step assertion pattern.

Reviews (1): Last reviewed commit: "fix: report disabled no-op calls as fals..." | Re-trigger Greptile

Comment thread test/PostHogTest.php Outdated
Copy link
Copy Markdown

@ioannisj ioannisj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, left a couple of comments that make sense to me

Comment thread lib/PostHog.php
Comment thread lib/PostHog.php
Comment thread lib/Client.php
Comment thread lib/Client.php Outdated
@marandaneto marandaneto merged commit 806dd0b into main May 28, 2026
15 checks passed
@marandaneto marandaneto deleted the fix/noop-empty-api-key branch May 28, 2026 14:14
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.

2 participants