diff --git a/bundle/Command/ShowApiUsageCommand.php b/bundle/Command/ShowApiUsageCommand.php
index 0d7a5c32..1b4ab11e 100644
--- a/bundle/Command/ShowApiUsageCommand.php
+++ b/bundle/Command/ShowApiUsageCommand.php
@@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($this->getPrettyKey($key) . ': ' . $value . '');
}
- return 0;
+ return Command::SUCCESS;
}
private function getPrettyKey(string $key): string
diff --git a/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php b/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php
index ea97ffcd..3dba5808 100644
--- a/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php
+++ b/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php
@@ -8,31 +8,23 @@
final class CloudinaryConfiguration
{
- private ?Configuration $configuration = null;
-
public function __construct(
private string $cloudName,
private string $apiKey,
private string $apiSecret,
private string $uploadPrefix,
- private bool $useSubdomains = false
+ private bool $useSubdomains = false,
) {}
public function create(): Configuration
{
- if (!$this->configuration instanceof Configuration) {
- $this->configuration = Configuration::instance(
- [
- 'cloud_name' => $this->cloudName,
- 'api_key' => $this->apiKey,
- 'api_secret' => $this->apiSecret,
- 'upload_prefix' => $this->uploadPrefix,
- 'cdn_subdomain' => $this->useSubdomains,
- 'force_version' => false,
- ],
- );
- }
-
- return $this->configuration;
+ return Configuration::instance([
+ 'cloud_name' => $this->cloudName,
+ 'api_key' => $this->apiKey,
+ 'api_secret' => $this->apiSecret,
+ 'upload_prefix' => $this->uploadPrefix,
+ 'cdn_subdomain' => $this->useSubdomains,
+ 'force_version' => false,
+ ]);
}
}
diff --git a/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php b/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
index ee673163..c22c78c0 100644
--- a/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
+++ b/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
@@ -61,12 +61,12 @@ public function __construct(
}
public function setServices(
- UploadApi $uploadApi,
AdminApi $adminApi,
+ UploadApi $uploadApi,
SearchApi $searchApi,
): void {
- $this->uploadApi = $uploadApi;
$this->adminApi = $adminApi;
+ $this->uploadApi = $uploadApi;
$this->searchApi = $searchApi;
}
@@ -173,7 +173,7 @@ public function upload(string $fileUri, array $options): RemoteResource
$response = $this->uploadApi->upload($fileUri, $options);
$resource = $this->remoteResourceFactory->create((array) $response);
- if ($response['existing'] ?? false) {
+ if (($response['existing'] ?? false) !== false) {
throw new RemoteResourceExistsException($resource);
}
diff --git a/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php b/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php
index 75c63728..63cdd818 100644
--- a/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php
+++ b/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php
@@ -165,7 +165,7 @@ public function getVideoTag(CloudinaryRemoteId $remoteId, array $options = [], ?
public function getDownloadLink(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
{
- $this->logger->info("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Cloudinary::cloudinary_url(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getDownloadLink($remoteId, $options, $token);
}
diff --git a/tests/lib/Core/Provider/Cloudinary/CloudinaryConfigurationInitializer.php b/tests/lib/Core/Provider/Cloudinary/CloudinaryConfigurationInitializer.php
new file mode 100644
index 00000000..f4826d65
--- /dev/null
+++ b/tests/lib/Core/Provider/Cloudinary/CloudinaryConfigurationInitializer.php
@@ -0,0 +1,32 @@
+ self::CLOUD_NAME,
+ 'api_key' => self::API_KEY,
+ 'api_secret' => self::API_SECRET,
+ 'upload_prefix' => self::UPLOAD_PREFIX,
+ 'cdn_subdomain' => false,
+ 'force_version' => false,
+ ]);
+ }
+}
diff --git a/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php b/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
index a952d4e6..2d6e3221 100644
--- a/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
@@ -764,7 +764,7 @@ public function testInternalUpload(): void
'type' => 'upload',
'resource_type' => 'image',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
];
diff --git a/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php b/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php
index 374447ed..8226ce0a 100644
--- a/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php
@@ -83,8 +83,8 @@ public static function toCloudinaryAccessModeProvider(): array
public static function toCloudinaryAccessControlProvider(): array
{
return [
- [RemoteResource::VISIBILITY_PUBLIC, ['access_type' => 'anonymous']],
- [RemoteResource::VISIBILITY_PROTECTED, ['access_type' => 'token']],
+ [RemoteResource::VISIBILITY_PUBLIC, [['access_type' => 'anonymous']]],
+ [RemoteResource::VISIBILITY_PROTECTED, [['access_type' => 'token']]],
];
}
}
diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfigurationTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfigurationTest.php
new file mode 100644
index 00000000..22a48840
--- /dev/null
+++ b/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfigurationTest.php
@@ -0,0 +1,35 @@
+cloudinaryConfigurationFactory = new CloudinaryConfigurationFactory(
+ CloudinaryConfigurationInitializer::CLOUD_NAME,
+ CloudinaryConfigurationInitializer::API_KEY,
+ CloudinaryConfigurationInitializer::API_SECRET,
+ CloudinaryConfigurationInitializer::UPLOAD_PREFIX,
+ false,
+ );
+ }
+
+ public function testCreate(): void
+ {
+ self::assertSame(
+ CloudinaryConfigurationInitializer::getConfiguration(),
+ $this->cloudinaryConfigurationFactory->create(),
+ );
+ }
+}
diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstanceTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstanceTest.php
deleted file mode 100644
index 068f567d..00000000
--- a/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstanceTest.php
+++ /dev/null
@@ -1,35 +0,0 @@
-cloudinaryInstanceFactory = new CloudinaryInstanceFactory('myCloud', 'myKey', 'mySecret', 'myprefix');
- }
-
- public function testCreate(): void
- {
- $cloudinaryInstance = $this->cloudinaryInstanceFactory->create();
-
- self::assertInstanceOf(Cloudinary::class, $cloudinaryInstance);
-
- $newCloudinaryInstance = $this->cloudinaryInstanceFactory->create();
-
- self::assertSame(
- $cloudinaryInstance,
- $newCloudinaryInstance,
- );
- }
-}
diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
index f37630e6..e84ee236 100644
--- a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
@@ -9,7 +9,7 @@
use Netgen\RemoteMedia\API\Values\RemoteResource;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\ResourceType as ResourceTypeConverter;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType as VisibilityTypeConverter;
-use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryInstance;
+use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryConfiguration;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\RemoteResource as RemoteResourceFactory;
use Netgen\RemoteMedia\Exception\Factory\InvalidDataException;
use Netgen\RemoteMedia\Tests\AbstractTestCase;
@@ -28,8 +28,15 @@ protected function setUp(): void
{
$this->fileHashFactoryMock = $this->createMock(FileHashFactoryInterface::class);
- $cloudinaryInstanceFactory = new CloudinaryInstance('myCloud', 'myKey', 'mySecret', 'https://api.cloudinary.com');
- $cloudinaryInstanceFactory->create();
+ $cloudinaryConfigurationFactory = new CloudinaryConfiguration(
+ 'testcloud',
+ 'apikey',
+ 'apisecret',
+ 'https://api.cloudinary.com',
+ false,
+ );
+
+ $cloudinaryConfigurationFactory->create();
$this->remoteResourceFactory = new RemoteResourceFactory(
new ResourceTypeConverter(),
@@ -88,8 +95,8 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'type' => 'upload',
- 'url' => 'http://res.cloudinary.com/myCloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
+ 'url' => 'http://res.cloudinary.com/testcloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
'etag' => 'e522f43cf89aa0afd03387c37e2b6e12',
'tags' => ['tag1'],
'overwritten' => 'true',
@@ -110,7 +117,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'upload|image|c87hg9xfxrd4itiim3t0',
type: 'image',
- url: 'https://res.cloudinary.com/myCloud/image/upload/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/image/upload/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e12',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.jpg',
@@ -142,8 +149,8 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'type' => 'upload',
- 'url' => 'http://res.cloudinary.com/myCloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
+ 'url' => 'http://res.cloudinary.com/testcloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
'etag' => 'e522f43cf89aa0afd03387c37e2b6e29',
'context' => [
'custom' => [
@@ -154,7 +161,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'upload|image|other/c87hg9xfxrd4itiim3t0',
type: 'document',
- url: 'https://res.cloudinary.com/myCloud/image/upload/other/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/image/upload/other/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'my_original_image.jpg',
@@ -182,7 +189,7 @@ public static function createDataProvider(): array
'resource_type' => 'video',
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
- 'url' => 'http://res.cloudinary.com/myCloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
+ 'url' => 'http://res.cloudinary.com/testcloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
'tags' => ['tag1', 'tag2'],
'overwritten' => 'false',
'context' => [
@@ -198,7 +205,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'upload|video|c87hg9xfxrd4itiim3t0',
type: 'video',
- url: 'https://res.cloudinary.com/myCloud/video/upload/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/video/upload/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
@@ -229,8 +236,8 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'type' => 'authenticated',
- 'url' => 'http://res.cloudinary.com/myCloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
+ 'url' => 'http://res.cloudinary.com/testcloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
'tags' => ['tag1', 'tag2'],
'overwritten' => 'false',
'context' => [],
@@ -242,7 +249,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'authenticated|video|c87hg9xfxrd4itiim3t0',
type: 'video',
- url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/video/authenticated/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
@@ -270,7 +277,7 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 12025,
'type' => 'authenticated',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/authenticated/video/v1371995958/c87hg9xfxrd4itiim3t0.mp3',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/authenticated/video/v1371995958/c87hg9xfxrd4itiim3t0.mp3',
'etag' => 'e522f43cf89aa0afd03387c37e2b6e29',
'overwritten' => 'false',
'context' => [
@@ -284,7 +291,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'authenticated|video|c87hg9xfxrd4itiim3t0',
type: 'audio',
- url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/video/authenticated/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp3',
@@ -313,7 +320,7 @@ public static function createDataProvider(): array
'created_at' => '2011-06-23T13:59:18Z',
'bytes' => 12025,
'type' => 'test',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/v1371995958/raw/media/raw/new/c87hg9xfxrd4itiim3t0',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/v1371995958/raw/media/raw/new/c87hg9xfxrd4itiim3t0',
'etag' => 'e522f43cf89aa0afd03387c38e2b6e29',
'context' => [
'test' => 'test',
@@ -326,7 +333,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'test|raw|media/raw/new/c87hg9xfxrd4itiim3t0',
type: 'other',
- url: 'https://res.cloudinary.com/myCloud/raw/test/media/raw/new/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/raw/test/media/raw/new/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c38e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'test.mp4',
diff --git a/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php b/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php
index cd765169..80359447 100644
--- a/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php
@@ -5,11 +5,11 @@
namespace Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\Gateway;
use ArrayObject;
-use Cloudinary;
-use Cloudinary\Api;
-use Cloudinary\Api\Response as CloudinaryApiResponse;
-use Cloudinary\Search;
-use Cloudinary\Uploader as CloudinaryUploader;
+use Cloudinary\Api\Admin\AdminApi;
+use Cloudinary\Api\ApiResponse;
+use Cloudinary\Api\Exception\NotFound;
+use Cloudinary\Api\Search\SearchApi;
+use Cloudinary\Api\Upload\UploadApi;
use DateTimeImmutable;
use Netgen\RemoteMedia\API\Factory\RemoteResource as RemoteResourceFactoryInterface;
use Netgen\RemoteMedia\API\Factory\SearchResult as SearchResultFactoryInterface;
@@ -21,39 +21,26 @@
use Netgen\RemoteMedia\Core\Provider\Cloudinary\CloudinaryRemoteId;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\ResourceType as ResourceTypeConverter;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType as VisibilityTypeConverter;
-use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryInstance;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Gateway\CloudinaryApiGateway;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Resolver\AuthToken as AuthTokenResolver;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Resolver\SearchExpression as SearchExpressionResolver;
use Netgen\RemoteMedia\Exception\FolderNotFoundException;
use Netgen\RemoteMedia\Exception\RemoteResourceNotFoundException;
use Netgen\RemoteMedia\Tests\AbstractTestCase;
+use Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\CloudinaryConfigurationInitializer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
-use stdClass;
-
-use function json_encode;
#[CoversClass(CloudinaryApiGateway::class)]
class CloudinaryApiGatewayTest extends AbstractTestCase
{
- protected const CLOUD_NAME = 'testcloud';
-
- protected const API_KEY = 'apikey';
-
- protected const API_SECRET = 'secret';
-
- protected const UPLOAD_PREFIX = 'https://api.cloudinary.com';
-
- protected const ENCRYPTION_KEY = '38128319a3a49e1d589a31a217e1a3f8';
-
protected CloudinaryApiGateway $apiGateway;
- protected Cloudinary|MockObject $cloudinaryMock;
+ protected AdminApi|MockObject $adminApiMock;
- protected Api|MockObject $cloudinaryApiMock;
+ protected MockObject|UploadApi $uploadApiMock;
- protected MockObject|Search $cloudinarySearchMock;
+ protected MockObject|SearchApi $searchApiMock;
protected MockObject|RemoteResourceFactoryInterface $remoteResourceFactoryMock;
@@ -61,35 +48,27 @@ class CloudinaryApiGatewayTest extends AbstractTestCase
protected function setUp(): void
{
- $this->cloudinaryMock = $this->createMock(Cloudinary::class);
- $this->cloudinaryApiMock = $this->createMock(Api::class);
- $this->cloudinarySearchMock = $this->createMock(Search::class);
+ $this->adminApiMock = $this->createMock(AdminApi::class);
+ $this->uploadApiMock = $this->createMock(UploadApi::class);
+ $this->searchApiMock = $this->createMock(SearchApi::class);
$this->remoteResourceFactoryMock = $this->createMock(RemoteResourceFactoryInterface::class);
$this->searchResultFactoryMock = $this->createMock(SearchResultFactoryInterface::class);
- $cloudinaryInstanceFactory = new CloudinaryInstance(
- self::CLOUD_NAME,
- self::API_KEY,
- self::API_SECRET,
- self::UPLOAD_PREFIX,
- );
-
$this->apiGateway = new CloudinaryApiGateway(
- $cloudinaryInstanceFactory->create(),
+ CloudinaryConfigurationInitializer::getConfiguration(),
$this->remoteResourceFactoryMock,
$this->searchResultFactoryMock,
new SearchExpressionResolver(
new ResourceTypeConverter(),
new VisibilityTypeConverter(),
),
- new AuthTokenResolver(self::ENCRYPTION_KEY),
+ new AuthTokenResolver(CloudinaryConfigurationInitializer::ENCRYPTION_KEY),
);
$this->apiGateway->setServices(
- $this->cloudinaryMock,
- new CloudinaryUploader(),
- $this->cloudinaryApiMock,
- $this->cloudinarySearchMock,
+ $this->adminApiMock,
+ $this->uploadApiMock,
+ $this->searchApiMock,
);
}
@@ -130,17 +109,15 @@ public function testUsage(): void
],
];
- $response = new stdClass();
- $response->body = json_encode($data);
- $response->headers = [
- 'X-FeatureRateLimit-Reset' => '12.11.2021 17:00:00',
- 'X-FeatureRateLimit-Limit' => 1567654320,
- 'X-FeatureRateLimit-Remaining' => 1965,
+ $headers = [
+ 'X-FeatureRateLimit-Reset' => ['12.11.2021 17:00:00'],
+ 'X-FeatureRateLimit-Limit' => ['1567654320'],
+ 'X-FeatureRateLimit-Remaining' => ['1965'],
];
- $response = new CloudinaryApiResponse($response);
+ $response = new ApiResponse($data, $headers);
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('usage')
->willReturn($response);
@@ -243,7 +220,7 @@ public function testUsage(): void
self::assertTrue($usage->has('credits_limit'));
self::assertSame(
- 135,
+ 135.0,
$usage->get('credits_limit'),
);
@@ -255,15 +232,8 @@ public function testIsEncryptionEnabled(): void
{
self::assertTrue($this->apiGateway->isEncryptionEnabled());
- $cloudinaryInstanceFactory = new CloudinaryInstance(
- self::CLOUD_NAME,
- self::API_KEY,
- self::API_SECRET,
- self::UPLOAD_PREFIX,
- );
-
$apiGateway = new CloudinaryApiGateway(
- $cloudinaryInstanceFactory->create(),
+ CloudinaryConfigurationInitializer::getConfiguration(),
$this->remoteResourceFactoryMock,
$this->searchResultFactoryMock,
new SearchExpressionResolver(
@@ -278,7 +248,7 @@ public function testIsEncryptionEnabled(): void
public function testCountResources(): void
{
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('usage')
->willReturn(['resources' => 1200]);
@@ -293,19 +263,19 @@ public function testCountResourcesInFolder(): void
{
$expression = 'folder:folderName/*';
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with(0)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($this->getSearchResponse());
@@ -329,9 +299,9 @@ public function testListFolders(): void
],
];
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('root_folders')
+ ->method('rootFolders')
->willReturn(
new ArrayObject(
['folders' => $folders],
@@ -360,7 +330,7 @@ public function testListSubFolders(): void
],
];
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('subfolders')
->with('folder_1')
@@ -381,11 +351,11 @@ public function testListSubFolders(): void
public function testListSubFoldersInNonExistingParent(): void
{
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('subfolders')
->with('non_existing_folder/non_existing_subfolder')
- ->willThrowException(new Api\NotFound());
+ ->willThrowException(new NotFound());
self::expectException(FolderNotFoundException::class);
self::expectExceptionMessage('Folder with path "non_existing_folder/non_existing_subfolder" was not found on remote.');
@@ -397,9 +367,9 @@ public function testCreateFolder(): void
{
$path = 'folder/subfolder/my_new_folder';
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('create_folder')
+ ->method('createFolder')
->with($path);
$this->apiGateway->createFolder($path);
@@ -417,9 +387,9 @@ public function testGet(): void
'secure_url' => 'https://res.cloudinary.com/demo/image/upload/folder/test_image.jpg',
];
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('resource')
+ ->method('asset')
->with(
$remoteId->getResourceId(),
[
@@ -457,9 +427,9 @@ public function testGetNotExisting(): void
{
$remoteId = CloudinaryRemoteId::fromRemoteId('upload|image|folder/test_image.jpg');
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('resource')
+ ->method('asset')
->with(
$remoteId->getResourceId(),
[
@@ -470,7 +440,7 @@ public function testGetNotExisting(): void
'exif' => true,
],
)
- ->willThrowException(new Api\NotFound());
+ ->willThrowException(new NotFound());
self::expectException(RemoteResourceNotFoundException::class);
self::expectExceptionMessage('Remote resource with ID "upload|image|folder/test_image.jpg" not found.');
@@ -534,31 +504,31 @@ public function testSearch(): void
. ' AND test* AND (folder:"test_folder") AND (tags:"tag1")';
$limit = 25;
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with($limit)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::exactly(2))
- ->method('with_field')
+ ->method('withField')
->willReturnMap(
[
- ['context', $this->cloudinarySearchMock],
- ['tags', $this->cloudinarySearchMock],
+ ['context', $this->searchApiMock],
+ ['tags', $this->searchApiMock],
],
);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -606,37 +576,37 @@ public function testSearchWithNextCursor(): void
$limit = 25;
$nextCursor = 'gfr566455fdg';
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with($limit)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::exactly(2))
- ->method('with_field')
+ ->method('withField')
->willReturnMap(
[
- ['context', $this->cloudinarySearchMock],
- ['tags', $this->cloudinarySearchMock],
+ ['context', $this->searchApiMock],
+ ['tags', $this->searchApiMock],
],
);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('next_cursor')
+ ->method('nextCursor')
->willReturn($nextCursor)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -683,21 +653,21 @@ public function testSearchCount(): void
. ' AND (!format="m4a") AND (!format="mp3") AND (!format="ogg") AND (!format="opus") AND (!format="wav")))'
. ' AND test* AND (folder:"test_folder") AND (tags:"tag1")';
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with(0)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -717,7 +687,7 @@ public function testSearchCount(): void
public function testListTags(): void
{
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::exactly(3))
->method('tags')
->willReturnMap(
@@ -786,31 +756,31 @@ public function testSearchResourceByHash(): void
. ' AND test* AND (folder:"test_folder") AND (etag="e522f43cf89aa0afd03387c37e2b6e29")';
$limit = 1;
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with($limit)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::exactly(2))
- ->method('with_field')
+ ->method('withField')
->willReturnMap(
[
- ['context', $this->cloudinarySearchMock],
- ['tags', $this->cloudinarySearchMock],
+ ['context', $this->searchApiMock],
+ ['tags', $this->searchApiMock],
],
);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -854,7 +824,7 @@ public function testGetVideoThumbnail(): void
$cloudinaryRemoteId = CloudinaryRemoteId::fromRemoteId('upload|video|media/example');
self::assertSame(
- 'https://res.cloudinary.com/testcloud/video/upload/media/example.jpg',
+ 'https://res.cloudinary.com/testcloud/video/upload/media/example',
$this->apiGateway->getVideoThumbnail($cloudinaryRemoteId),
);
}
@@ -865,7 +835,7 @@ public function testGetVideoThumbnailAuthenticated(): void
$token = AuthToken::fromExpiresAt(new DateTimeImmutable('2023/1/1'));
self::assertSame(
- 'https://res.cloudinary.com/testcloud/video/upload/media/example.jpg?__cld_token__=exp=1672531200~hmac=62ddaa466e7acbd07699201e33c8c1865b78b91365bd727f7b88ac524f02095b',
+ 'https://res.cloudinary.com/testcloud/video/upload/media/example?__cld_token__=exp=1672531200~hmac=91194b19360a54349173e96f49135838cdabd3cdb07d97eb2f12b60d8168e5cc',
$this->apiGateway->getVideoThumbnail($cloudinaryRemoteId, [], $token),
);
}
@@ -875,7 +845,7 @@ public function testGetImageTag(): void
$cloudinaryRemoteId = CloudinaryRemoteId::fromRemoteId('upload|image|media/example');
self::assertSame(
- "",
+ "",
$this->apiGateway->getImageTag($cloudinaryRemoteId),
);
}
@@ -886,7 +856,7 @@ public function testGetImageTagAuthenticated(): void
$token = AuthToken::fromExpiresAt(new DateTimeImmutable('2023/1/1'));
self::assertSame(
- "",
+ "",
$this->apiGateway->getImageTag($cloudinaryRemoteId, [], $token),
);
}
@@ -918,21 +888,18 @@ public function testGetVideoTagAuthenticated(): void
);
}
- private function getCloudinaryResponse(array $data): CloudinaryApiResponse
+ private function getCloudinaryResponse(array $data): ApiResponse
{
- $response = new stdClass();
- $response->body = json_encode($data);
- $response->responseCode = 200;
- $response->headers = [
+ $headers = [
'X-FeatureRateLimit-Reset' => 'test',
'X-FeatureRateLimit-Limit' => 'test',
'X-FeatureRateLimit-Remaining' => 'test',
];
- return new CloudinaryApiResponse($response);
+ return new ApiResponse($data, $headers);
}
- private function getSearchResponse(): CloudinaryApiResponse
+ private function getSearchResponse(): ApiResponse
{
return $this->getCloudinaryResponse([
'total_count' => 200,
diff --git a/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php b/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php
index 3928da1b..43841ca1 100644
--- a/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php
@@ -325,7 +325,7 @@ public function testGetAuthenticatedUrl(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with('[INTERNAL][FREE] getAuthenticatedUrl("upload|image|folder/test_image.jpg") -> cloudinary_url_internal("upload|image|folder/test_image.jpg")');
+ ->with('[INTERNAL][FREE] getAuthenticatedUrl("upload|image|folder/test_image.jpg") -> Media::fromParams("upload|image|folder/test_image.jpg")');
self::assertSame(
$url,
@@ -353,7 +353,7 @@ public function testGetVariationUrl(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getVariationUrl(\"{$remoteId->getRemoteId()}\") -> cloudinary_url_internal(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getVariationUrl(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'https://res.cloudinary.com/testcloud/image/upload/c_crop,h_200,w_300,x_50,y_50/folder/test_image.jpg',
@@ -523,7 +523,7 @@ public function testGetDownloadLink(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Cloudinary::cloudinary_url(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'https://cloudinary.com/test.zip',
diff --git a/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php b/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php
index 17a538eb..d075d82e 100644
--- a/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php
@@ -70,7 +70,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -92,7 +92,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -131,7 +131,7 @@ public static function dataProvider(): array
'type' => 'authenticated',
'resource_type' => 'raw',
'access_mode' => 'authenticated',
- 'access_control' => ['access_type' => 'token'],
+ 'access_control' => [['access_type' => 'token']],
'tags' => ['backup'],
],
],
@@ -163,7 +163,7 @@ public static function dataProvider(): array
'type' => 'authenticated',
'resource_type' => 'raw',
'access_mode' => 'authenticated',
- 'access_control' => ['access_type' => 'token'],
+ 'access_control' => [['access_type' => 'token']],
'tags' => ['backup', 'archive'],
],
],
@@ -184,7 +184,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -214,7 +214,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'video',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -242,7 +242,7 @@ public static function dataProvider(): array
'type' => 'authenticated',
'resource_type' => 'auto',
'access_mode' => 'authenticated',
- 'access_control' => ['access_type' => 'token'],
+ 'access_control' => [['access_type' => 'token']],
'tags' => [],
],
],
@@ -266,7 +266,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
false,
diff --git a/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php b/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php
index cf889c4f..fc6ed0e9 100644
--- a/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php
@@ -4,9 +4,9 @@
namespace Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\Verifier\Request;
-use Cloudinary;
-use Cloudinary\SignatureVerifier as CloudinarySignatureVerifier;
+use Cloudinary\Utils\SignatureVerifier as CloudinarySignatureVerifier;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Verifier\Request\Signature as SignatureVerifier;
+use Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\CloudinaryConfigurationInitializer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
@@ -17,25 +17,11 @@
#[CoversClass(SignatureVerifier::class)]
class SignatureTest extends TestCase
{
- private const CLOUD_NAME = 'testcloud';
-
- private const API_KEY = 'apikey';
-
- private const API_SECRET = 'secret';
-
private SignatureVerifier $signatureVerifier;
protected function setUp(): void
{
- $cloudinary = new Cloudinary();
- $cloudinary->config(
- [
- 'cloud_name' => self::CLOUD_NAME,
- 'api_key' => self::API_KEY,
- 'api_secret' => self::API_SECRET,
- 'cdn_subdomain' => true,
- ],
- );
+ CloudinaryConfigurationInitializer::getConfiguration();
$this->signatureVerifier = new SignatureVerifier();
}
@@ -77,7 +63,7 @@ public function testVerifyValid(): void
$timestamp = time();
$payloadToSign = $body . $timestamp;
- $signature = CloudinarySignatureVerifier::generateHmac($payloadToSign, self::API_SECRET);
+ $signature = CloudinarySignatureVerifier::generateHmac($payloadToSign, CloudinaryConfigurationInitializer::API_SECRET);
$request->headers->add(
[