I’m pretty new into testing things, and I was wondering how I could test such code or even if it’s valuable to test this.
this is what my code looks like :
public function convert(string $urlToConvert, string $path, array $options = []): void
{
try {
$result = $this->getClient()->post(
sprintf('%s/%s', $this->config->getEndpoint(), self::GOTENBERG_CHROMIUM_ENDPOINT),
[
'multipart' => [
['name' => 'url', 'contents' => $urlToConvert],
['name' => 'emulatedMediaType', 'contents' => 'screen'],
...$options
]
]
);
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$directory->writeFile($path, $result->getBody());
} catch (Exception | GuzzleException $e) {
$this->logger->error($e, ['context' => 'm2-gotenberg']);
throw new GotenbergConvertException(__('Failed converting PDF'), $e);
}
}
The getClient() returns an instance of a GuzzleHttp.
The process is the following :
- Do a request on an endpoint with the URL
- Get the response body which is the converted PDF
- Create a file with the content given by the response
I don’t feel like I could test anything, or a really small amount of the code.
About the lines creating the files, this is the done by the framework I’m using
The only thing I see is to do an integration test, and fetching the endpoint to create a real pdf, then delete it.
Can someone clarify this for me or give me some advices? When using framework I have troubles on what to test to avoid testing the implementation of my code