5 * @package akeebaengine
6 * @copyright Copyright (c)2006-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
7 * @license GNU General Public License version 3, or later
10 namespace Akeeba\MiniTest\Test;
13 use Akeeba\Engine\Postproc\Connector\S3v4\Connector;
14 use Akeeba\Engine\Postproc\Connector\S3v4\Input;
17 * Upload, download and delete small files (under 1MB) using a string source
19 * @package Akeeba\MiniTest\Test
21 class SmallInlineFiles extends SmallFiles
23 protected static function upload(Connector $s3, array $options, int $size, string $uri): bool
25 // Randomize the name. Required for archive buckets where you cannot overwrite data.
26 $dotPos = strrpos($uri, '.');
27 $uri = substr($uri, 0, $dotPos) . '.' . md5(microtime(false)) . substr($uri, $dotPos);
29 // Create some random data to upload
30 $sourceData = self::getRandomData($size);
32 // Upload the data. Throws exception if it fails.
33 $bucket = $options['bucket'];
34 $input = Input::createFromData($sourceData);
36 $s3->putObject($input, $bucket, $uri);
38 // Tentatively accept that this method succeeded.
41 // Should I download the file and compare its contents with my random data?
42 if (self::$downloadAfter)
44 $downloadedData = $s3->getObject($bucket, $uri);
46 $result = self::areStringsEqual($sourceData, $downloadedData);
49 // Should I delete the remotely stored file?
50 if (self::$deleteRemote)
52 // Delete the remote file. Throws exception if it fails.
53 $s3->deleteObject($bucket, $uri);