@@ -276,7 +276,11 @@ public function testParseFacetsUrlWithTrickyRegex()
276276
277277 public function testWithMedia ()
278278 {
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 ) {
280284 yield function (string $ method , string $ url , array $ options ) {
281285 $ this ->assertSame ('POST ' , $ method );
282286 $ this ->assertSame ('https://bsky.social/xrpc/com.atproto.server.createSession ' , $ url );
@@ -299,21 +303,40 @@ public function testWithMedia()
299303 ]]);
300304 };
301305
302- yield function (string $ method , string $ url , array $ options ) {
306+ yield function (string $ method , string $ url , array $ options ) use ( $ recordUri , $ recordCid ) {
303307 $ this ->assertSame ('POST ' , $ method );
304308 $ this ->assertSame ('https://bsky.social/xrpc/com.atproto.repo.createRecord ' , $ url );
305309 $ this ->assertArrayHasKey ('authorization ' , $ options ['normalized_headers ' ]);
306310 $ 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 ' ]);
307311
308- return new JsonMockResponse (['cid ' => ' 103254962155278888 ' ]);
312+ return new JsonMockResponse (['uri ' => $ recordUri , ' cid ' => $ recordCid ]);
309313 };
310314 })()));
311315
312316 $ options = (new BlueskyOptions ())
313317 ->attachMedia (new File (__DIR__ .'/fixtures.gif ' ), 'A fixture ' );
314318 $ result = $ transport ->send (new ChatMessage ('Hello World! ' , $ options ));
315319
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 ());
317340 }
318341
319342 /**
0 commit comments