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;
15 class ListThousandsOfFiles extends AbstractTest
17 private const PATH_PREFIX = 'massive/';
19 public static function setup(Connector $s3, array $options): void
21 if (defined('CREATE_2100_FILES') && CREATE_2100_FILES === false)
26 $data = static::getRandomData(128);
28 echo "\nPopulating with 2100 files\n";
30 for ($i = 1; $i <= 2100; $i++)
34 echo "Uploading from $i...\n";
37 $uri = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
38 $input = Input::createFromData($data);
39 $s3->putObject($input, $options['bucket'], $uri);
43 public static function testGetAll(Connector $s3, array $options): bool
45 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX);
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");
50 for ($i = 1; $i <= 2100; $i++)
52 $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
54 static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
60 public static function testGetHundred(Connector $s3, array $options): bool
62 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX, null, 100);
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");
67 for ($i = 1; $i <= 100; $i++)
69 $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
71 static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
77 public static function testGetElevenHundred(Connector $s3, array $options): bool
79 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX, null, 1100);
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");
84 for ($i = 1; $i <= 1100; $i++)
86 $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
88 static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));
94 public static function testGetLastHundred(Connector $s3, array $options): bool
96 $listing = $s3->getBucket($options['bucket'], static::PATH_PREFIX . 'test_20', null);
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");
101 for ($i = 2000; $i <= 2099; $i++)
103 $key = sprintf('%stest_%04u.dat', static::PATH_PREFIX, $i);
105 static::assert(array_key_exists($key, $listing), sprintf('Results should list object %s', $key));