@@ -25,10 +25,13 @@ protected function setUp(): void
2525
2626 public function testCreate (): void
2727 {
28+ // GIVEN: a list of members
2829 $ members = [['sn ' => 'user1 ' ], ['sn ' => 'user2 ' ]];
2930
31+ // WHEN: create is called with all params
3032 $ this ->api ->create ('Test Chat ' , about: 'desc ' , members: $ members , public: true );
3133
34+ // THEN: correct request is sent
3235 [$ method , $ path , $ params ] = $ this ->httpClientSpy ->calls [0 ];
3336 $ this ->assertSame ('get ' , $ method );
3437 $ this ->assertSame ('/v1/chats/createChat ' , $ path );
@@ -40,8 +43,10 @@ public function testCreate(): void
4043
4144 public function testCreateDefaults (): void
4245 {
46+ // WHEN: create is called with only name
4347 $ this ->api ->create ('Chat ' );
4448
49+ // THEN: default values are used
4550 $ params = $ this ->httpClientSpy ->calls [0 ][2 ];
4651 $ this ->assertNull ($ params ['about ' ]);
4752 $ this ->assertNull ($ params ['rules ' ]);
@@ -53,10 +58,13 @@ public function testCreateDefaults(): void
5358
5459 public function testAddMembers (): void
5560 {
61+ // GIVEN: a list of members to add
5662 $ members = [['sn ' => 'user1 ' ]];
5763
64+ // WHEN: addMembers is called
5865 $ this ->api ->addMembers ('chat1 ' , $ members );
5966
67+ // THEN: correct request is sent
6068 [$ method , $ path , $ params ] = $ this ->httpClientSpy ->calls [0 ];
6169 $ this ->assertSame ('get ' , $ method );
6270 $ this ->assertSame ('/v1/chats/members/add ' , $ path );
@@ -66,15 +74,19 @@ public function testAddMembers(): void
6674
6775 public function testRemoveMembers (): void
6876 {
77+ // WHEN: removeMembers is called
6978 $ this ->api ->removeMembers ('chat1 ' , [['sn ' => 'user1 ' ]]);
7079
80+ // THEN: correct path is used
7181 $ this ->assertSame ('/v1/chats/members/delete ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
7282 }
7383
7484 public function testSendAction (): void
7585 {
86+ // WHEN: sendAction is called
7687 $ this ->api ->sendAction ('chat1 ' , 'typing ' );
7788
89+ // THEN: correct path and params are sent
7890 [$ method , $ path , $ params ] = $ this ->httpClientSpy ->calls [0 ];
7991 $ this ->assertSame ('/v1/chats/sendActions ' , $ path );
8092 $ this ->assertSame ('chat1 ' , $ params ['chatId ' ]);
@@ -83,55 +95,69 @@ public function testSendAction(): void
8395
8496 public function testGetInfo (): void
8597 {
98+ // WHEN: getInfo is called
8699 $ this ->api ->getInfo ('chat1 ' );
87100
101+ // THEN: correct path and chatId are sent
88102 $ this ->assertSame ('/v1/chats/getInfo ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
89103 $ this ->assertSame ('chat1 ' , $ this ->httpClientSpy ->calls [0 ][2 ]['chatId ' ]);
90104 }
91105
92106 public function testGetAdmins (): void
93107 {
108+ // WHEN: getAdmins is called
94109 $ this ->api ->getAdmins ('chat1 ' );
95110
111+ // THEN: correct path is used
96112 $ this ->assertSame ('/v1/chats/getAdmins ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
97113 }
98114
99115 public function testGetMembersWithCursor (): void
100116 {
117+ // WHEN: getMembers is called with cursor
101118 $ this ->api ->getMembers ('chat1 ' , cursor: 'abc ' );
102119
120+ // THEN: cursor param is included
103121 $ params = $ this ->httpClientSpy ->calls [0 ][2 ];
104122 $ this ->assertSame ('chat1 ' , $ params ['chatId ' ]);
105123 $ this ->assertSame ('abc ' , $ params ['cursor ' ]);
106124 }
107125
108126 public function testGetMembersWithoutCursorDoesNotIncludeCursorParam (): void
109127 {
128+ // WHEN: getMembers is called without cursor
110129 $ this ->api ->getMembers ('chat1 ' );
111130
131+ // THEN: cursor param is absent
112132 $ params = $ this ->httpClientSpy ->calls [0 ][2 ];
113133 $ this ->assertSame ('chat1 ' , $ params ['chatId ' ]);
114134 $ this ->assertArrayNotHasKey ('cursor ' , $ params );
115135 }
116136
117137 public function testGetBlockedUsers (): void
118138 {
139+ // WHEN: getBlockedUsers is called
119140 $ this ->api ->getBlockedUsers ('chat1 ' );
120141
142+ // THEN: correct path is used
121143 $ this ->assertSame ('/v1/chats/getBlockedUsers ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
122144 }
123145
124146 public function testGetPendingUsers (): void
125147 {
148+ // WHEN: getPendingUsers is called
126149 $ this ->api ->getPendingUsers ('chat1 ' );
127150
151+ // THEN: correct path is used
128152 $ this ->assertSame ('/v1/chats/getPendingUsers ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
129153 }
130154
131155 public function testBlockUser (): void
132156 {
157+ // WHEN: blockUser is called with delLastMessages=true
133158 $ this ->api ->blockUser ('chat1 ' , 'user1 ' , delLastMessages: true );
134159
160+ // THEN: correct params are sent
135161 $ params = $ this ->httpClientSpy ->calls [0 ][2 ];
136162 $ this ->assertSame ('/v1/chats/blockUser ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
137163 $ this ->assertSame ('user1 ' , $ params ['userId ' ]);
@@ -140,16 +166,20 @@ public function testBlockUser(): void
140166
141167 public function testUnblockUser (): void
142168 {
169+ // WHEN: unblockUser is called
143170 $ this ->api ->unblockUser ('chat1 ' , 'user1 ' );
144171
172+ // THEN: correct path and userId are sent
145173 $ this ->assertSame ('/v1/chats/unblockUser ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
146174 $ this ->assertSame ('user1 ' , $ this ->httpClientSpy ->calls [0 ][2 ]['userId ' ]);
147175 }
148176
149177 public function testResolvePendingWithUserId (): void
150178 {
179+ // WHEN: resolvePending is called with userId
151180 $ this ->api ->resolvePending ('chat1 ' , approve: true , userId: 'user1 ' );
152181
182+ // THEN: userId is sent, everyone is absent
153183 $ params = $ this ->httpClientSpy ->calls [0 ][2 ];
154184 $ this ->assertSame ('/v1/chats/resolvePending ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
155185 $ this ->assertTrue ($ params ['approve ' ]);
@@ -159,8 +189,10 @@ public function testResolvePendingWithUserId(): void
159189
160190 public function testResolvePendingWithEveryone (): void
161191 {
192+ // WHEN: resolvePending is called with everyone=true
162193 $ this ->api ->resolvePending ('chat1 ' , approve: false , everyone: true );
163194
195+ // THEN: everyone is sent, userId is absent
164196 $ params = $ this ->httpClientSpy ->calls [0 ][2 ];
165197 $ this ->assertFalse ($ params ['approve ' ]);
166198 $ this ->assertTrue ($ params ['everyone ' ]);
@@ -179,24 +211,30 @@ public static function invalidResolvePendingParamsProvider(): iterable
179211 #[DataProvider('invalidResolvePendingParamsProvider ' )]
180212 public function testResolvePendingThrowsOnInvalidParams (?string $ userId , ?bool $ everyone ): void
181213 {
214+ // THEN: exception is expected
182215 $ this ->expectException (\InvalidArgumentException::class);
183216 $ this ->expectExceptionMessage ('Exactly one of userId or everyone must be provided ' );
184217
218+ // WHEN: resolvePending is called with invalid param combination
185219 $ this ->api ->resolvePending ('chat1 ' , approve: true , userId: $ userId , everyone: $ everyone );
186220 }
187221
188222 public function testSetTitle (): void
189223 {
224+ // WHEN: setTitle is called
190225 $ this ->api ->setTitle ('chat1 ' , 'New Title ' );
191226
227+ // THEN: correct path and title are sent
192228 $ this ->assertSame ('/v1/chats/setTitle ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
193229 $ this ->assertSame ('New Title ' , $ this ->httpClientSpy ->calls [0 ][2 ]['title ' ]);
194230 }
195231
196232 public function testSetAvatar (): void
197233 {
234+ // WHEN: setAvatar is called
198235 $ this ->api ->setAvatar ('chat1 ' , '/tmp/avatar.png ' );
199236
237+ // THEN: multipart request is sent with file path
200238 [$ method , $ path , $ params , $ filePath ] = $ this ->httpClientSpy ->calls [0 ];
201239 $ this ->assertSame ('postMultipart ' , $ method );
202240 $ this ->assertSame ('/v1/chats/avatar/set ' , $ path );
@@ -206,16 +244,20 @@ public function testSetAvatar(): void
206244
207245 public function testSetAbout (): void
208246 {
247+ // WHEN: setAbout is called
209248 $ this ->api ->setAbout ('chat1 ' , 'About text ' );
210249
250+ // THEN: correct path and about are sent
211251 $ this ->assertSame ('/v1/chats/setAbout ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
212252 $ this ->assertSame ('About text ' , $ this ->httpClientSpy ->calls [0 ][2 ]['about ' ]);
213253 }
214254
215255 public function testSetRules (): void
216256 {
257+ // WHEN: setRules is called
217258 $ this ->api ->setRules ('chat1 ' , 'Be nice ' );
218259
260+ // THEN: correct path and rules are sent
219261 $ this ->assertSame ('/v1/chats/setRules ' , $ this ->httpClientSpy ->calls [0 ][1 ]);
220262 $ this ->assertSame ('Be nice ' , $ this ->httpClientSpy ->calls [0 ][2 ]['rules ' ]);
221263 }
0 commit comments