@@ -59,7 +59,10 @@ public function testWithContextProperty(): void
59
59
$ this ->assertNull ($ cloudevent ->getSubject ());
60
60
61
61
// Verify Pub/Sub-specific data transformation.
62
- $ this ->assertSame (['message ' => 'foo ' ], $ cloudevent ->getData ());
62
+ $ message = $ cloudevent ->getData ()['message ' ];
63
+ $ this ->assertSame ('foo ' , $ message ['data ' ]);
64
+ $ this ->assertSame ($ jsonData ['context ' ]['eventId ' ], $ message ['messageId ' ]);
65
+ $ this ->assertSame ($ jsonData ['context ' ]['timestamp ' ], $ message ['publishTime ' ]);
63
66
}
64
67
65
68
public function testWithoutContextProperty (): void
@@ -93,7 +96,10 @@ public function testWithoutContextProperty(): void
93
96
$ this ->assertSame ('2020-12-08T20:03:19.162Z ' , $ cloudevent ->getTime ());
94
97
95
98
// Verify Pub/Sub-specific data transformation.
96
- $ this ->assertSame (['message ' => 'foo ' ], $ cloudevent ->getData ());
99
+ $ message = $ cloudevent ->getData ()['message ' ];
100
+ $ this ->assertSame ('foo ' , $ message ['data ' ]);
101
+ $ this ->assertSame ($ jsonData ['eventId ' ], $ message ['messageId ' ]);
102
+ $ this ->assertSame ($ jsonData ['timestamp ' ], $ message ['publishTime ' ]);
97
103
}
98
104
99
105
public function testResourceAsString (): void
@@ -124,7 +130,10 @@ public function testResourceAsString(): void
124
130
$ this ->assertSame ('2020-12-08T20:03:19.162Z ' , $ cloudevent ->getTime ());
125
131
126
132
// Verify Pub/Sub-specific data transformation.
127
- $ this ->assertSame (['message ' => 'foo ' ], $ cloudevent ->getData ());
133
+ $ message = $ cloudevent ->getData ()['message ' ];
134
+ $ this ->assertSame ('foo ' , $ message ['data ' ]);
135
+ $ this ->assertSame ($ jsonData ['eventId ' ], $ message ['messageId ' ]);
136
+ $ this ->assertSame ($ jsonData ['timestamp ' ], $ message ['publishTime ' ]);
128
137
}
129
138
130
139
public function testCloudStorage (): void
@@ -211,4 +220,130 @@ public function testFirebaseAuth(): void
211
220
$ this ->assertSame ('2020-05-26T10:42:27Z ' , $ cloudevent ->getData ()['metadata ' ]['createTime ' ]);
212
221
$ this ->assertSame ('2020-10-24T11:00:00Z ' , $ cloudevent ->getData ()['metadata ' ]['lastSignInTime ' ]);
213
222
}
223
+
224
+ public function testFirebaseAuthDbDelete (): void
225
+ {
226
+ $ mapper = new LegacyEventMapper ();
227
+ $ jsonData = [
228
+ 'eventType ' => 'providers/google.firebase.database/eventTypes/ref.delete ' ,
229
+ 'params ' => [
230
+ 'child ' => 'xyz '
231
+ ],
232
+ 'auth ' => [
233
+ 'admin ' => true
234
+ ],
235
+ 'domain ' => 'europe-west1.firebasedatabase.app ' ,
236
+ 'data ' => [
237
+ 'data ' => [
238
+ 'grandchild ' => 'other changed '
239
+ ],
240
+ 'delta ' => null
241
+ ],
242
+ 'resource ' => 'projects/_/instances/my-project-id/refs/gcf-test/xyz ' ,
243
+ 'timestamp ' => '2020-05-21T11:53:45.337Z ' ,
244
+ 'eventId ' => 'oIcVXHEMZfhQMNs/yD4nwpuKE0s= '
245
+ ];
246
+ $ cloudevent = $ mapper ->fromJsonData ($ jsonData );
247
+
248
+ $ this ->assertSame ('oIcVXHEMZfhQMNs/yD4nwpuKE0s= ' , $ cloudevent ->getId ());
249
+ $ this ->assertSame (
250
+ '//firebasedatabase.googleapis.com/projects/_/locations/europe-west1/instances/my-project-id ' ,
251
+ $ cloudevent ->getSource ()
252
+ );
253
+ $ this ->assertSame ('1.0 ' , $ cloudevent ->getSpecVersion ());
254
+ $ this ->assertSame (
255
+ 'google.firebase.database.document.v1.deleted ' ,
256
+ $ cloudevent ->getType ()
257
+ );
258
+ $ this ->assertSame ('application/json ' , $ cloudevent ->getDataContentType ());
259
+ $ this ->assertNull ($ cloudevent ->getDataSchema ());
260
+ $ this ->assertSame (
261
+ 'refs/gcf-test/xyz ' ,
262
+ $ cloudevent ->getSubject ()
263
+ );
264
+ $ this ->assertSame ('2020-05-21T11:53:45.337Z ' , $ cloudevent ->getTime ());
265
+ }
266
+
267
+ public function testFirebaseAuthDbDeleteWithAlternateDomain (): void
268
+ {
269
+ $ mapper = new LegacyEventMapper ();
270
+ $ jsonData = [
271
+ 'eventType ' => 'providers/google.firebase.database/eventTypes/ref.delete ' ,
272
+ 'params ' => [
273
+ 'child ' => 'xyz '
274
+ ],
275
+ 'auth ' => [
276
+ 'admin ' => true
277
+ ],
278
+ 'domain ' => 'europe-west1.someother.app ' ,
279
+ 'data ' => [
280
+ 'data ' => [
281
+ 'grandchild ' => 'other changed '
282
+ ],
283
+ 'delta ' => null
284
+ ],
285
+ 'resource ' => 'projects/_/instances/my-project-id/refs/gcf-test/xyz ' ,
286
+ 'timestamp ' => '2020-05-21T11:53:45.337Z ' ,
287
+ 'eventId ' => 'oIcVXHEMZfhQMNs/yD4nwpuKE0s= '
288
+ ];
289
+ $ cloudevent = $ mapper ->fromJsonData ($ jsonData );
290
+
291
+ $ this ->assertSame ('oIcVXHEMZfhQMNs/yD4nwpuKE0s= ' , $ cloudevent ->getId ());
292
+ $ this ->assertSame (
293
+ '//firebasedatabase.googleapis.com/projects/_/locations/europe-west1/instances/my-project-id ' ,
294
+ $ cloudevent ->getSource ()
295
+ );
296
+ $ this ->assertSame ('1.0 ' , $ cloudevent ->getSpecVersion ());
297
+ $ this ->assertSame (
298
+ 'google.firebase.database.document.v1.deleted ' ,
299
+ $ cloudevent ->getType ()
300
+ );
301
+ $ this ->assertSame ('application/json ' , $ cloudevent ->getDataContentType ());
302
+ $ this ->assertNull ($ cloudevent ->getDataSchema ());
303
+ $ this ->assertSame (
304
+ 'refs/gcf-test/xyz ' ,
305
+ $ cloudevent ->getSubject ()
306
+ );
307
+ $ this ->assertSame ('2020-05-21T11:53:45.337Z ' , $ cloudevent ->getTime ());
308
+ }
309
+
310
+ public function testFirebaseAuthDbDeleteWithInvalidDomain (): void
311
+ {
312
+ $ mapper = new LegacyEventMapper ();
313
+ $ jsonData = [
314
+ 'eventType ' => 'providers/google.firebase.database/eventTypes/ref.delete ' ,
315
+ 'params ' => [
316
+ 'child ' => 'xyz '
317
+ ],
318
+ 'auth ' => [
319
+ 'admin ' => true
320
+ ],
321
+ 'domain ' => 'this-wont-match-regex ' ,
322
+ 'data ' => [
323
+ 'data ' => [
324
+ 'grandchild ' => 'other changed '
325
+ ],
326
+ 'delta ' => null
327
+ ],
328
+ 'resource ' => 'projects/_/instances/my-project-id/refs/gcf-test/xyz ' ,
329
+ 'timestamp ' => '2020-05-21T11:53:45.337Z ' ,
330
+ 'eventId ' => 'oIcVXHEMZfhQMNs/yD4nwpuKE0s= '
331
+ ];
332
+ $ cloudevent = $ mapper ->fromJsonData ($ jsonData );
333
+
334
+ $ this ->assertSame ('oIcVXHEMZfhQMNs/yD4nwpuKE0s= ' , $ cloudevent ->getId ());
335
+ $ this ->assertSame (
336
+ '//firebasedatabase.googleapis.com/ ' ,
337
+ $ cloudevent ->getSource ()
338
+ );
339
+ $ this ->assertSame ('1.0 ' , $ cloudevent ->getSpecVersion ());
340
+ $ this ->assertSame (
341
+ 'google.firebase.database.document.v1.deleted ' ,
342
+ $ cloudevent ->getType ()
343
+ );
344
+ $ this ->assertSame ('application/json ' , $ cloudevent ->getDataContentType ());
345
+ $ this ->assertNull ($ cloudevent ->getDataSchema ());
346
+ $ this ->assertNull ($ cloudevent ->getSubject ());
347
+ $ this ->assertSame ('2020-05-21T11:53:45.337Z ' , $ cloudevent ->getTime ());
348
+ }
214
349
}
0 commit comments