@@ -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 ()
@@ -396,8 +394,9 @@ public function testSentryHandlerWhenADSNIsSpecified()
396
394
397
395
$ handler = $ container ->getDefinition ('monolog.handler.sentry ' );
398
396
$ this ->assertDICDefinitionClass ($ handler , 'Sentry\Monolog\Handler ' );
397
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.sentry.hub ' ), 'DEBUG ' , true , false ]);
399
398
400
- $ hub = $ container ->getDefinition (' monolog. handler.sentry.hub ' );
399
+ $ hub = $ container ->getDefinition ($ handler-> getArguments ()[ 0 ] );
401
400
$ this ->assertDICDefinitionClass ($ hub , 'Sentry\State\Hub ' );
402
401
$ this ->assertDICConstructorArguments ($ hub , [new Reference ('monolog.sentry.client. ' .sha1 ($ dsn ))]);
403
402
}
@@ -426,7 +425,12 @@ public function testSentryHandlerWhenADSNAndAClientAreSpecified()
426
425
$ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
427
426
428
427
$ handler = $ container ->getDefinition ('monolog.handler.sentry ' );
429
- $ this ->assertDICConstructorArguments ($ handler ->getArguments ()[0 ], [new Reference ('sentry.client ' )]);
428
+ $ this ->assertDICDefinitionClass ($ handler , 'Sentry\Monolog\Handler ' );
429
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.sentry.hub ' ), 'DEBUG ' , true , false ]);
430
+
431
+ $ hub = $ container ->getDefinition ($ handler ->getArguments ()[0 ]);
432
+ $ this ->assertDICDefinitionClass ($ hub , 'Sentry\State\Hub ' );
433
+ $ this ->assertDICConstructorArguments ($ hub , [new Reference ('sentry.client ' )]);
430
434
}
431
435
432
436
public function testSentryHandlerWhenAClientIsSpecified ()
@@ -452,7 +456,12 @@ public function testSentryHandlerWhenAClientIsSpecified()
452
456
$ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
453
457
454
458
$ handler = $ container ->getDefinition ('monolog.handler.sentry ' );
455
- $ this ->assertDICConstructorArguments ($ handler ->getArguments ()[0 ], [new Reference ('sentry.client ' )]);
459
+ $ this ->assertDICDefinitionClass ($ handler , 'Sentry\Monolog\Handler ' );
460
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ('monolog.handler.sentry.hub ' ), 'DEBUG ' , true , false ]);
461
+
462
+ $ hub = $ container ->getDefinition ($ handler ->getArguments ()[0 ]);
463
+ $ this ->assertDICDefinitionClass ($ hub , 'Sentry\State\Hub ' );
464
+ $ this ->assertDICConstructorArguments ($ hub , [new Reference ('sentry.client ' )]);
456
465
}
457
466
458
467
public function testSentryHandlerWhenAHubIsSpecified ()
@@ -478,6 +487,7 @@ public function testSentryHandlerWhenAHubIsSpecified()
478
487
$ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
479
488
480
489
$ handler = $ container ->getDefinition ('monolog.handler.sentry ' );
490
+ $ this ->assertDICDefinitionClass ($ handler , 'Sentry\Monolog\Handler ' );
481
491
$ this ->assertDICConstructorArguments ($ handler , [new Reference ('sentry.hub ' ), 'DEBUG ' , true , false ]);
482
492
}
483
493
@@ -501,6 +511,51 @@ public function testSentryHandlerWhenAHubAndAClientAreSpecified()
501
511
);
502
512
}
503
513
514
+ public function testSentryBreadcrumbHandlerWhenConfigurationIsWrong ()
515
+ {
516
+ $ this ->expectException (InvalidConfigurationException::class);
517
+ $ this ->expectExceptionMessage ('The sentry_handler has to be specified to use a Sentry BreadcrumbHandler ' );
518
+
519
+ $ this ->getContainer ([['handlers ' => ['sentry_breadcrumb ' => ['type ' => 'sentry_breadcrumb ' ]]]]);
520
+ }
521
+
522
+ /**
523
+ * @testWith [{"dsn": "http://a:[email protected] :9000/1"}, "monolog.handler.sentry.hub"]
524
+ * [{"hub_id": "sentry.hub"}, "sentry.hub"]
525
+ */
526
+ public function testSentryBreadcrumbHandlerWhenConfigurationIsOk (array $ config , string $ hubId )
527
+ {
528
+ $ container = $ this ->getContainer (
529
+ [
530
+ [
531
+ 'handlers ' => [
532
+ 'sentry_breadcrumb ' => ['type ' => 'sentry_breadcrumb ' , 'sentry_handler ' => 'sentry ' ],
533
+ 'sentry ' => ['type ' => 'sentry ' ] + $ config ,
534
+ ],
535
+ ],
536
+ ],
537
+ [
538
+ 'sentry.hub ' => new Definition (\Sentry \State \HubInterface::class),
539
+ ]
540
+ );
541
+
542
+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.logger ' ));
543
+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.sentry ' ));
544
+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.sentry_breadcrumb ' ));
545
+
546
+ $ logger = $ container ->getDefinition ('monolog.logger ' );
547
+ $ this ->assertDICDefinitionMethodCallAt (0 , $ logger , 'useMicrosecondTimestamps ' , ['%monolog.use_microseconds% ' ]);
548
+ $ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry ' )]);
549
+ $ this ->assertDICDefinitionMethodCallAt (2 , $ logger , 'pushHandler ' , [new Reference ('monolog.handler.sentry_breadcrumb ' )]);
550
+
551
+ $ handler = $ container ->getDefinition ('monolog.handler.sentry_breadcrumb ' );
552
+ $ this ->assertDICDefinitionClass ($ handler , 'Sentry\Monolog\BreadcrumbHandler ' );
553
+ $ this ->assertDICConstructorArguments ($ handler , [new Reference ($ hubId ), 'DEBUG ' , true ]);
554
+
555
+ $ sentry = $ container ->getDefinition ('monolog.handler.sentry ' );
556
+ $ this ->assertSame ((string ) $ sentry ->getArgument (0 ), (string ) $ handler ->getArgument (0 ));
557
+ }
558
+
504
559
public function testLogglyHandler ()
505
560
{
506
561
$ token = '026308d8-2b63-4225-8fe9-e01294b6e472 ' ;
0 commit comments