@@ -276,7 +276,11 @@ public function testParseFacetsUrlWithTrickyRegex()
276
276
277
277
public function testWithMedia ()
278
278
{
279
- $ transport = $ this ->createTransport (new MockHttpClient ((function () {
279
+ // realistic sample values taken from https://docs.bsky.app/docs/advanced-guides/posts#post-record-structure
280
+ $ recordUri = 'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k4duaz5vfs2b ' ;
281
+ $ recordCid = 'bafyreibjifzpqj6o6wcq3hejh7y4z4z2vmiklkvykc57tw3pcbx3kxifpm ' ;
282
+
283
+ $ transport = $ this ->createTransport (new MockHttpClient ((function () use ($ recordUri , $ recordCid ) {
280
284
yield function (string $ method , string $ url , array $ options ) {
281
285
$ this ->assertSame ('POST ' , $ method );
282
286
$ this ->assertSame ('https://bsky.social/xrpc/com.atproto.server.createSession ' , $ url );
@@ -299,21 +303,40 @@ public function testWithMedia()
299
303
]]);
300
304
};
301
305
302
- yield function (string $ method , string $ url , array $ options ) {
306
+ yield function (string $ method , string $ url , array $ options ) use ( $ recordUri , $ recordCid ) {
303
307
$ this ->assertSame ('POST ' , $ method );
304
308
$ this ->assertSame ('https://bsky.social/xrpc/com.atproto.repo.createRecord ' , $ url );
305
309
$ this ->assertArrayHasKey ('authorization ' , $ options ['normalized_headers ' ]);
306
310
$ this ->assertSame ('{"repo":null,"collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"Hello World!","createdAt":"2024-04-28T08:40:17.000000Z","embed":{"$type":"app.bsky.embed.images","images":[{"alt":"A fixture","image":{"$type":"blob","ref":{"$link":"bafkreibabalobzn6cd366ukcsjycp4yymjymgfxcv6xczmlgpemzkz3cfa"},"mimeType":"image\/png","size":760898}}]}}} ' , $ options ['body ' ]);
307
311
308
- return new JsonMockResponse (['cid ' => ' 103254962155278888 ' ]);
312
+ return new JsonMockResponse (['uri ' => $ recordUri , ' cid ' => $ recordCid ]);
309
313
};
310
314
})()));
311
315
312
316
$ options = (new BlueskyOptions ())
313
317
->attachMedia (new File (__DIR__ .'/fixtures.gif ' ), 'A fixture ' );
314
318
$ result = $ transport ->send (new ChatMessage ('Hello World! ' , $ options ));
315
319
316
- $ this ->assertSame ('103254962155278888 ' , $ result ->getMessageId ());
320
+ $ this ->assertSame ($ recordUri , $ result ->getMessageId ());
321
+ }
322
+
323
+ public function testReturnedMessageId ()
324
+ {
325
+ // realistic sample values taken from https://docs.bsky.app/docs/advanced-guides/posts#post-record-structure
326
+ $ recordUri = 'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k4duaz5vfs2b ' ;
327
+ $ recordCid = 'bafyreibjifzpqj6o6wcq3hejh7y4z4z2vmiklkvykc57tw3pcbx3kxifpm ' ;
328
+
329
+ $ client = new MockHttpClient (function () use ($ recordUri , $ recordCid ) {
330
+ return new JsonMockResponse ([
331
+ 'uri ' => $ recordUri ,
332
+ 'cid ' => $ recordCid ,
333
+ ]);
334
+ });
335
+
336
+ $ transport = self ::createTransport ($ client );
337
+ $ message = $ transport ->send (new ChatMessage ('Hello! ' ));
338
+
339
+ $ this ->assertSame ($ recordUri , $ message ->getMessageId ());
317
340
}
318
341
319
342
/**
0 commit comments