Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.14.0: Add domains.list functionality #122

Merged
merged 9 commits into from
Dec 12, 2024
3 changes: 3 additions & 0 deletions SilMock/Google/Service/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Google\Client;
use SilMock\Google\Http\Batch;
use SilMock\Google\Service\Directory\Asps;
use SilMock\Google\Service\Directory\Resource\Domains;
use SilMock\Google\Service\Directory\Resource\Groups;
use SilMock\Google\Service\Directory\Resource\GroupsAliases;
use SilMock\Google\Service\Directory\Resource\Members;
Expand All @@ -18,6 +19,7 @@
class Directory
{
public $asps;
public Domains $domains;
public Members $members;
public Groups $groups;
public GroupsAliases $groups_aliases;
Expand All @@ -38,6 +40,7 @@ class Directory
public function __construct($client, ?string $dbFile = null)
{
$this->asps = new Asps($dbFile);
$this->domains = new Domains($dbFile);
$this->members = new Members($dbFile);
$this->groups = new Groups($dbFile);
$this->groups_aliases = new GroupsAliases($dbFile);
Expand Down
32 changes: 32 additions & 0 deletions SilMock/Google/Service/Directory/Resource/Domains.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace SilMock\Google\Service\Directory\Resource;

use Google\Service\Directory\Domains as GoogleDirectory_Domains;
use Google\Service\Directory\Domains2 as GoogleDirectory_Domains2;
use SilMock\Google\Service\DbClass;

class Domains extends DbClass
{
// default to the same as Group and Members
public function __construct(?string $dbFile = DATAFILE5)
{
parent::__construct($dbFile, 'directory', 'domains');
}

public function listDomains(string $customer, array $options = []): GoogleDirectory_Domains2
{
// no need to store anything at this time.
$domainNamesString = getenv('DOMAIN_NAMES');
$domainNames = explode(',', $domainNamesString);
$domains = [];
foreach ($domainNames as $domainName) {
$domain = new GoogleDirectory_Domains();
$domain->setDomainName($domainName);
$domains[] = $domain;
}
$domains2 = new GoogleDirectory_Domains2();
$domains2->setDomains($domains);
return $domains2;
}
}
28 changes: 28 additions & 0 deletions SilMock/tests/Google/Service/Directory/Resource/DomainsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Service\Directory\Resource;

use PHPUnit\Framework\TestCase;
use SilMock\Google\Service\Directory\Resource\Domains;

class DomainsTest extends TestCase
{
public function testListDomains()
{
$domainsApi = new Domains();
$domainNameListObject = $domainsApi->listDomains('any_customer');
$arrayOfDomainsObjects = $domainNameListObject->getDomains();
$domainNameList = [];
foreach ($arrayOfDomainsObjects as $domainObject) {
$domainNameList[$domainObject->getDomainName()] = $domainObject->getDomainName();
}
// This should match the values in docker-compose.yml when testing locally
// This should match the values in run-tests.sh when testing is triggered by GitHub actions
// This is the keyed array version of the list.
$expected = [
'groups.example.org' => 'groups.example.org',
'example.org' => 'example.org',
];
self::assertEquals($expected, $domainNameList, 'Domain name list does not match expected values');
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "silinternational/google-api-php-client-mock",
"version": "2.13.2",
"version": "2.14.0",
"description": "Attempting to create an intelligent mock of the Google API PHP Client for unit and functional testing.",
"type": "library",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ services:
volumes:
- ./:/data
working_dir: /data
environment:
# This should match the value in run-tests.sh
- DOMAIN_NAMES=groups.example.org,example.org
command: ["true"]

networks:
Expand Down
3 changes: 2 additions & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


cd /data/SilMock/tests
./phpunit
# This should match the value in docker-compose.yml
DOMAIN_NAMES=groups.example.org,example.org ./phpunit
Loading