async-aws / aws

AWS SDK with readable code and async responses
https://async-aws.com
MIT License
436 stars 132 forks source link

Improve testability - remove "final" from "presign" #1531

Open alex-billetsca opened 1 year ago

alex-billetsca commented 1 year ago
final public function presign(Input $input, ?\DateTimeImmutable $expires = null): string

This makes testing impossible as you cannot mock the presign!

--

I am aware of libs that override the loading mechanisms - this does not always work depending on how CI/CD builds are configured. It should not be a requirement to be able to properly test against this lib.

stof commented 1 year ago

what is the use case for mocking this method though ? You can use the actual one.

alex-billetsca commented 1 year ago

Simple use case - write a test for this class: I don't care about the internals of the s3 client (just like I wouldn't for any other service).

class AsyncAwsAdapter {
    public function __construct(
        private readonly S3Client $s3Client,
        private readonly string $bucket,
        private readonly string $path = ''
    ) {
    }

    public function doSomeCall(string $name): string {
        return $this->s3Client->presign(
            new GetObjectRequest([
                'Bucket' => $this->bucket,
                'Key' => $this->path,
            ]),
            new DateTimeImmutable('2 hours'),
        );
    }
}