2022-02-20 21:22:07 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Akeeba Engine
|
|
|
|
*
|
|
|
|
* @package akeebaengine
|
2024-03-20 04:03:34 +01:00
|
|
|
* @copyright Copyright (c)2006-2024 Nicholas K. Dionysopoulos / Akeeba Ltd
|
2022-02-20 21:22:07 +01:00
|
|
|
* @license GNU General Public License version 3, or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Akeeba\MiniTest\Test;
|
|
|
|
|
|
|
|
|
2023-12-19 03:28:16 +01:00
|
|
|
use Akeeba\S3\Acl;
|
|
|
|
use Akeeba\S3\Connector;
|
|
|
|
use Akeeba\S3\Input;
|
|
|
|
use Akeeba\S3\StorageClass;
|
2022-02-20 21:22:07 +01:00
|
|
|
|
|
|
|
class StorageClasses extends AbstractTest
|
|
|
|
{
|
|
|
|
protected static $downloadAfter = true;
|
|
|
|
|
|
|
|
protected static $deleteRemote = true;
|
|
|
|
|
|
|
|
public static function uploadRRS(Connector $s3, array $options): bool
|
|
|
|
{
|
2023-12-19 03:28:16 +01:00
|
|
|
return static::upload($s3, $options, static::TEN_KB, 'rrs_test_10kb.dat', StorageClass::REDUCED_REDUNDANCY);
|
2022-02-20 21:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function uploadIntelligentTiering(Connector $s3, array $options): bool
|
|
|
|
{
|
2023-12-19 03:28:16 +01:00
|
|
|
return static::upload($s3, $options, static::TEN_KB, 'rrs_test_10kb.dat', StorageClass::INTELLIGENT_TIERING);
|
2022-02-20 21:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static function upload(Connector $s3, array $options, int $size, string $uri, string $storageClass = null)
|
|
|
|
{
|
|
|
|
// Randomize the name. Required for archive buckets where you cannot overwrite data.
|
|
|
|
$dotPos = strrpos($uri, '.');
|
|
|
|
$uri = substr($uri, 0, $dotPos) . '.' . md5(microtime(false)) . substr($uri, $dotPos);
|
|
|
|
|
|
|
|
// Create some random data to upload
|
2023-12-19 03:28:16 +01:00
|
|
|
$sourceData = static::getRandomData($size);
|
2022-02-20 21:22:07 +01:00
|
|
|
|
|
|
|
// Upload the data. Throws exception if it fails.
|
|
|
|
$bucket = $options['bucket'];
|
|
|
|
$input = Input::createFromData($sourceData);
|
|
|
|
|
|
|
|
// Get the headers
|
|
|
|
$headers = [];
|
|
|
|
StorageClass::setStorageClass($headers, $storageClass);
|
|
|
|
|
|
|
|
$s3->putObject($input, $bucket, $uri, Acl::ACL_PRIVATE, $headers);
|
|
|
|
|
|
|
|
// Tentatively accept that this method succeeded.
|
|
|
|
$result = true;
|
|
|
|
|
|
|
|
// Should I download the file and compare its contents with my random data?
|
2023-12-19 03:28:16 +01:00
|
|
|
if (static::$downloadAfter)
|
2022-02-20 21:22:07 +01:00
|
|
|
{
|
|
|
|
$downloadedData = $s3->getObject($bucket, $uri);
|
|
|
|
|
2023-12-19 03:28:16 +01:00
|
|
|
$result = static::areStringsEqual($sourceData, $downloadedData);
|
2022-02-20 21:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should I delete the remotely stored file?
|
2023-12-19 03:28:16 +01:00
|
|
|
if (static::$deleteRemote)
|
2022-02-20 21:22:07 +01:00
|
|
|
{
|
|
|
|
// Delete the remote file. Throws exception if it fails.
|
|
|
|
$s3->deleteObject($bucket, $uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|