-
Notifications
You must be signed in to change notification settings - Fork 1
Testing
Run the full test suite from the repository root:
# All tests
composer test
# Unit tests only
composer test:unit
# Cross-SDK parity tests
composer test:cross-sdk
# Integration tests
composer test:integration
# Coverage report (requires PCOV)
composer test:coverage
# Coverage for CI (clover XML + text summary)
composer test:coverage:ciThe three suites map to directories in phpunit.xml: unit → packages/*/tests, cross-sdk → tests/CrossSdk, integration → tests/Integration.
tests/CrossSdk pins this SDK to the shared cross-SDK contract. Each test consumes a JSON fixture copied byte-identical from the JavaScript SDK reference and asserts against the fixture's expected values — the tests never recompute them, so a failure means this SDK has diverged, not that the fixture is stale.
| Test | Fixture | What it pins |
|---|---|---|
HashParityTest |
test-vectors.json |
MurmurHash3 output and the hash-to-bucket-value scaling |
BucketingConsistencyTest |
test-vectors.json |
Deterministic visitor → variation assignment |
AnchoredBucketingGoldenVectorTest |
cross-sdk-bucketing-vectors.json |
Both bucketing layouts through the real DataManager fresh-bucketing path — packed (experience version <= 11) and anchored (version > 11, contract v12) |
RuleParityTest |
rule-test-vectors.json |
Comparison operators and rule-tree evaluation, including the SegmentsKeys wire values |
When you change bucketing, hashing, or comparison logic, do not edit these fixtures to make a test pass — the fixture is the contract, and editing it here would silently break parity with the JavaScript SDK reference it was copied from.
# PHPStan (level 6)
composer analyze
# PHP-CS-Fixer (PSR-12)
composer cs-check
# Fix code style
composer cs-fixThe integration test suite supports three auth modes, each running the full test suite:
- static — uses a bundled JSON config file (no network calls)
-
live — fetches config from the staging CDN using
sdkKeyonly (requiresCONVERT_STAGING_SDK_KEY) -
live-secret — fetches config using
sdkKey+sdkKeySecretBearer auth (requiresCONVERT_STAGING_SDK_KEY2andCONVERT_STAGING_SDK_KEY2_SECRET)
When the required env vars for a live mode are absent, those tests are skipped automatically — unit and static-mode tests still run normally.
PHP's getenv() reads OS-level environment variables only (not .env files). You must export the variables in your shell before running the tests:
export CONVERT_STAGING_SDK_KEY=xxx CONVERT_STAGING_SDK_KEY2=yyy CONVERT_STAGING_SDK_KEY2_SECRET=zzz && composer test:integrationOr set and run in one line without persisting:
CONVERT_STAGING_SDK_KEY=xxx CONVERT_STAGING_SDK_KEY2=yyy CONVERT_STAGING_SDK_KEY2_SECRET=zzz composer test:integrationNote: Because
getenv()only reads OS-level environment variables, libraries likevlucas/phpdotenvthat populate$_ENVor$_SERVERwill not make these values visible to the SDK. Always useexportor inline assignment as shown above.
| Variable | Used By | Default | Description |
|---|---|---|---|
CONVERT_STAGING_SDK_KEY |
Integration tests | (none — live tests skipped when absent) | SDK key for the Convert staging project. Enables live mode integration tests that fetch real config and post real tracking events. |
CONVERT_STAGING_SDK_KEY2 |
Integration tests | (none — live-secret tests skipped when absent) | SDK key for the live-secret auth mode. Used with sdkKeySecret to test Bearer-authenticated config fetching. |
CONVERT_STAGING_SDK_KEY2_SECRET |
Integration tests | (none — live-secret tests skipped when absent) | SDK key secret for the live-secret auth mode. Sent as a Bearer token in the Authorization header. |
CONFIG_ENDPOINT |
SDK runtime | https://cdn-4.convertexperiments.com/api/v1 |
Override the CDN endpoint used to fetch project configuration. Useful for pointing at a staging or local server. |
TRACK_ENDPOINT |
SDK runtime | https://[project_id].metrics.convertexperiments.com/v1 |
Override the Tracking API endpoint used to post events. [project_id] is replaced at runtime with the actual project ID. |
VERSION |
SDK runtime | php-sdk |
Override the source identifier sent with tracking requests (the network.source field). |
Copyrights © 2026 All Rights Reserved by Convert Insights, Inc.
Getting Started
PHP SDK
- Quickstart
- Installation
- Initialization
- Configuration
- Return Types & DTOs
- Code Examples
- Segments Manager
Core Concepts
- Experiences & Variations
- Feature Flags
- Bucketing Algorithm
- Rule Evaluation
- Segments
- Data Management
- Event System
- API Communication
How-To Guides
- Running Experiences
- Running Features
- Tracking Conversions
- Visitor Context
- Persistent DataStore
- Troubleshooting
- Direct Tracking Endpoint
- Server-Side Experimentation
- From Tracking Script to SDK
- QA & Preview
- Mutually Exclusive Experiments
- Split URL Tests
Contributing