PHPackages                             silinternational/google-api-php-client-mock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. silinternational/google-api-php-client-mock

Abandoned → [https://github.com/sil-org/google-api-php-client-mock](/?search=https%3A%2F%2Fgithub.com%2Fsil-org%2Fgoogle-api-php-client-mock)Library[Testing &amp; Quality](/categories/testing)

silinternational/google-api-php-client-mock
===========================================

Attempting to create an intelligent mock of the Google API PHP Client for unit and functional testing.

2.17.1(1mo ago)016.4kMITPHPPHP ^8.3CI passing

Since Jul 16Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/sil-org/google-api-php-client-mock)[ Packagist](https://packagist.org/packages/silinternational/google-api-php-client-mock)[ Docs](https://github.com/sil-org/google-api-php-client-mock)[ RSS](/packages/silinternational-google-api-php-client-mock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (72)Used By (0)

google-api-php-client-mock
==========================

[](#google-api-php-client-mock)

A small scale intelligent mock of the Google API PHP Client for unit and functional testing.

Overview
--------

[](#overview)

This is intended to mock a portion of the Google APIs related to Google Workspace accounts, particularly calls relating to users and users' aliases.

Directory
---------

[](#directory)

Properties of a Google Service Directory (GSD) include...

1. $asps, which gets set to a GSD Asps\_Resource
2. $memebers, which gets set to a GSD Members\_Resource
3. $users, which gets set to a GSD Users\_Resource
4. $users\_aliases, which gets set to a GSD UsersAliases\_Resource
5. $tokens, which gets set to a GSD Tokens\_Resource
6. $twoStepVerification, which gets set to a GSD TwoStepVerification\_Resource
7. $verificationCodes, which gets set to a GSD VerificationCodes\_Resource

### Asps\_Resource

[](#asps_resource)

An Asps\_Resource is for managing a user's App Specific Passwords (ASPs). This mock implements...

1. listAsps()

### Members\_Resource

[](#members_resource)

A Members\_Resource is for managing members of a group. This mock implements...

1. insert()
2. listMembers()

### Users\_Resource

[](#users_resource)

A Users\_Resource has various methods for managing Google Apps users. Three of these that are implemented by this mock are ...

1. delete()
2. get()
3. insert()
4. update()
5. listUsers()

### UsersAliases\_Resource

[](#usersaliases_resource)

A UsersAliases\_Resource has various methods for managing Google Apps users aliases. The ones implemented by this mock are ...

1. delete()
2. insert()
3. listUsersAliases()

### Tokens\_Resource

[](#tokens_resource)

A Tokens\_Resource is for managing a user's OAuth access tokens. This mock implements...

1. listTokens()

### TwoStepVerification\_Resource

[](#twostepverification_resource)

A TwoStepVerification\_Resource is for turning off 2SV. This mock implements...

1. turnOff()

### VerificationCodes\_Resource

[](#verificationcodes_resource)

A VerificationCodes\_Resource is for managing a user's OAuth access tokens. This mock implements...

1. generate()
2. invalidate()
3. listVerificationCodes()

Gmail
-----

[](#gmail)

Properties of the Gmail API object include...

1. $users\_settings
2. $users\_settings\_delegates
3. $users\_settings\_forwardingAddresses

### UsersSettings

[](#userssettings)

Methods on the UsersSettings resource that this mock implements include...

1. updateImap()
2. updatePop()

UsersSettingsDelegates
----------------------

[](#userssettingsdelegates)

Methods on the UsersSettingsDelegates resource that this mock implements include...

1. create()
2. delete()
3. get()
4. listUsersSettingsDelegates()

UsersSettingsForwardingAddresses
--------------------------------

[](#userssettingsforwardingaddresses)

Methods on the UsersSettingsForwardingAddresses resource that this mock implements include...

1. listUsersSettingsForwardingAddresses()

Unit Testing
------------

[](#unit-testing)

You should have docker and the docker compose plugin installed. To run testing:

- make it-now

Data Persistence
----------------

[](#data-persistence)

In order to keep data available for use by this mock, it makes use of a **Sqlite** database file. The default path and name of this file are ... **SilMock/DataStore/Sqlite/Google\_Service\_Data.db**. To override this, the constructors for the UsersResource and UsersAliasesResource class accept an optional string parameter.

The database is accessed/managed by **SilMock/DataStore/Sqlite/SqliteUtils.php**. It has one table with four columns ...

1. id = INTEGER PRIMARY KEY,
2. type = TEXT, e.g. "directory",
3. class = TEXT, e.g. "user" or "users\_alias",
4. data = TEXT

The **data** field contains json with key-value pairs related to the properties of the GSD objects. The data is prepared by using the php json\_encode function.

Test Fixtures
-------------

[](#test-fixtures)

There is a class to assist with dealing with data for unit tests ... **SilMock\\Google\\Service\\GoogleFixtures.php**. Its constructor accepts an optional parameter for the path and name of the Sqlite database file. It has two methods ...

1. addFixtures($fixtures), expecting an array of 3-element arrays (type, class, data).
2. removeAllFixtures()

Unit Tests for the Mock Itself
------------------------------

[](#unit-tests-for-the-mock-itself)

The SilMock/tests folder includes phpunit tests for the three main portions of this mock (Directory, GoogleFixtures, SqliteUtils). These should help provide examples of how to use the mock.

Examples
--------

[](#examples)

### Switching between the Mock and the Real GSD

[](#switching-between-the-mock-and-the-real-gsd)

```
public static function useRealGoogle() {
    return  ( ! isset (\Yii::app()->params['use_real_google']) ||
              \Yii::app()->params['use_real_google']);
}

public static function getGoogleServiceDirectory($client) {
    if (static::useRealGoogle()) {
        return new Google\Service\Directory($client);
    }
    $db_path = null;
    if (isset(\Yii::app()->params['googleMockDbPath'])) {
        $db_path = \Yii::app()->params['googleMockDbPath'];
    }
    return new SilMock\Google\Service\Directory($client, $db_path);
}

```

### Managing a User

[](#managing-a-user)

```
$dir = static::getGoogleServiceDirectory($client);
$google_user = new Google\Service\Directory\User();
$google_user = $dir->users->insert($google_user);
$google_user = $dir->users->get($usersEmail);

$google_user->suspended = true;
$google_user->suspensionReason = 'ADMIN';
$account = $dir->users->update($users_email, $google_user);

```

### Managing a User's Aliases

[](#managing-a-users-aliases)

```
$dir = static::getGoogleServiceDirectory($client);
$google_alias = new Google\Service\Directory\Alias();
$google_alias->setAlias($alias);
$alias = $dir->users_aliases->insert($users_email, $google_alias);

$aliases = $dir->users_aliases->listUsersAliases($users_email);
$alias = $dir->users_aliases->delete($users_email, $alias);

```

### WARNING: Aliases and email address which are multibyte will likely break this library.

[](#warning-aliases-and-email-address-which-are-multibyte-will-likely-break-this-library)

### DEVELOPER'S NOTE: Releases should include updating the version in composer.json to match

[](#developers-note-releases-should-include-updating-the-version-in-composerjson-to-match)

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance89

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 69.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~45 days

Total

67

Last Release

57d ago

Major Versions

0.9.0 → 1.0.02021-03-24

1.6.1 → 2.0.02023-08-21

1.6.3 → 2.0.32024-02-15

1.6.4 → 2.0.42024-03-25

PHP version history (6 changes)0.1PHP &gt;=5.3.3

0.6.0PHP &gt;=7.2.0

1.0.0PHP &gt;=7.3.0

1.0.1PHP &gt;=7.4.0

2.0.0PHP ^8.2

2.16.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5e188393958c4505bb06d9e79ed99a47d1cd42551142f02ef364d8268449ef8?d=identicon)[fillup](/maintainers/fillup)

![](https://www.gravatar.com/avatar/836739aa4f60c754dc9a4a547ebd0c166e4b6e855d9f119df2be5aec92f3a375?d=identicon)[forevermatt](/maintainers/forevermatt)

![](https://www.gravatar.com/avatar/a0d56d7e6fc794910b03eff96448007ee05879ad38493f0b5f215c4fe61f4b30?d=identicon)[mtompset](/maintainers/mtompset)

---

Top Contributors

[![mtompset](https://avatars.githubusercontent.com/u/10937901?v=4)](https://github.com/mtompset "mtompset (360 commits)")[![Baggerone](https://avatars.githubusercontent.com/u/8058522?v=4)](https://github.com/Baggerone "Baggerone (84 commits)")[![forevermatt](https://avatars.githubusercontent.com/u/6233204?v=4)](https://github.com/forevermatt "forevermatt (56 commits)")[![briskt](https://avatars.githubusercontent.com/u/3172830?v=4)](https://github.com/briskt "briskt (8 commits)")[![jason-jackson](https://avatars.githubusercontent.com/u/35783387?v=4)](https://github.com/jason-jackson "jason-jackson (4 commits)")[![fillup](https://avatars.githubusercontent.com/u/556105?v=4)](https://github.com/fillup "fillup (3 commits)")[![devon-sil](https://avatars.githubusercontent.com/u/122382412?v=4)](https://github.com/devon-sil "devon-sil (1 commits)")

---

Tags

mockgoogle-api-php-client

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/silinternational-google-api-php-client-mock/health.svg)

```
[![Health](https://phpackages.com/badges/silinternational-google-api-php-client-mock/health.svg)](https://phpackages.com/packages/silinternational-google-api-php-client-mock)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[phake/phake

The Phake mock testing library

4758.0M324](/packages/phake-phake)[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.2k1.2M247](/packages/kahlan-kahlan)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33412.5M350](/packages/brain-monkey)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
