Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alex-billetsca opened this issue Jul 31, 2023 · 2 comments
Open

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

alex-billetsca opened this issue Jul 31, 2023 · 2 comments

Comments

@alex-billetsca
Copy link

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
Copy link
Member

stof commented Aug 8, 2023

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

@alex-billetsca
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants