Skip to content

fix: empty People props guard and chore: upgrade PHPUnit version - #88

Draft
santigracia wants to merge 2 commits into
mixpanel:masterfrom
santigracia:fix/issue-55-empty-props-guard
Draft

fix: empty People props guard and chore: upgrade PHPUnit version#88
santigracia wants to merge 2 commits into
mixpanel:masterfrom
santigracia:fix/issue-55-empty-props-guard

Conversation

@santigracia

Copy link
Copy Markdown
Collaborator

Summary

Test plan

  • ./vendor/bin/phpunit: 50 tests passing on PHP 8.4
  • Verified people->set($id, []) leaves the queue empty
  • Verified valid people->set() calls still enqueue as expected

Fixes mixpanel#55. Prevents invalid API calls and repeated flush retries on destruct.
Fixes mixpanel#72. Migrates test suite to modern PHPUnit APIs and fixes stale test assertions.
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Confidence Score: 4/5

Safe to merge; the core logic change is small and well-tested, and the PHPUnit migration is mechanical.

The empty-props guard solves a real problem cleanly, and the test suite modernisation is thorough. The one gap is that append() with an empty array value still enqueues a payload, leaving the same class of issue open for that method.

lib/Producers/MixpanelPeople.php — the append() method was not given the same empty-value guard as the other mutating methods.

Important Files Changed

Filename Overview
lib/Producers/MixpanelPeople.php Added empty-props guard to set(), setOnce(), and remove(); append() with an empty array value is not guarded.
test/Producers/MixpanelPeopleProducerTest.php Added three new tests covering the empty-props guard; migrated to PHPUnit 10 class names and method signatures.
test/Producers/MixpanelEventsProducerTest.php Fixed previously-dead unregister/unregisterAll tests by adding test prefix; removed stale prop11 assertions; replaced deprecated assertFileNotExists.
test/Producers/MixpanelGroupsProducerTest.php Corrected testRemove to assert $remove instead of $unset, matching the actual Groups producer implementation.
test/ConsumerStrategies/CurlConsumerTest.php Replaced CURLE_COULDNT_RESOLVE_HOST equality check with assertNotSame(-1, ...) — weaker assertion that only verifies the error callback fired, not the specific curl error code.
composer.json PHPUnit bumped from 5.6.* to ^10.5; phpdocumentor removed from dev dependencies.
phpunit.xml.dist Updated to PHPUnit 10 schema, removed deprecated attributes, added source/include block for coverage.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["people->set / setOnce / remove"] --> B{empty props?}
    B -->|yes| C[return — no enqueue]
    B -->|no| D[_constructPayload]
    D --> E[enqueue to queue]
    E --> F{flush trigger}
    F -->|manual flush / destruct| G[HTTP POST to Mixpanel API]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["people->set / setOnce / remove"] --> B{empty props?}
    B -->|yes| C[return — no enqueue]
    B -->|no| D[_constructPayload]
    D --> E[enqueue to queue]
    E --> F{flush trigger}
    F -->|manual flush / destruct| G[HTTP POST to Mixpanel API]
Loading

Comments Outside Diff (1)

  1. lib/Producers/MixpanelPeople.php, line 109-113 (link)

    P2 append() not guarded against empty value

    set(), setOnce(), and remove() all gained empty-props guards, but append($distinct_id, 'list', []) still enqueues a payload with '$union' => ['list' => []] to the API. The issue described in MixpanelPeople::set causes 10 calls if array of properties is empty. #55 (flush retries on destruct) can be triggered the same way via append with an empty array.

Reviews (1): Last reviewed commit: "Upgrade PHPUnit to 10.5 for PHP 8.1+ com..." | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses two related maintenance/runtime concerns in the Mixpanel PHP SDK: it prevents invalid “People” profile update calls when no properties are provided (avoiding repeated flush retries on destruct), and modernizes the test suite to run on PHP 8.1+ by upgrading to PHPUnit 10.5.

Changes:

  • Add an early-return guard in Producers_MixpanelPeople::{set,setOnce,remove} to skip enqueueing when the props array is empty.
  • Upgrade PHPUnit configuration and update tests for PHPUnit 10 (base TestCase, lifecycle method signatures, updated assertions).
  • Make a couple of tests deterministic/offline by explicitly using the file consumer where network calls could otherwise occur.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/Producers/MixpanelPeople.php Skips enqueueing People updates when $props is empty to avoid invalid API calls and repeated retry flushes.
test/Producers/MixpanelPeopleProducerTest.php Adds coverage to ensure empty-props People operations do not enqueue; updates for PHPUnit 10.
test/Producers/MixpanelGroupsProducerTest.php Updates PHPUnit 10 base class/signatures; aligns remove assertion with $remove payload key.
test/Producers/MixpanelEventsProducerTest.php Updates test method names and PHPUnit 10 assertions; makes createAlias test avoid network by using file consumer.
test/MixpanelTest.php Updates PHPUnit 10 base class and lifecycle method signatures.
test/ConsumerStrategies/SocketConsumerTest.php Updates PHPUnit 10 base class/signatures; marks empty test as not performing assertions.
test/ConsumerStrategies/FileConsumerTest.php Updates PHPUnit 10 base class and lifecycle method signatures.
test/ConsumerStrategies/CurlConsumerTest.php Updates PHPUnit 10 base class/assertions; reduces flakiness by not hardcoding a specific curl error constant.
test/ConsumerStrategies/AbstractConsumerTest.php Updates PHPUnit 10 base class and lifecycle method signatures.
test/Base/MixpanelBaseProducerTest.php Updates PHPUnit 10 base class/signatures; uses file consumer in a test path that could otherwise hit the network.
phpunit.xml.dist Migrates config to PHPUnit 10.5 schema and modern <source> include/exclude configuration.
composer.json Upgrades dev dependency to phpunit/phpunit: ^10.5.
.gitignore Ignores PHPUnit cache directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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