使用嘲笑模拟s3client getObject

时间:2020-02-25 11:02:02

标签: php amazon-web-services unit-testing amazon-s3 mockery

我需要模拟以下代码的帮助:

try {
    $s3Client = new S3Client([
        'region' => getenv('AWS_REGION'),
        'version' => 'latest',
    ]);
    $result = $s3Client->getObject([
        'Bucket' => getenv('AWS_BUCKET_NAME'),
        'Key' => 'KEY'
    ]);
} catch (S3Exception $e) {
    $cacheRequired = true;
}

我想编写测试以模拟上面的服务。

我已经尝试过了:

$awsS3Service = Mockery::mock(S3Client::class)->makePartial();
$awsS3Service
    ->shouldReceive('getObject')
    ->andReturn(NULL);

0 个答案:

没有答案