Skip to content

Commit

Permalink
Merge pull request #106 from silinternational/feature/fix-name-in-get
Browse files Browse the repository at this point in the history
Make sure the name property of a GoogleUser is a GoogleName object
  • Loading branch information
mtompset authored Jul 30, 2024
2 parents 2ed42ea + 0a896ce commit a6d6665
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions SilMock/Google/Service/Directory/UsersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ public function get($userKey)
}

$newUser = new \Google_Service_Directory_User();
ObjectUtils::initialize($newUser, json_decode($userEntry['data'], true));

$decodedData = json_decode($userEntry['data'], true);
$nameArray = $decodedData['name'] ?? [];
ObjectUtils::initialize($newUser, $decodedData);
$newName = new \Google_Service_Directory_UserName();
ObjectUtils::initialize($newName, $nameArray);
$newUser->setName($newName);

// find its aliases in the database and populate its aliases property
$aliases = $this->getAliasesForUser($userKey);

Expand Down
9 changes: 7 additions & 2 deletions SilMock/tests/Google/Service/SampleUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace SilMock\tests\Google\Service;

use Google_Service_Directory_User;
use Google_Service_Directory_Aliases;
use Google_Service_Directory_Alias;
use Google\Service\Directory\UserName;
use SilMock\Google\Service\GoogleFixtures;
use SilMock\Google\Service\Directory;

Expand All @@ -24,6 +23,12 @@ public function setupSampleUser(string $dataFile, bool $withAliases = false): ?G
$newUser->isEnrolledIn2Sv = true;
$newUser->isEnforcedIn2Sv = false;
// $newUser->$suspensionReason = ''; // string
$newName = new UserName();
$newName->givenName = 'Johnathan';
$newName->familyName = 'Smith';
$newName->fullName = 'Johnathan Doe Smith';
$newName->displayName = 'John Doe Smith';
$newUser->name = $newName;

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

0 comments on commit a6d6665

Please sign in to comment.