Skip to content

Commit c5caac2

Browse files
authored
Improve E2E tests for the Performance Monitoring feature (#517)
1 parent bcc8794 commit c5caac2

14 files changed

+217
-7
lines changed

.github/workflows/tests.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ jobs:
2323
- '7.3'
2424
- '7.2'
2525
sentry_constraint: [false]
26+
dbal_constraint: [false]
2627
symfony_constraint: ['']
2728
experimental: [false]
2829
include:
2930
# - description: 'sentry/sentry dev-develop'
3031
# php: '7.4'
3132
# sentry_constraint: 'dev-develop'
3233
# experimental: true
34+
- description: 'DBAL 2'
35+
php: '7.4'
36+
dbal_constraint: '^2.13'
3337
- description: 'Symfony 4.4'
3438
php: '7.3'
3539
symfony_constraint: 4.4.*
@@ -41,6 +45,7 @@ jobs:
4145
- description: 'prefer lowest'
4246
php: '7.2'
4347
composer_option: '--prefer-lowest'
48+
symfony_constraint: ^3.4.44
4449
env:
4550
SYMFONY_DEPRECATIONS_HELPER: disabled
4651

@@ -61,6 +66,8 @@ jobs:
6166
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex
6267
- run: composer remove --dev symfony/messenger --no-update
6368
if: matrix.symfony_constraint == '3.4.*' || matrix.composer_option == '--prefer-lowest'
69+
- run: composer require --dev doctrine/dbal ${{ matrix.dbal_constraint }} --no-update
70+
if: matrix.dbal_constraint
6471
- run: composer update --no-progress --ansi ${{ matrix.composer_option }}
6572
- run: composer require sentry/sentry dev-develop
6673
if: matrix.sentry_constraint == 'dev-develop'

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ parameters:
115115
count: 1
116116
path: src/aliases.php
117117

118-
-
119-
message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#"
120-
count: 1
121-
path: tests/End2End/End2EndTest.php
122-
123118
-
124119
message: "#^Call to method getException\\(\\) on an unknown class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent\\.$#"
125120
count: 1

tests/Command/SentryTestCommandTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717

1818
class SentryTestCommandTest extends BaseTestCase
1919
{
20+
protected function tearDown(): void
21+
{
22+
parent::tearDown();
23+
24+
// reset current Hub to avoid leaking the mock outside of this tests
25+
SentrySdk::init();
26+
}
27+
2028
public function testExecuteSuccessfully(): void
2129
{
2230
$options = new Options(['dsn' => 'http://public:[email protected]/sentry/1']);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Tests\End2End\App\Controller;
6+
7+
use Doctrine\DBAL\Connection;
8+
use Sentry\State\HubInterface;
9+
use Sentry\Tracing\SpanContext;
10+
use Symfony\Component\HttpFoundation\Response;
11+
12+
class TracingController
13+
{
14+
/**
15+
* @var HubInterface
16+
*/
17+
private $hub;
18+
19+
/**
20+
* @var Connection|null
21+
*/
22+
private $connection;
23+
24+
public function __construct(HubInterface $hub, Connection $connection = null)
25+
{
26+
$this->hub = $hub;
27+
$this->connection = $connection;
28+
}
29+
30+
public function pingDatabase(): Response
31+
{
32+
$this->hub->setSpan(
33+
$this->hub->getSpan()
34+
->startChild($this->createSpan())
35+
);
36+
37+
if ($this->connection) {
38+
$this->connection->executeQuery('SELECT 1');
39+
}
40+
41+
return new Response('Success');
42+
}
43+
44+
private function createSpan(): SpanContext
45+
{
46+
$spanContext = new SpanContext();
47+
$spanContext->setOp('mock.span');
48+
$spanContext->setDescription('mocked subspan');
49+
50+
return $spanContext;
51+
}
52+
}

tests/End2End/App/Kernel.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Sentry\SentryBundle\Tests\End2End\App;
66

7+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
78
use Symfony\Component\Config\Loader\LoaderInterface;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
910
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
@@ -12,25 +13,44 @@
1213

1314
class Kernel extends SymfonyKernel
1415
{
16+
/**
17+
* @var string
18+
*/
19+
private static $cacheDir = null;
20+
1521
/**
1622
* @return BundleInterface[]
1723
*/
1824
public function registerBundles(): array
1925
{
20-
return [
26+
$bundles = [
2127
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
2228
new \Symfony\Bundle\MonologBundle\MonologBundle(),
2329
new \Sentry\SentryBundle\SentryBundle(),
2430
];
31+
32+
if (class_exists(DoctrineBundle::class)) {
33+
$bundles[] = new DoctrineBundle();
34+
}
35+
36+
return $bundles;
2537
}
2638

2739
public function registerContainerConfiguration(LoaderInterface $loader): void
2840
{
2941
$loader->load(__DIR__ . '/config.yml');
3042

43+
if (self::VERSION_ID >= 50000) {
44+
$loader->load(__DIR__ . '/deprecations_for_5.yml');
45+
}
46+
3147
if (interface_exists(MessageBusInterface::class) && self::VERSION_ID >= 40300) {
3248
$loader->load(__DIR__ . '/messenger.yml');
3349
}
50+
51+
if (class_exists(DoctrineBundle::class)) {
52+
$loader->load(__DIR__ . '/doctrine.yml');
53+
}
3454
}
3555

3656
protected function build(ContainerBuilder $container): void
@@ -39,4 +59,13 @@ protected function build(ContainerBuilder $container): void
3959

4060
parent::build($container);
4161
}
62+
63+
public function getCacheDir(): string
64+
{
65+
if (null === self::$cacheDir) {
66+
self::$cacheDir = sys_get_temp_dir() . \DIRECTORY_SEPARATOR . uniqid('sentry-symfony-');
67+
}
68+
69+
return self::$cacheDir;
70+
}
4271
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Tests\End2End\App;
6+
7+
use Symfony\Component\Config\Loader\LoaderInterface;
8+
9+
class KernelWithTracing extends Kernel
10+
{
11+
public function registerContainerConfiguration(LoaderInterface $loader): void
12+
{
13+
parent::registerContainerConfiguration($loader);
14+
15+
$loader->load(__DIR__ . '/tracing.yml');
16+
}
17+
}

tests/End2End/App/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
sentry:
2+
tracing:
3+
enabled: true
24
options:
35
capture_silenced_errors: true
46
error_types: E_ALL & ~E_USER_DEPRECATED
7+
traces_sample_rate: 0
58

69
framework:
710
router: { resource: "%routing_config_dir%/routing.yml" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
router:
3+
utf8: true

tests/End2End/App/doctrine.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
doctrine:
2+
dbal:
3+
url: 'sqlite:///%kernel.cache_dir%/data.db'

tests/End2End/App/routing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ dispatch:
2929
dispatch_unrecoverable:
3030
path: /dispatch-unrecoverable-message
3131
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\MessengerController::dispatchUnrecoverableMessage' }
32+
33+
tracing_ping_database:
34+
path: /tracing/ping-database
35+
defaults: { _controller: 'Sentry\SentryBundle\Tests\End2End\App\Controller\TracingController::pingDatabase' }

0 commit comments

Comments
 (0)