@@ -918,50 +918,68 @@ public function wont_send_event_if_disabled() {
918
918
919
919
/** @test */
920
920
public function it_adds_event_type_and_ts_to_event_payload () {
921
- $ eventsDispatcher = $ this ->createMock (BulkEventDispatcher::class);
922
- $ eventsDispatcher
923
- ->expects ($ this ->once ())
924
- ->method ('addEvent ' )
925
- ->with ([
926
- 'event_type ' => 'log ' ,
927
- 'ts ' => (new DateTime ())->format (DATE_ATOM ),
928
- 'message ' => 'Test message ' ,
929
- ]);
930
-
931
- $ client = HoneybadgerClient::new ([
932
- new Response (201 ),
933
- ]);
934
- $ badger = Honeybadger::new ([
935
- 'api_key ' => 'asdf ' ,
921
+ $ client = $ this ->createMock (\Honeybadger \HoneybadgerClient::class);
922
+ $ config = new Config ([
923
+ 'api_key ' => '1234 ' ,
936
924
'events ' => [
937
- 'enabled ' => true ,
938
- ],
939
- ], $ client ->make (), $ eventsDispatcher );
940
-
925
+ 'enabled ' => true
926
+ ]
927
+ ]);
928
+ $ eventsDispatcher = new class ($ config , $ client ) extends BulkEventDispatcher {
929
+ public $ events = [];
930
+
931
+ public function __construct (Config $ config , \Honeybadger \HoneybadgerClient $ client )
932
+ {
933
+ parent ::__construct ($ config , $ client );
934
+ }
935
+
936
+ public function addEvent ($ event ): void
937
+ {
938
+ $ this ->events [] = $ event ;
939
+ }
940
+ };
941
+ $ badger = new Honeybadger ($ config ->all (), null , $ eventsDispatcher );
941
942
$ badger ->event ('log ' , ['message ' => 'Test message ' ]);
943
+
944
+ $ this ->assertCount (1 , $ eventsDispatcher ->events );
945
+
946
+ $ event = $ eventsDispatcher ->events [0 ];
947
+ $ this ->assertArrayHasKey ('ts ' , $ event );
948
+ $ this ->assertEquals ('log ' , $ event ['event_type ' ]);
949
+ $ this ->assertEquals ('Test message ' , $ event ['message ' ]);
942
950
}
943
951
944
952
/** @test */
945
953
public function it_adds_ts_to_event_payload () {
946
- $ eventsDispatcher = $ this ->createMock (BulkEventDispatcher::class);
947
- $ eventsDispatcher
948
- ->expects ($ this ->once ())
949
- ->method ('addEvent ' )
950
- ->with ([
951
- 'ts ' => (new DateTime ())->format (DATE_ATOM ),
952
- 'message ' => 'Test message ' ,
953
- ]);
954
-
955
- $ client = HoneybadgerClient::new ([
956
- new Response (201 ),
957
- ]);
958
- $ badger = Honeybadger::new ([
959
- 'api_key ' => 'asdf ' ,
954
+ $ client = $ this ->createMock (\Honeybadger \HoneybadgerClient::class);
955
+ $ config = new Config ([
956
+ 'api_key ' => '1234 ' ,
960
957
'events ' => [
961
- 'enabled ' => true ,
962
- ],
963
- ], $ client ->make (), $ eventsDispatcher );
958
+ 'enabled ' => true
959
+ ]
960
+ ]);
961
+ $ eventsDispatcher = new class ($ config , $ client ) extends BulkEventDispatcher {
962
+ public $ events = [];
963
+
964
+ public function __construct (Config $ config , \Honeybadger \HoneybadgerClient $ client )
965
+ {
966
+ parent ::__construct ($ config , $ client );
967
+ }
968
+
969
+ public function addEvent ($ event ): void
970
+ {
971
+ $ this ->events [] = $ event ;
972
+ }
973
+ };
974
+ $ badger = new Honeybadger ($ config ->all (), null , $ eventsDispatcher );
975
+
964
976
$ badger ->event (['message ' => 'Test message ' ]);
977
+ $ this ->assertCount (1 , $ eventsDispatcher ->events );
978
+
979
+ $ event = $ eventsDispatcher ->events [0 ];
980
+ $ this ->assertArrayHasKey ('ts ' , $ event );
981
+ $ this ->assertArrayNotHasKey ('event_type ' , $ event );
982
+ $ this ->assertEquals ('Test message ' , $ event ['message ' ]);
965
983
}
966
984
967
985
/** @test */
0 commit comments