-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathTracingEnd2EndTest.php
70 lines (52 loc) · 2.14 KB
/
TracingEnd2EndTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace Sentry\SentryBundle\Tests\End2End;
use Sentry\SentryBundle\Tests\End2End\App\KernelWithTracing;
use Sentry\State\HubInterface;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
if (!class_exists(KernelBrowser::class)) {
class_alias(Client::class, KernelBrowser::class);
}
class TracingEnd2EndTest extends WebTestCase
{
public const SENT_EVENTS_LOG = '/tmp/sentry_e2e_test_sent_events.log';
protected static function getKernelClass(): string
{
return KernelWithTracing::class;
}
protected function setUp(): void
{
parent::setUp();
file_put_contents(self::SENT_EVENTS_LOG, '');
}
public function testTracingWithDoctrineConnectionPing(): void
{
$client = static::createClient(['debug' => false]);
$client->request('GET', '/tracing/ping-database');
$response = $client->getResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertSame(200, $response->getStatusCode());
$this->assertLastEventIdIsNotNull($client);
$this->assertTracingEventCount(1);
}
private function assertLastEventIdIsNotNull(KernelBrowser $client): void
{
$container = $client->getContainer();
$this->assertNotNull($container);
$hub = $container->get('test.hub');
$this->assertInstanceOf(HubInterface::class, $hub);
$this->assertNotNull($hub->getLastEventId(), 'Last error not captured');
}
private function assertTracingEventCount(int $expectedCount): void
{
$events = file_get_contents(self::SENT_EVENTS_LOG);
$this->assertNotFalse($events, 'Cannot read sent events log');
$listOfTracingEvents = array_filter(explode(StubTransportFactory::SEPARATOR, trim($events)), static function (string $elem) {
return str_contains('TRACING', $elem);
});
$this->assertCount($expectedCount, $listOfTracingEvents, 'Wrong number of tracing events sent: ' . \PHP_EOL . $events);
}
}