Skip to content

Commit 6a456ae

Browse files
committed
Removed tests for telemetry.
1 parent cdbba2d commit 6a456ae

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed

tests/TelemetryListenerTest.php

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<?php
2+
3+
namespace Rollbar\Laravel\Tests;
4+
5+
use Illuminate\Database\Connection;
6+
use Illuminate\Database\Events\QueryExecuted;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Log\Events\MessageLogged;
9+
use Illuminate\Routing\Events\RouteMatched;
10+
use Illuminate\Routing\Route;
11+
use Rollbar\Rollbar;
12+
use Rollbar\Telemetry\EventLevel;
13+
14+
class TelemetryListenerTest extends TestCase
15+
{
16+
protected function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
Rollbar::getTelemeter()?->clearQueue();
21+
}
22+
23+
public function testTelemetryDisabled(): void
24+
{
25+
$this->refreshApplicationWithConfig([
26+
'logging.channels.rollbar.telemetry' => false,
27+
]);
28+
29+
self::assertFalse($this->app['config']->get('logging.channels.rollbar.telemetry'));
30+
self::assertNull(Rollbar::getTelemeter());
31+
}
32+
33+
public function testTelemetryCapturesLaravelLogs(): void
34+
{
35+
$this->refreshApplicationWithConfig([
36+
'logging.channels.rollbar.telemetry.capture_logs' => true,
37+
]);
38+
39+
self::assertTrue($this->app['config']->get('logging.channels.rollbar.telemetry.capture_logs'));
40+
41+
$this->app['events']->dispatch(new MessageLogged(
42+
level: 'debug',
43+
message: 'telemetry test message',
44+
context: ['foo' => 'bar']
45+
));
46+
47+
$telemetryEvents = Rollbar::getTelemeter()->copyEvents();
48+
$lastItem = array_pop($telemetryEvents);
49+
50+
self::assertSame(EventLevel::Debug, $lastItem->level);
51+
self::assertSame('telemetry test message', $lastItem->body->message);
52+
self::assertSame(['foo' => 'bar'], $lastItem->body->extra);
53+
}
54+
55+
public function testTelemetryDoesNotCaptureLaravelLogsWhenDisabled(): void
56+
{
57+
$this->refreshApplicationWithConfig([
58+
'logging.channels.rollbar.telemetry.capture_logs' => false,
59+
]);
60+
61+
self::assertFalse($this->app['config']->get('logging.channels.rollbar.telemetry.capture_logs'));
62+
63+
$this->app['events']->dispatch(new MessageLogged(
64+
level: 'debug',
65+
message: 'telemetry test message',
66+
context: ['foo' => 'bar']
67+
));
68+
69+
self::assertEmpty(Rollbar::getTelemeter()->copyEvents());
70+
}
71+
72+
public function testTelemetryCapturesRouteMatched(): void
73+
{
74+
$this->refreshApplicationWithConfig([
75+
'logging.channels.rollbar.telemetry.capture_routing' => true,
76+
]);
77+
78+
self::assertTrue($this->app['config']->get('logging.channels.rollbar.telemetry.capture_routing'));
79+
80+
$this->app['events']->dispatch(new RouteMatched(
81+
route: new Route(
82+
methods: ['GET'],
83+
uri: 'test',
84+
action: (fn() => 'test')(...),
85+
),
86+
request: new Request(),
87+
));
88+
89+
$telemetryEvents = Rollbar::getTelemeter()->copyEvents();
90+
$lastItem = array_pop($telemetryEvents);
91+
92+
self::assertSame(EventLevel::Info, $lastItem->level);
93+
self::assertSame('Route matched', $lastItem->body->message);
94+
self::assertSame(['route' => 'test'], $lastItem->body->extra);
95+
}
96+
97+
public function testTelemetryDoesNotCaptureRouteMatchedWhenDisabled(): void
98+
{
99+
$this->refreshApplicationWithConfig([
100+
'logging.channels.rollbar.telemetry.capture_routing' => false,
101+
]);
102+
103+
self::assertFalse($this->app['config']->get('logging.channels.rollbar.telemetry.capture_routing'));
104+
105+
$this->app['events']->dispatch(new RouteMatched(
106+
route: new Route(
107+
methods: ['GET'],
108+
uri: 'test',
109+
action: (fn() => 'test')(...),
110+
),
111+
request: new Request(),
112+
));
113+
114+
self::assertEmpty(Rollbar::getTelemeter()->copyEvents());
115+
}
116+
117+
public function testTelemetryCapturesQueryExecuted(): void
118+
{
119+
$this->refreshApplicationWithConfig([
120+
'logging.channels.rollbar.telemetry.capture_db_queries' => true,
121+
'logging.channels.rollbar.telemetry.capture_db_query_parameters' => true,
122+
]);
123+
124+
self::assertTrue($this->app['config']->get('logging.channels.rollbar.telemetry.capture_db_queries'));
125+
self::assertTrue($this->app['config']->get('logging.channels.rollbar.telemetry.capture_db_query_parameters'));
126+
127+
$this->app['events']->dispatch(new QueryExecuted(
128+
sql: 'SELECT * FROM test WHERE id = ?',
129+
bindings: [1],
130+
time: 0.1,
131+
connection: new Connection(
132+
pdo: (fn() => 'test')(...),
133+
config: ['name' => 'connection_name'],
134+
),
135+
));
136+
137+
$telemetryEvents = Rollbar::getTelemeter()->copyEvents();
138+
$lastItem = array_pop($telemetryEvents);
139+
140+
self::assertSame(EventLevel::Info, $lastItem->level);
141+
self::assertSame('Query executed', $lastItem->body->message);
142+
self::assertSame([
143+
'query' => 'SELECT * FROM test WHERE id = ?',
144+
'time' => 0.1,
145+
'connection' => 'connection_name',
146+
'bindings' => [1],
147+
], $lastItem->body->extra);
148+
}
149+
150+
public function testTelemetryDoesNotCaptureQueryExecutedWhenDisabled(): void
151+
{
152+
$this->refreshApplicationWithConfig([
153+
'logging.channels.rollbar.telemetry.capture_db_queries' => false,
154+
]);
155+
156+
self::assertFalse($this->app['config']->get('logging.channels.rollbar.telemetry.capture_db_queries'));
157+
158+
$this->app['events']->dispatch(new QueryExecuted(
159+
sql: 'SELECT * FROM test WHERE id = ?',
160+
bindings: [1],
161+
time: 0.1,
162+
connection: new Connection(
163+
pdo: (fn() => 'test')(...),
164+
config: ['name' => 'connection_name'],
165+
),
166+
));
167+
168+
self::assertEmpty(Rollbar::getTelemeter()->copyEvents());
169+
}
170+
171+
public function testTelemetryDoesNotCaptureQueryParametersWhenDisabled(): void
172+
{
173+
$this->refreshApplicationWithConfig([
174+
'logging.channels.rollbar.telemetry.capture_db_queries' => true,
175+
'logging.channels.rollbar.telemetry.capture_db_query_parameters' => false,
176+
]);
177+
178+
self::assertTrue($this->app['config']->get('logging.channels.rollbar.telemetry.capture_db_queries'));
179+
self::assertFalse($this->app['config']->get('logging.channels.rollbar.telemetry.capture_db_query_parameters'));
180+
181+
$this->app['events']->dispatch(new QueryExecuted(
182+
sql: 'SELECT * FROM test WHERE id = ?',
183+
bindings: [1],
184+
time: 0.1,
185+
connection: new Connection(
186+
pdo: (fn() => 'test')(...),
187+
config: ['name' => 'connection_name'],
188+
),
189+
));
190+
191+
$telemetryEvents = Rollbar::getTelemeter()->copyEvents();
192+
$lastItem = array_pop($telemetryEvents);
193+
194+
self::assertSame(EventLevel::Info, $lastItem->level);
195+
self::assertSame('Query executed', $lastItem->body->message);
196+
self::assertSame([
197+
'query' => 'SELECT * FROM test WHERE id = ?',
198+
'time' => 0.1,
199+
'connection' => 'connection_name',
200+
], $lastItem->body->extra);
201+
}
202+
}

0 commit comments

Comments
 (0)