5 * @package akeebaengine
6 * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
7 * @license GNU General Public License version 3, or later
10 namespace Akeeba\MiniTest\Test;
12 use Akeeba\S3\Connector;
16 * Upload, download and delete small files (under 1MB) using a string source
18 * @package Akeeba\MiniTest\Test
20 class SmallInlineFiles extends SmallFiles
22 protected static function upload(Connector $s3, array $options, int $size, string $uri): bool
24 // Randomize the name. Required for archive buckets where you cannot overwrite data.
25 $dotPos = strrpos($uri, '.');
26 $uri = substr($uri, 0, $dotPos) . '.' . md5(microtime(false)) . substr($uri, $dotPos);
28 // Create some random data to upload
29 $sourceData = static::getRandomData($size);
31 // Upload the data. Throws exception if it fails.
32 $bucket = $options['bucket'];
33 $input = Input::createFromData($sourceData);
35 $s3->putObject($input, $bucket, $uri);
37 // Tentatively accept that this method succeeded.
40 // Should I download the file and compare its contents with my random data?
41 if (static::$downloadAfter)
43 $downloadedData = $s3->getObject($bucket, $uri);
45 $result = static::areStringsEqual($sourceData, $downloadedData);
48 // Should I delete the remotely stored file?
49 if (static::$deleteRemote)
51 // Delete the remote file. Throws exception if it fails.
52 $s3->deleteObject($bucket, $uri);