]> git.mxchange.org Git - friendica-addons.git/blob - s3_storage/vendor/akeeba/s3/minitest/Test/ListThousandsOfFiles.php
[s3_storage] Bump version of akeeba/s3 to version 2.3.1
[friendica-addons.git] / s3_storage / vendor / akeeba / s3 / minitest / Test / ListThousandsOfFiles.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 class ListThousandsOfFiles extends AbstractTest
16 {
17         private const PATH_PREFIX = 'massive/';
18
19         public static function setup(Connector $s3, array $options): void
20         {
21                 if (defined('CREATE_2100_FILES') && CREATE_2100_FILES === false)
22                 {
23                         return;
24                 }
25
26                 $data = static::getRandomData(128);
27
28                 echo "\nPopulating with 2100 files\n";
29
30                 for ($i = 1; $i <= 2100; $i++)
31                 {
32                         if ($i % 10 === 0)
33                         {
34                                 echo "Uploading from $i...\n";
35                         }
36
37                         $uri   = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
38                         $input = Input::createFromData($data);
39                         $s3->putObject($input, $options['bucket'], $uri);
40                 }
41         }
42
43         public static function testGetAll(Connector $s3, array $options): bool
44         {
45                 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX);
46
47                 static::assert(is_array($listing), "The files listing must be an array");
48                 static::assert(count($listing) === 2100, "I am expecting to see 2100 files");
49
50                 for ($i = 1; $i <= 2100; $i++)
51                 {
52                         $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
53
54                         static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
55                 }
56
57                 return true;
58         }
59
60         public static function testGetHundred(Connector $s3, array $options): bool
61         {
62                 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX, null, 100);
63
64                 static::assert(is_array($listing), "The files listing must be an array");
65                 static::assert(count($listing) === 100, "I am expecting to see 100 files");
66
67                 for ($i = 1; $i <= 100; $i++)
68                 {
69                         $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
70
71                         static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
72                 }
73
74                 return true;
75         }
76
77         public static function testGetElevenHundred(Connector $s3, array $options): bool
78         {
79                 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX, null, 1100);
80
81                 static::assert(is_array($listing), "The files listing must be an array");
82                 static::assert(count($listing) === 1100, "I am expecting to see 1100 files");
83
84                 for ($i = 1; $i <= 1100; $i++)
85                 {
86                         $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
87
88                         static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
89                 }
90
91                 return true;
92         }
93
94         public static function testGetLastHundred(Connector $s3, array $options): bool
95         {
96                 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX . 'test_20', null);
97
98                 static::assert(is_array($listing), "The files listing must be an array");
99                 static::assert(count($listing) === 100, "I am expecting to see 100 files");
100
101                 for ($i = 2000; $i <= 2099; $i++)
102                 {
103                         $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
104
105                         static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
106                 }
107
108                 return true;
109         }
110
111 }