VOOZH about

URL: https://deepwiki.com/rudderlabs/rudder-php-sdk/5-testing

⇱ Testing | rudderlabs/rudder-php-sdk | DeepWiki


Loading...
Menu

Testing

The RudderStack PHP SDK utilizes a comprehensive testing suite to ensure the reliability of its event tracking pipeline across various transport mechanisms. The testing strategy combines unit tests for core logic, integration tests for consumer implementations, and automated CI/CD workflows to maintain code quality and security.

Test Infrastructure

The SDK uses PHPUnit as its primary testing framework, configured via phpunit.xml phpunit.xml1-41 The test suite is designed to cover both the high-level Client interface and the specific behaviors of different Consumer types.

Key Testing Components

ComponentDescription
PHPUnitOrchestrates test execution and generates coverage reports in Clover/JUnit formats phpunit.xml26-39
MockWebServerUsed to intercept HTTP requests and simulate data plane responses without hitting live endpoints.
DotenvLoads environment variables (like WRITE_KEY) from a .env file for localized test configurations test/ConsumerSocketTest.php17-23
pcovEmployed in CI to generate high-performance code coverage metrics .github/workflows/test.yml32

Testing Logic Flow

The following diagram illustrates how tests interact with the SDK components and external mocks:

SDK Test Execution Flow


Sources: phpunit.xml1-41 test/ConsumerSocketTest.php17-33 .github/workflows/test.yml61-64


Test Suite Structure

The test/ directory contains specialized test classes for each major component of the SDK. Each consumer (Socket, LibCurl, ForkCurl, File) has a dedicated test file to validate its unique transport logic, such as error handling, timeouts, and payload compression.

Major Test Entities


For a detailed breakdown of test cases, environment setup, and mock configurations, see Test Suite Structure.

Sources: test/ConsumerSocketTest.php13-15 phpunit.xml30-34 phpcs.xml5-6


CI/CD Pipeline

The SDK leverages GitHub Actions to automate quality assurance. The primary pipeline, defined in test.yml, executes on every push and pull request to master or develop branches .github/workflows/test.yml3-9

Pipeline Stages

  1. Environment Setup: Configures PHP 8.2 with pcov and composer .github/workflows/test.yml27-33
  2. Linting: Enforces PSR-12 standards using phpcs .github/workflows/test.yml49-52
  3. Security: Hardens the runner and audits outbound calls .github/workflows/test.yml17-21
  4. Unit Testing: Runs the full PHPUnit suite with secret-backed environment variables .github/workflows/test.yml53-64
  5. Analysis: Integrates with SonarCloud for static analysis and code quality tracking .github/workflows/test.yml76-81

For details on workflow triggers, secret management, and automated release notifications, see CI/CD Pipeline.

Sources: .github/workflows/test.yml1-81 phpcs.xml1-38