Stub icon indicating copy to clipboard operation
Stub copied to clipboard

Can't mock magic methods for \Aws\S3\S3Client

Open uaoleg opened this issue 1 year ago • 1 comments

\Aws\S3\S3Client has way too many magic, e.g. for method putObject() So when I try to mock this method it's treated as a property. Possible solution is to explicitly specify if it's a method or a property:

\Codeception\Stub::makeEmpty(
    \Aws\S3\S3Client::class,
    [
        'putObject()' => 'result',
    ],
);

uaoleg avatar Sep 29 '23 12:09 uaoleg

A better solution might not be to mock it at all. What I do as a clean approach is this:

  1. Define an interface for the functionality that you use.
  2. Create an implementation that uses S3 client, test it using integration tests
  3. In your application tests mock your own interface.

SamMousa avatar Sep 29 '23 12:09 SamMousa