async-aws / aws

AWS SDK with readable code and async responses

Home Page:https://async-aws.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve testability - remove "final" from "presign"

alex-billetsca opened this issue · comments

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.

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

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'),
		);
	}
}