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