]> git.mxchange.org Git - friendica-addons.git/blob - s3_storage/vendor/akeeba/s3/minitest/Test/SmallInlineFiles.php
[s3_storage] Bump version of akeeba/s3 to version 2.3.1
[friendica-addons.git] / s3_storage / vendor / akeeba / s3 / minitest / Test / SmallInlineFiles.php
1 <?php
2 /**
3  * Akeeba Engine
4  *
5  * @package   akeebaengine
6  * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
7  * @license   GNU General Public License version 3, or later
8  */
9
10 namespace Akeeba\MiniTest\Test;
11
12 use Akeeba\S3\Connector;
13 use Akeeba\S3\Input;
14
15 /**
16  * Upload, download and delete small files (under 1MB) using a string source
17  *
18  * @package Akeeba\MiniTest\Test
19  */
20 class SmallInlineFiles extends SmallFiles
21 {
22         protected static function upload(Connector $s3, array $options, int $size, string $uri): bool
23         {
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);
27
28                 // Create some random data to upload
29                 $sourceData = static::getRandomData($size);
30
31                 // Upload the data. Throws exception if it fails.
32                 $bucket = $options['bucket'];
33                 $input  = Input::createFromData($sourceData);
34
35                 $s3->putObject($input, $bucket, $uri);
36
37                 // Tentatively accept that this method succeeded.
38                 $result = true;
39
40                 // Should I download the file and compare its contents with my random data?
41                 if (static::$downloadAfter)
42                 {
43                         $downloadedData = $s3->getObject($bucket, $uri);
44
45                         $result = static::areStringsEqual($sourceData, $downloadedData);
46                 }
47
48                 // Should I delete the remotely stored file?
49                 if (static::$deleteRemote)
50                 {
51                         // Delete the remote file. Throws exception if it fails.
52                         $s3->deleteObject($bucket, $uri);
53                 }
54
55                 return $result;
56         }
57 }