【问题标题】:phpunit Google_Client mockphpunit Google_Client 模拟
【发布时间】:2015-07-08 21:22:32
【问题描述】:

尝试对 GA 处理类进行一些单元测试,但我不知道如何正确模拟客户端对象。我在下面的模拟代码中遇到了这个错误。

Call to undefined method Google_Client::__phpunit_cleanup()

public function getMockGaClient() {
    return $this->getMockBuilder('Google_Client')
        ->setMockClassName('Google_Client')
        ->getMock();
}

有点先发制人,我正在设置模拟名称,以便它通过参数检查。

【问题讨论】:

    标签: php unit-testing google-analytics phpunit google-analytics-api


    【解决方案1】:
    $googleClientMock = $this->createMock(Google_Client::class);
    $googleClientMock->expects(static::once())->method('setScopes')
    ->with([
        Google_Service_Sheets::SPREADSHEETS,
        Google_Service_Drive::DRIVE
    ]);
    

    【讨论】:

    • 请在您的代码中添加一些解释,以帮助其他人了解您在做什么。
    猜你喜欢
    • 2020-10-25
    • 2014-11-07
    • 2015-11-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 2018-03-03
    • 2013-02-09
    相关资源
    最近更新 更多