# wpvr/9.1.3/vendor/linno/telemetry/tests/Drivers/PostHogDriverTest.php

WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress, version 9.1.3. 116 lines.

- Page: https://pluginprobe.com/plugins/wpvr/9.1.3/code/vendor/linno/telemetry/tests/Drivers/PostHogDriverTest.php
- Raw: https://pluginprobe.com/plugins/wpvr/9.1.3/raw/vendor/linno/telemetry/tests/Drivers/PostHogDriverTest.php
- Modified: 2026-04-02T11:52:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpvr/9.1.3/code/vendor/linno/telemetry/tests/Drivers/PostHogDriverTest.php#L10-L20`.

```php
<?php

namespace LinnoSDK\Telemetry\Tests\Drivers;

use LinnoSDK\Telemetry\Drivers\PostHogDriver;
use Mockery;
use PostHog\PostHog;
use PHPUnit\Framework\TestCase;

class PostHogDriverTest extends TestCase
{
    protected function tearDown(): void
    {
        Mockery::close();
    }

    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testSendReturnsTrueOnSuccess()
    {
        $driver = new PostHogDriver('host');
        $driver->setApiKey('key');

        Mockery::mock('alias:' . PostHog::class)
            ->shouldReceive('init')->once()
            ->shouldReceive('capture')->once()
            ->shouldReceive('flush')->once();

        $this->assertTrue($driver->send('event', []));
    }

    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testSendReturnsFalseOnFailure()
    {
        $driver = new PostHogDriver('host');
        $driver->setApiKey('key');

        Mockery::mock('alias:' . PostHog::class)
            ->shouldReceive('init')->once()->andThrow(new \Exception('error'));

        $this->assertFalse($driver->send('event', []));
    }

    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testGetLastErrorReturnsErrorMessage()
    {
        $driver = new PostHogDriver('host');
        $driver->setApiKey('key');

        Mockery::mock('alias:' . PostHog::class)
            ->shouldReceive('init')->once()->andThrow(new \Exception('error message'));

        $driver->send('event', []);

        $this->assertEquals('error message', $driver->getLastError());
    }

    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testSendWithMalformedHostUrl()
    {
        $driver = new PostHogDriver('malformed-url');
        $driver->setApiKey('key');

        Mockery::mock('alias:' . PostHog::class)
            ->shouldReceive('init')->once()->andThrow(new \Exception('cURL error'));

        $this->assertFalse($driver->send('event', []));
        $this->assertStringContainsString('cURL error', $driver->getLastError());
    }

    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testSendWithLargePayload()
    {
        $driver = new PostHogDriver('host');
        $driver->setApiKey('key');

        Mockery::mock('alias:' . PostHog::class)
            ->shouldReceive('init')->once()
            ->shouldReceive('capture')->once()
            ->shouldReceive('flush')->once();

        $largePayload = array_fill(0, 1000, 'a');
        $this->assertTrue($driver->send('event', ['large_payload' => $largePayload]));
    }

    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testSendWithNonJsonErrorResponse()
    {
        $driver = new PostHogDriver('host');
        $driver->setApiKey('key');

        Mockery::mock('alias:' . PostHog::class)
            ->shouldReceive('init')->once()->andThrow(new \Exception('not a json response'));

        $this->assertFalse($driver->send('event', []));
        $this->assertEquals('not a json response', $driver->getLastError());
    }
}

```
