@@ -371,12 +371,10 @@ public function testRavenHandlerWhenAClientIsSpecified()
371
371
372
372
public function testSentryHandlerWhenConfigurationIsWrong ()
373
373
{
374
- try {
375
- $ this ->getContainer ([['handlers ' => ['sentry ' => ['type ' => 'sentry ' ]]]]);
376
- $ this ->fail ();
377
- } catch (InvalidConfigurationException $ e ) {
378
- $ this ->assertStringContainsString ('DSN ' , $ e ->getMessage ());
379
- }
374
+ $ this ->expectException (InvalidConfigurationException::class);
375
+ $ this ->expectExceptionMessage ('The DSN has to be specified to use Sentry \'s handler ' );
376
+
377
+ $ this ->getContainer ([['handlers ' => ['sentry ' => ['type ' => 'sentry ' ]]]]);
380
378
}
381
379
382
380
public function testSentryHandlerWhenADSNIsSpecified ()
@@ -426,7 +424,10 @@ public function testSentryHandlerWhenADSNAndAClientAreSpecified()
426
424
$ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
427
425
428
426
$ handler = $ container ->getDefinition ('monolog.handler.sentry ' );
429
- $ this ->assertDICConstructorArguments ($ handler ->getArguments ()[0 ], [new Reference ('sentry.client ' )]);
427
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.sentry.hub ' ), 'DEBUG ' , true , false ]);
428
+
429
+ $ hub = $ container ->getDefinition ($ handler ->getArguments ()[0 ]);
430
+ $ this ->assertDICConstructorArguments ($ hub , [new Reference ('sentry.client ' )]);
430
431
}
431
432
432
433
public function testSentryHandlerWhenAClientIsSpecified ()
@@ -452,7 +453,10 @@ public function testSentryHandlerWhenAClientIsSpecified()
452
453
$ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
453
454
454
455
$ handler = $ container ->getDefinition ('monolog.handler.sentry ' );
455
- $ this ->assertDICConstructorArguments ($ handler ->getArguments ()[0 ], [new Reference ('sentry.client ' )]);
456
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.sentry.hub ' ), 'DEBUG ' , true , false ]);
457
+
458
+ $ hub = $ container ->getDefinition ($ handler ->getArguments ()[0 ]);
459
+ $ this ->assertDICConstructorArguments ($ hub , [new Reference ('sentry.client ' )]);
456
460
}
457
461
458
462
public function testSentryHandlerWhenAHubIsSpecified ()
@@ -501,6 +505,51 @@ public function testSentryHandlerWhenAHubAndAClientAreSpecified()
501
505
);
502
506
}
503
507
508
+ public function testSentryBreadcrumbHandlerWhenConfigurationIsWrong ()
509
+ {
510
+ $ this ->expectException (InvalidConfigurationException::class);
511
+ $ this ->expectExceptionMessage ('The sentry_handler has to be specified to use a Sentry BreadcrumbHandler ' );
512
+
513
+ $ this ->getContainer ([['handlers ' => ['sentry_breadcrumb ' => ['type ' => 'sentry_breadcrumb ' ]]]]);
514
+ }
515
+
516
+ /**
517
+ * @testWith [{"dsn": "http://a:[email protected] :9000/1"}, "monolog.handler.sentry.hub"]
518
+ * [{"hub_id": "sentry.hub"}, "sentry.hub"]
519
+ */
520
+ public function testSentryBreadcrumbHandlerWhenConfigurationIsOk (array $ config , string $ hubId )
521
+ {
522
+ $ container = $ this ->getContainer (
523
+ [
524
+ [
525
+ 'handlers ' => [
526
+ 'sentry_breadcrumb ' => ['type ' => 'sentry_breadcrumb ' , 'sentry_handler ' => 'sentry ' ],
527
+ 'sentry ' => ['type ' => 'sentry ' ] + $ config ,
528
+ ],
529
+ ],
530
+ ],
531
+ [
532
+ 'sentry.hub ' => new Definition (\Sentry \State \HubInterface::class),
533
+ ]
534
+ );
535
+
536
+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.logger ' ));
537
+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.sentry ' ));
538
+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.sentry_breadcrumb ' ));
539
+
540
+ $ logger = $ container ->getDefinition ('monolog.logger ' );
541
+ $ this ->assertDICDefinitionMethodCallAt (0 , $ logger , 'useMicrosecondTimestamps ' , ['%monolog.use_microseconds% ' ]);
542
+ $ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
543
+ $ this ->assertDICDefinitionMethodCallAt (2 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry_breadcrumb ' )]);
544
+
545
+ $ handler = $ container ->getDefinition ('monolog.handler.sentry_breadcrumb ' );
546
+ $ this ->assertDICDefinitionClass ($ handler , 'Sentry\Monolog\BreadcrumbHandler ' );
547
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ($ hubId ), 'DEBUG ' , true ]);
548
+
549
+ $ sentry = $ container ->getDefinition ('monolog.handler.sentry ' );
550
+ $ this ->assertSame ((string ) $ sentry ->getArgument (0 ), (string ) $ handler ->getArgument (0 ));
551
+ }
552
+
504
553
public function testLogglyHandler ()
505
554
{
506
555
$ token = '026308d8-2b63-4225-8fe9-e01294b6e472 ' ;
0 commit comments