Skip to content

Commit 59f85b9

Browse files
author
Amin Mahboubi
authored
deprecate updateUsers in favor upsertUsers (#64)
1 parent b4f88a2 commit 59f85b9

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ $bob = [
8181
'name' => 'Robert Tables',
8282
];
8383

84-
$bob = $client->updateUser($bob);
84+
$bob = $client->upsertUser($bob);
8585

8686
//batch update is also supported
8787
$jane = ['id' => 'jane', 'role' => 'admin'];
8888
$june = ['id' => 'june', 'role' => 'user'];
8989
$tom = ['id' => 'tom', 'role' => 'guest'];
90-
$users = $client->updateUsers([$jane, $june, $tom]);
90+
$users = $client->upsertUsers([$jane, $june, $tom]);
9191
```
9292

9393
## ChannelType CRUD

lib/GetStream/StreamChat/Client.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public function updateAppSettings($settings)
328328
* @return mixed
329329
* @throws StreamException
330330
*/
331-
public function updateUsers($users)
331+
public function upsertUsers($users)
332332
{
333333
$user_array = [];
334334
foreach ($users as $user) {
@@ -342,9 +342,31 @@ public function updateUsers($users)
342342
* @return mixed
343343
* @throws StreamException
344344
*/
345+
public function upsertUser($user)
346+
{
347+
return $this->upsertUsers([$user]);
348+
}
349+
350+
/**
351+
* @deprecated use $client->upsertUsers instead
352+
* @param array $users
353+
* @return mixed
354+
* @throws StreamException
355+
*/
356+
public function updateUsers($users)
357+
{
358+
return $this->upsertUsers($users);
359+
}
360+
361+
/**
362+
* @deprecated use $client->upsertUser instead
363+
* @param array $user
364+
* @return mixed
365+
* @throws StreamException
366+
*/
345367
public function updateUser($user)
346368
{
347-
return $this->updateUsers([$user]);
369+
return $this->upsertUsers([$user]);
348370
}
349371

350372
/**

tests/integration/IntegrationTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function getUser()
4949
{
5050
// this creates a user on the server
5151
$user = ["id" => Uuid::uuid4()->toString()];
52-
$response = $this->client->updateUser($user);
52+
$response = $this->client->upsertUser($user);
5353
$this->assertTrue(array_key_exists("users", $response));
5454
$this->assertTrue(array_key_exists($user["id"], $response["users"]));
5555
return $user;
@@ -78,18 +78,18 @@ public function testUpdateAppSettings()
7878
$this->assertTrue(array_key_exists("duration", $response));
7979
}
8080

81-
public function testUpdateUser()
81+
public function testUpsertUser()
8282
{
8383
$user = ["id" => Uuid::uuid4()->toString()];
84-
$response = $this->client->updateUser($user);
84+
$response = $this->client->upsertUser($user);
8585
$this->assertTrue(array_key_exists("users", $response));
8686
$this->assertTrue(array_key_exists($user["id"], $response["users"]));
8787
}
8888

89-
public function testUpdateUsers()
89+
public function testUpsertUsers()
9090
{
9191
$user = ["id" => Uuid::uuid4()->toString()];
92-
$response = $this->client->updateUsers([$user]);
92+
$response = $this->client->upsertUsers([$user]);
9393
$this->assertTrue(array_key_exists("users", $response));
9494
$this->assertTrue(array_key_exists($user["id"], $response["users"]));
9595
}
@@ -122,7 +122,7 @@ public function testDeleteUsers()
122122
public function testDeleteChannels()
123123
{
124124
$user = ["id" => Uuid::uuid4()->toString()];
125-
$response = $this->client->updateUser($user);
125+
$response = $this->client->upsertUser($user);
126126

127127
$c1 = $this->getChannel();
128128
$c2 = $this->getChannel();
@@ -186,7 +186,7 @@ public function createFellowship()
186186
],
187187
["id" => "peregrin-took", "name" => "Peregrin Took", "race" => "Hobbit", "age" => 28],
188188
];
189-
$this->client->updateUsers($members);
189+
$this->client->upsertUsers($members);
190190
$user_ids = [];
191191
foreach ($members as $user) {
192192
$user_ids[] = $user['id'];
@@ -383,7 +383,7 @@ public function testQueryMembers()
383383
{
384384
$bob = ["id" => Uuid::uuid4()->toString(), "name" => "bob the builder"];
385385
$bobSponge = ["id" => Uuid::uuid4()->toString(), "name" => "bob the sponge"];
386-
$this->client->updateUsers([$bob, $bobSponge]);
386+
$this->client->upsertUsers([$bob, $bobSponge]);
387387
$channel = $this->client->Channel(
388388
"messaging",
389389
Uuid::uuid4()->toString(),
@@ -409,7 +409,7 @@ public function testQueryMembersMemberBasedChannel()
409409
{
410410
$bob = ["id" => Uuid::uuid4()->toString(), "name" => "bob the builder"];
411411
$bobSponge = ["id" => Uuid::uuid4()->toString(), "name" => "bob the sponge"];
412-
$this->client->updateUsers([$bob, $bobSponge]);
412+
$this->client->upsertUsers([$bob, $bobSponge]);
413413
$channel = $this->client->Channel(
414414
"messaging",
415415
null,
@@ -850,7 +850,7 @@ public function testChannelHideShow()
850850
public function testPartialUpdateUsers()
851851
{
852852
$carmen = ["id" => Uuid::uuid4()->toString(), "name" => "Carmen SanDiego", "hat" => "blue", "location" => "Here"];
853-
$response = $this->client->updateUser($carmen);
853+
$response = $this->client->upsertUser($carmen);
854854
$this->assertTrue(array_key_exists("users", $response));
855855
$this->assertTrue(array_key_exists($carmen["id"], $response["users"]));
856856
$this->assertSame($response["users"][$carmen["id"]]["hat"], "blue");
@@ -859,7 +859,7 @@ public function testPartialUpdateUsers()
859859
$this->assertSame($response["users"][0]["hat"], "red");
860860
$this->assertSame($response["users"][0]["location"], "Here");
861861
$wally = ["id" => Uuid::uuid4()->toString(), "name" => "Wally", "shirt" => "white", "location" => "There"];
862-
$response = $this->client->updateUser($wally);
862+
$response = $this->client->upsertUser($wally);
863863
$response = $this->client->partialUpdateUsers([
864864
["id" => $carmen["id"], "set" => ["coat" => "red"], "unset" => ["location"]],
865865
["id" => $wally["id"], "set" => ["shirt" => "striped"], "unset" => ["location"]],

0 commit comments

Comments
 (0)