Skip to content

Commit 0a896ce

Browse files
committed
Make sure the name property of a GoogleUser is a GoogleName object
1 parent 2ed42ea commit 0a896ce

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

SilMock/Google/Service/Directory/UsersResource.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ public function get($userKey)
6060
}
6161

6262
$newUser = new \Google_Service_Directory_User();
63-
ObjectUtils::initialize($newUser, json_decode($userEntry['data'], true));
64-
63+
$decodedData = json_decode($userEntry['data'], true);
64+
$nameArray = $decodedData['name'] ?? [];
65+
ObjectUtils::initialize($newUser, $decodedData);
66+
$newName = new \Google_Service_Directory_UserName();
67+
ObjectUtils::initialize($newName, $nameArray);
68+
$newUser->setName($newName);
69+
6570
// find its aliases in the database and populate its aliases property
6671
$aliases = $this->getAliasesForUser($userKey);
6772

SilMock/tests/Google/Service/SampleUser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
namespace SilMock\tests\Google\Service;
44

55
use Google_Service_Directory_User;
6-
use Google_Service_Directory_Aliases;
7-
use Google_Service_Directory_Alias;
6+
use Google\Service\Directory\UserName;
87
use SilMock\Google\Service\GoogleFixtures;
98
use SilMock\Google\Service\Directory;
109

@@ -24,6 +23,12 @@ public function setupSampleUser(string $dataFile, bool $withAliases = false): ?G
2423
$newUser->isEnrolledIn2Sv = true;
2524
$newUser->isEnforcedIn2Sv = false;
2625
// $newUser->$suspensionReason = ''; // string
26+
$newName = new UserName();
27+
$newName->givenName = 'Johnathan';
28+
$newName->familyName = 'Smith';
29+
$newName->fullName = 'Johnathan Doe Smith';
30+
$newName->displayName = 'John Doe Smith';
31+
$newUser->name = $newName;
2732

2833
if ($withAliases) {
2934
$newUser->aliases = [ '[email protected]', '[email protected]' ];

0 commit comments

Comments
 (0)