PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.72
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.72
9.1.3 9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 All 222 releases
wpvr / vendor / linno / telemetry / tests / Drivers / PostHogDriverTest.php

PostHogDriverTest.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.72, at vendor/linno/telemetry/tests/Drivers/PostHogDriverTest.php

116 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LinnoSDK\Telemetry\Tests\Drivers;
4
5 use LinnoSDK\Telemetry\Drivers\PostHogDriver;
6 use Mockery;
7 use PostHog\PostHog;
8 use PHPUnit\Framework\TestCase;
9
10 class PostHogDriverTest extends TestCase
11 {
12 protected function tearDown(): void
13 {
14 Mockery::close();
15 }
16
17 /**
18 * @runInSeparateProcess
19 * @preserveGlobalState disabled
20 */
21 public function testSendReturnsTrueOnSuccess()
22 {
23 $driver = new PostHogDriver('host');
24 $driver->setApiKey('key');
25
26 Mockery::mock('alias:' . PostHog::class)
27 ->shouldReceive('init')->once()
28 ->shouldReceive('capture')->once()
29 ->shouldReceive('flush')->once();
30
31 $this->assertTrue($driver->send('event', []));
32 }
33
34 /**
35 * @runInSeparateProcess
36 * @preserveGlobalState disabled
37 */
38 public function testSendReturnsFalseOnFailure()
39 {
40 $driver = new PostHogDriver('host');
41 $driver->setApiKey('key');
42
43 Mockery::mock('alias:' . PostHog::class)
44 ->shouldReceive('init')->once()->andThrow(new \Exception('error'));
45
46 $this->assertFalse($driver->send('event', []));
47 }
48
49 /**
50 * @runInSeparateProcess
51 * @preserveGlobalState disabled
52 */
53 public function testGetLastErrorReturnsErrorMessage()
54 {
55 $driver = new PostHogDriver('host');
56 $driver->setApiKey('key');
57
58 Mockery::mock('alias:' . PostHog::class)
59 ->shouldReceive('init')->once()->andThrow(new \Exception('error message'));
60
61 $driver->send('event', []);
62
63 $this->assertEquals('error message', $driver->getLastError());
64 }
65
66 /**
67 * @runInSeparateProcess
68 * @preserveGlobalState disabled
69 */
70 public function testSendWithMalformedHostUrl()
71 {
72 $driver = new PostHogDriver('malformed-url');
73 $driver->setApiKey('key');
74
75 Mockery::mock('alias:' . PostHog::class)
76 ->shouldReceive('init')->once()->andThrow(new \Exception('cURL error'));
77
78 $this->assertFalse($driver->send('event', []));
79 $this->assertStringContainsString('cURL error', $driver->getLastError());
80 }
81
82 /**
83 * @runInSeparateProcess
84 * @preserveGlobalState disabled
85 */
86 public function testSendWithLargePayload()
87 {
88 $driver = new PostHogDriver('host');
89 $driver->setApiKey('key');
90
91 Mockery::mock('alias:' . PostHog::class)
92 ->shouldReceive('init')->once()
93 ->shouldReceive('capture')->once()
94 ->shouldReceive('flush')->once();
95
96 $largePayload = array_fill(0, 1000, 'a');
97 $this->assertTrue($driver->send('event', ['large_payload' => $largePayload]));
98 }
99
100 /**
101 * @runInSeparateProcess
102 * @preserveGlobalState disabled
103 */
104 public function testSendWithNonJsonErrorResponse()
105 {
106 $driver = new PostHogDriver('host');
107 $driver->setApiKey('key');
108
109 Mockery::mock('alias:' . PostHog::class)
110 ->shouldReceive('init')->once()->andThrow(new \Exception('not a json response'));
111
112 $this->assertFalse($driver->send('event', []));
113 $this->assertEquals('not a json response', $driver->getLastError());
114 }
115 }
116