Skip to content

Commit

Permalink
Perform cleanup and fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Randy Čupić committed Sep 17, 2024
1 parent 0092831 commit 026e7c4
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 232 deletions.
2 changes: 1 addition & 1 deletion bundle/Command/ShowApiUsageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($this->getPrettyKey($key) . ': <comment>' . $value . '</comment>');
}

return 0;
return Command::SUCCESS;
}

private function getPrettyKey(string $key): string
Expand Down
26 changes: 9 additions & 17 deletions lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
6 changes: 3 additions & 3 deletions lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary;

use Cloudinary\Configuration\Configuration;

final class CloudinaryConfigurationInitializer
{
public const CLOUD_NAME = 'testcloud';

public const API_KEY = 'apikey';

public const API_SECRET = 'apisecret';

public const UPLOAD_PREFIX = 'https://api.cloudinary.com';

public const ENCRYPTION_KEY = '38128319a3a49e1d589a31a217e1a3f8';

public static function getConfiguration(): Configuration
{
return Configuration::instance([
'cloud_name' => self::CLOUD_NAME,
'api_key' => self::API_KEY,
'api_secret' => self::API_SECRET,
'upload_prefix' => self::UPLOAD_PREFIX,
'cdn_subdomain' => false,
'force_version' => false,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']]],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\Factory;

use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryConfiguration as CloudinaryConfigurationFactory;
use Netgen\RemoteMedia\Tests\AbstractTestCase;
use Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\CloudinaryConfigurationInitializer;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(CloudinaryConfigurationFactory::class)]
final class CloudinaryConfigurationTest extends AbstractTestCase
{
protected CloudinaryConfigurationFactory $cloudinaryConfigurationFactory;

protected function setUp(): void
{
$this->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(),
);
}
}

This file was deleted.

43 changes: 25 additions & 18 deletions tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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' => [
Expand All @@ -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',
Expand Down Expand Up @@ -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' => [
Expand All @@ -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',
Expand Down Expand Up @@ -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' => [],
Expand All @@ -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',
Expand Down Expand Up @@ -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' => [
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Loading

0 comments on commit 026e7c4

Please sign in to comment.