Warm tip: This article is reproduced from serverfault.com, please click

Test error handling of the PHP S3Client uploadAsync method

发布于 2020-11-16 15:39:32

Method uploadAsync automatically decides and uploads object in single or multiple chunks. And we can expect 2 different kind of expectations S3Exception and S3MultipartUploadException in our $result['reason']. I'm trying to mock part of the S3 client to throw the exception, I have done this by MockHandler:

$s3->getHandlerList()->setHandler(new MockHandler([$result], null, null)); 

And the $result is:

new S3Exception("", new Command("mockCommand"), [
                    'code' => 'mockCode',
                    'response' => new Response(401)
                ])

Or either this:

new S3MultipartUploadException(new UploadState(['testid']))

Since the S3MultipartUploadException is not instance of AwsException I got this exception: InvalidArgumentException: Expected an Aws\ResultInterface or Aws\Exception\AwsException.

How can I handle such scenario?

Questioner
Matjaž Mav
Viewed
0
Matjaž Mav 2020-11-29 07:19:21

I have asked this on the project repo and they confirmed this is a bug https://github.com/aws/aws-sdk-php/issues/2143.