From b4924ea7e6257b7c2a950f3cfd32bf153747b455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20H=C3=A9lias?= Date: Sat, 14 Oct 2023 23:23:58 +0200 Subject: [PATCH] fix: Default visibility for directories --- src/Adapter/AdapterDefinitionFactory.php | 4 +- .../AbstractAdapterDefinitionBuilder.php | 49 +++++++++++++++++-- .../AdapterDefinitionBuilderInterface.php | 2 +- .../AsyncAwsAdapterDefinitionBuilder.php | 11 ++++- .../Builder/AwsAdapterDefinitionBuilder.php | 12 +++-- .../Builder/AzureAdapterDefinitionBuilder.php | 4 +- .../Builder/FtpAdapterDefinitionBuilder.php | 8 ++- .../GcloudAdapterDefinitionBuilder.php | 4 +- .../Builder/LocalAdapterDefinitionBuilder.php | 42 +++------------- .../MemoryAdapterDefinitionBuilder.php | 2 +- .../Builder/SftpAdapterDefinitionBuilder.php | 8 ++- .../FlysystemExtension.php | 8 +-- .../Adapter/AdapterDefinitionFactoryTest.php | 4 +- .../AsyncAwsAdapterDefinitionBuilderTest.php | 11 ++--- .../AwsAdapterDefinitionBuilderTest.php | 10 ++-- .../AzureAdapterDefinitionBuilderTest.php | 8 +-- .../FtpAdapterDefinitionBuilderTest.php | 20 ++++++-- .../GcloudAdapterDefinitionBuilderTest.php | 8 +-- .../LocalAdapterDefinitionBuilderTest.php | 10 ++-- .../MemoryAdapterDefinitionBuilderTest.php | 4 +- .../SftpAdapterDefinitionBuilderTest.php | 20 ++++++-- .../FlysystemExtensionTest.php | 4 +- tests/FlysystemBundleTest.php | 2 +- tests/Kernel/EmptyAppKernel.php | 2 +- tests/Kernel/FlysystemAppKernel.php | 6 +-- tests/Kernel/FrameworkAppKernel.php | 2 +- 26 files changed, 162 insertions(+), 103 deletions(-) diff --git a/src/Adapter/AdapterDefinitionFactory.php b/src/Adapter/AdapterDefinitionFactory.php index cbef22c..f5c8d4f 100644 --- a/src/Adapter/AdapterDefinitionFactory.php +++ b/src/Adapter/AdapterDefinitionFactory.php @@ -40,11 +40,11 @@ public function __construct() ]; } - public function createDefinition(string $name, array $options): ?Definition + public function createDefinition(string $name, array $options, ?string $defaultVisibilityForDirectories): ?Definition { foreach ($this->builders as $builder) { if ($builder->getName() === $name) { - return $builder->createDefinition($options); + return $builder->createDefinition($options, $defaultVisibilityForDirectories); } } diff --git a/src/Adapter/Builder/AbstractAdapterDefinitionBuilder.php b/src/Adapter/Builder/AbstractAdapterDefinitionBuilder.php index 355dc51..56b220c 100644 --- a/src/Adapter/Builder/AbstractAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/AbstractAdapterDefinitionBuilder.php @@ -11,6 +11,7 @@ namespace League\FlysystemBundle\Adapter\Builder; +use League\Flysystem\UnixVisibility\PortableVisibilityConverter; use League\FlysystemBundle\Exception\MissingPackageException; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -22,7 +23,7 @@ */ abstract class AbstractAdapterDefinitionBuilder implements AdapterDefinitionBuilderInterface { - final public function createDefinition(array $options): Definition + final public function createDefinition(array $options, ?string $defaultVisibilityForDirectories): Definition { $this->ensureRequiredPackagesAvailable(); @@ -31,7 +32,7 @@ final public function createDefinition(array $options): Definition $definition = new Definition(); $definition->setPublic(false); - $this->configureDefinition($definition, $resolver->resolve($options)); + $this->configureDefinition($definition, $resolver->resolve($options), $defaultVisibilityForDirectories); return $definition; } @@ -40,9 +41,49 @@ abstract protected function getRequiredPackages(): array; abstract protected function configureOptions(OptionsResolver $resolver); - abstract protected function configureDefinition(Definition $definition, array $options); + abstract protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories); - private function ensureRequiredPackagesAvailable() + protected function configureUnixOptions(OptionsResolver $resolver): void + { + $resolver->setDefault('permissions', function (OptionsResolver $subResolver) { + $subResolver->setDefault('file', function (OptionsResolver $permsResolver) { + $permsResolver->setDefault('public', 0644); + $permsResolver->setAllowedTypes('public', 'scalar'); + + $permsResolver->setDefault('private', 0600); + $permsResolver->setAllowedTypes('private', 'scalar'); + }); + + $subResolver->setDefault('dir', function (OptionsResolver $permsResolver) { + $permsResolver->setDefault('public', 0755); + $permsResolver->setAllowedTypes('public', 'scalar'); + + $permsResolver->setDefault('private', 0700); + $permsResolver->setAllowedTypes('private', 'scalar'); + }); + }); + } + + protected function createUnixDefinition(array $permissions, string $defaultVisibilityForDirectories): Definition + { + return (new Definition(PortableVisibilityConverter::class)) + ->setFactory([PortableVisibilityConverter::class, 'fromArray']) + ->addArgument([ + 'file' => [ + 'public' => (int) $permissions['file']['public'], + 'private' => (int) $permissions['file']['private'], + ], + 'dir' => [ + 'public' => (int) $permissions['dir']['public'], + 'private' => (int) $permissions['dir']['private'], + ], + ]) + ->addArgument($defaultVisibilityForDirectories) + ->setShared(false) + ; + } + + private function ensureRequiredPackagesAvailable(): void { $missingPackages = []; foreach ($this->getRequiredPackages() as $requiredClass => $packageName) { diff --git a/src/Adapter/Builder/AdapterDefinitionBuilderInterface.php b/src/Adapter/Builder/AdapterDefinitionBuilderInterface.php index d36615a..385e765 100644 --- a/src/Adapter/Builder/AdapterDefinitionBuilderInterface.php +++ b/src/Adapter/Builder/AdapterDefinitionBuilderInterface.php @@ -25,5 +25,5 @@ public function getName(): string; /** * Create the definition for this builder's adapter given an array of options. */ - public function createDefinition(array $options): Definition; + public function createDefinition(array $options, ?string $defaultVisibilityForDirectories): Definition; } diff --git a/src/Adapter/Builder/AsyncAwsAdapterDefinitionBuilder.php b/src/Adapter/Builder/AsyncAwsAdapterDefinitionBuilder.php index 482dab1..99e0759 100644 --- a/src/Adapter/Builder/AsyncAwsAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/AsyncAwsAdapterDefinitionBuilder.php @@ -12,6 +12,8 @@ namespace League\FlysystemBundle\Adapter\Builder; use League\Flysystem\AsyncAwsS3\AsyncAwsS3Adapter; +use League\Flysystem\AsyncAwsS3\PortableVisibilityConverter; +use League\Flysystem\Visibility; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -36,7 +38,7 @@ protected function getRequiredPackages(): array ]; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('client'); $resolver->setAllowedTypes('client', 'string'); @@ -48,11 +50,16 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('prefix', 'string'); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $definition->setClass(AsyncAwsS3Adapter::class); $definition->setArgument(0, new Reference($options['client'])); $definition->setArgument(1, $options['bucket']); $definition->setArgument(2, $options['prefix']); + $definition->setArgument(3, + (new Definition(PortableVisibilityConverter::class)) + ->setArgument(0, $defaultVisibilityForDirectories ?? Visibility::PUBLIC) + ->setShared(false) + ); } } diff --git a/src/Adapter/Builder/AwsAdapterDefinitionBuilder.php b/src/Adapter/Builder/AwsAdapterDefinitionBuilder.php index d45e7fd..6c1e3ef 100644 --- a/src/Adapter/Builder/AwsAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/AwsAdapterDefinitionBuilder.php @@ -12,6 +12,8 @@ namespace League\FlysystemBundle\Adapter\Builder; use League\Flysystem\AwsS3V3\AwsS3V3Adapter; +use League\Flysystem\AwsS3V3\PortableVisibilityConverter; +use League\Flysystem\Visibility; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -35,7 +37,7 @@ protected function getRequiredPackages(): array ]; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('client'); $resolver->setAllowedTypes('client', 'string'); @@ -53,13 +55,17 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('streamReads', 'bool'); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $definition->setClass(AwsS3V3Adapter::class); $definition->setArgument(0, new Reference($options['client'])); $definition->setArgument(1, $options['bucket']); $definition->setArgument(2, $options['prefix']); - $definition->setArgument(3, null); + $definition->setArgument(3, + (new Definition(PortableVisibilityConverter::class)) + ->setArgument(0, $defaultVisibilityForDirectories ?? Visibility::PUBLIC) + ->setShared(false) + ); $definition->setArgument(4, null); $definition->setArgument(5, $options['options']); $definition->setArgument(6, $options['streamReads']); diff --git a/src/Adapter/Builder/AzureAdapterDefinitionBuilder.php b/src/Adapter/Builder/AzureAdapterDefinitionBuilder.php index 7443b09..c4cc9f2 100644 --- a/src/Adapter/Builder/AzureAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/AzureAdapterDefinitionBuilder.php @@ -35,7 +35,7 @@ protected function getRequiredPackages(): array ]; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('client'); $resolver->setAllowedTypes('client', 'string'); @@ -47,7 +47,7 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('prefix', 'string'); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $definition->setClass(AzureBlobStorageAdapter::class); $definition->setArgument(0, new Reference($options['client'])); diff --git a/src/Adapter/Builder/FtpAdapterDefinitionBuilder.php b/src/Adapter/Builder/FtpAdapterDefinitionBuilder.php index f10358c..953f444 100644 --- a/src/Adapter/Builder/FtpAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/FtpAdapterDefinitionBuilder.php @@ -13,6 +13,7 @@ use League\Flysystem\Ftp\FtpAdapter; use League\Flysystem\Ftp\FtpConnectionOptions; +use League\Flysystem\Visibility; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -36,7 +37,7 @@ protected function getRequiredPackages(): array ]; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('host'); $resolver->setAllowedTypes('host', 'string'); @@ -84,9 +85,11 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setDefault('connectivityChecker', null); $resolver->setAllowedTypes('connectivityChecker', ['string', 'null']); + + $this->configureUnixOptions($resolver); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $options['transferMode'] = $options['transfer_mode']; $options['systemType'] = $options['system_type']; @@ -117,5 +120,6 @@ protected function configureDefinition(Definition $definition, array $options) ); $definition->setArgument(1, null); $definition->setArgument(2, $connectivityChecker); + $definition->setArgument(3, $this->createUnixDefinition($options['permissions'], $defaultVisibilityForDirectories ?? Visibility::PRIVATE)); } } diff --git a/src/Adapter/Builder/GcloudAdapterDefinitionBuilder.php b/src/Adapter/Builder/GcloudAdapterDefinitionBuilder.php index 0594cc8..ac6fefc 100644 --- a/src/Adapter/Builder/GcloudAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/GcloudAdapterDefinitionBuilder.php @@ -35,7 +35,7 @@ protected function getRequiredPackages(): array ]; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('client'); $resolver->setAllowedTypes('client', 'string'); @@ -47,7 +47,7 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('prefix', 'string'); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $bucketDefinition = new Definition(); $bucketDefinition->setFactory([new Reference($options['client']), 'bucket']); diff --git a/src/Adapter/Builder/LocalAdapterDefinitionBuilder.php b/src/Adapter/Builder/LocalAdapterDefinitionBuilder.php index 4c342ad..707a0ec 100644 --- a/src/Adapter/Builder/LocalAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/LocalAdapterDefinitionBuilder.php @@ -12,7 +12,7 @@ namespace League\FlysystemBundle\Adapter\Builder; use League\Flysystem\Local\LocalFilesystemAdapter; -use League\Flysystem\UnixVisibility\PortableVisibilityConverter; +use League\Flysystem\Visibility; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -33,58 +33,28 @@ protected function getRequiredPackages(): array return []; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('directory'); $resolver->setAllowedTypes('directory', 'string'); + $this->configureUnixOptions($resolver); + $resolver->setDefault('lock', 0); $resolver->setAllowedTypes('lock', 'scalar'); $resolver->setDefault('skip_links', false); $resolver->setAllowedTypes('skip_links', 'scalar'); - $resolver->setDefault('permissions', function (OptionsResolver $subResolver) { - $subResolver->setDefault('file', function (OptionsResolver $permsResolver) { - $permsResolver->setDefault('public', 0644); - $permsResolver->setAllowedTypes('public', 'scalar'); - - $permsResolver->setDefault('private', 0600); - $permsResolver->setAllowedTypes('private', 'scalar'); - }); - - $subResolver->setDefault('dir', function (OptionsResolver $permsResolver) { - $permsResolver->setDefault('public', 0755); - $permsResolver->setAllowedTypes('public', 'scalar'); - - $permsResolver->setDefault('private', 0700); - $permsResolver->setAllowedTypes('private', 'scalar'); - }); - }); - $resolver->setDefault('lazy_root_creation', false); $resolver->setAllowedTypes('lazy_root_creation', 'scalar'); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $definition->setClass(LocalFilesystemAdapter::class); $definition->setArgument(0, $options['directory']); - $definition->setArgument(1, - (new Definition(PortableVisibilityConverter::class)) - ->setFactory([PortableVisibilityConverter::class, 'fromArray']) - ->addArgument([ - 'file' => [ - 'public' => (int) $options['permissions']['file']['public'], - 'private' => (int) $options['permissions']['file']['private'], - ], - 'dir' => [ - 'public' => (int) $options['permissions']['dir']['public'], - 'private' => (int) $options['permissions']['dir']['private'], - ], - ]) - ->setShared(false) - ); + $definition->setArgument(1, $this->createUnixDefinition($options['permissions'], $defaultVisibilityForDirectories ?? Visibility::PRIVATE)); $definition->setArgument(2, $options['lock']); $definition->setArgument(3, $options['skip_links'] ? LocalFilesystemAdapter::SKIP_LINKS : LocalFilesystemAdapter::DISALLOW_LINKS); $definition->setArgument(4, null); diff --git a/src/Adapter/Builder/MemoryAdapterDefinitionBuilder.php b/src/Adapter/Builder/MemoryAdapterDefinitionBuilder.php index 96c5b85..3e75dee 100644 --- a/src/Adapter/Builder/MemoryAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/MemoryAdapterDefinitionBuilder.php @@ -38,7 +38,7 @@ protected function configureOptions(OptionsResolver $resolver) { } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { $definition->setClass(InMemoryFilesystemAdapter::class); } diff --git a/src/Adapter/Builder/SftpAdapterDefinitionBuilder.php b/src/Adapter/Builder/SftpAdapterDefinitionBuilder.php index 7616a69..70c0b3f 100644 --- a/src/Adapter/Builder/SftpAdapterDefinitionBuilder.php +++ b/src/Adapter/Builder/SftpAdapterDefinitionBuilder.php @@ -15,6 +15,7 @@ use League\Flysystem\PhpseclibV2\SftpConnectionProvider as SftpConnectionProviderLegacy; use League\Flysystem\PhpseclibV3\SftpAdapter; use League\Flysystem\PhpseclibV3\SftpConnectionProvider; +use League\Flysystem\Visibility; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -49,7 +50,7 @@ protected function getRequiredPackages(): array ]; } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('host'); $resolver->setAllowedTypes('host', 'string'); @@ -89,9 +90,11 @@ protected function configureOptions(OptionsResolver $resolver) $resolver->setDefault('connectivityChecker', null); $resolver->setAllowedTypes('connectivityChecker', ['string', 'null']); + + $this->configureUnixOptions($resolver); } - protected function configureDefinition(Definition $definition, array $options) + protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void { // Prevent BC $adapterFqcn = SftpAdapter::class; @@ -113,5 +116,6 @@ protected function configureDefinition(Definition $definition, array $options) ->setShared(false) ); $definition->setArgument(1, $options['root']); + $definition->setArgument(2, $this->createUnixDefinition($options['permissions'], $defaultVisibilityForDirectories ?? Visibility::PRIVATE)); } } diff --git a/src/DependencyInjection/FlysystemExtension.php b/src/DependencyInjection/FlysystemExtension.php index a1bfaef..f8bbbc4 100644 --- a/src/DependencyInjection/FlysystemExtension.php +++ b/src/DependencyInjection/FlysystemExtension.php @@ -43,7 +43,7 @@ public function load(array $configs, ContainerBuilder $container): void $this->createStoragesDefinitions($config, $container); } - private function createStoragesDefinitions(array $config, ContainerBuilder $container) + private function createStoragesDefinitions(array $config, ContainerBuilder $container): void { $definitionFactory = new AdapterDefinitionFactory(); @@ -61,7 +61,7 @@ private function createStoragesDefinitions(array $config, ContainerBuilder $cont } // Create adapter definition - if ($adapter = $definitionFactory->createDefinition($storageConfig['adapter'], $storageConfig['options'])) { + if ($adapter = $definitionFactory->createDefinition($storageConfig['adapter'], $storageConfig['options'], $storageConfig['directory_visibility'] ?? null)) { // Native adapter $container->setDefinition('flysystem.adapter.'.$storageName, $adapter)->setPublic(false); } else { @@ -82,7 +82,7 @@ private function createStoragesDefinitions(array $config, ContainerBuilder $cont } } - private function createLazyStorageDefinition(string $storageName, array $options) + private function createLazyStorageDefinition(string $storageName, array $options): Definition { $resolver = new OptionsResolver(); $resolver->setRequired('source'); @@ -98,7 +98,7 @@ private function createLazyStorageDefinition(string $storageName, array $options return $definition; } - private function createStorageDefinition(string $storageName, Reference $adapter, array $config) + private function createStorageDefinition(string $storageName, Reference $adapter, array $config): Definition { $publicUrl = null; if ($config['public_url']) { diff --git a/tests/Adapter/AdapterDefinitionFactoryTest.php b/tests/Adapter/AdapterDefinitionFactoryTest.php index c8adc07..44cd4a7 100644 --- a/tests/Adapter/AdapterDefinitionFactoryTest.php +++ b/tests/Adapter/AdapterDefinitionFactoryTest.php @@ -18,7 +18,7 @@ class AdapterDefinitionFactoryTest extends TestCase { - public function provideConfigOptions() + public function provideConfigOptions(): \Generator { $config = Yaml::parseFile(__DIR__.'/options.yaml'); @@ -34,7 +34,7 @@ public function testCreateDefinition($name, $options) { $factory = new AdapterDefinitionFactory(); - $definition = $factory->createDefinition($name, $options); + $definition = $factory->createDefinition($name, $options, null); $this->assertInstanceOf(Definition::class, $definition); } } diff --git a/tests/Adapter/Builder/AsyncAwsAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/AsyncAwsAdapterDefinitionBuilderTest.php index 4e6f5a9..4eb93fb 100644 --- a/tests/Adapter/Builder/AsyncAwsAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/AsyncAwsAdapterDefinitionBuilderTest.php @@ -12,21 +12,19 @@ namespace Tests\League\FlysystemBundle\Adapter\Builder; use League\Flysystem\AsyncAwsS3\AsyncAwsS3Adapter; +use League\Flysystem\Visibility; use League\FlysystemBundle\Adapter\Builder\AsyncAwsAdapterDefinitionBuilder; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Reference; -/** - * @requires PHP 7.2 - */ class AsyncAwsAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): AsyncAwsAdapterDefinitionBuilder { return new AsyncAwsAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'client' => 'my_client', @@ -45,10 +43,11 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $definition = $this->createBuilder()->createDefinition($options); + $definition = $this->createBuilder()->createDefinition($options, Visibility::PRIVATE); $this->assertSame(AsyncAwsS3Adapter::class, $definition->getClass()); $this->assertInstanceOf(Reference::class, $definition->getArgument(0)); $this->assertSame('my_client', (string) $definition->getArgument(0)); $this->assertSame('bucket', $definition->getArgument(1)); + $this->assertSame(Visibility::PRIVATE, $definition->getArgument(3)->getArgument(0)); } } diff --git a/tests/Adapter/Builder/AwsAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/AwsAdapterDefinitionBuilderTest.php index 9dae597..a32a091 100644 --- a/tests/Adapter/Builder/AwsAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/AwsAdapterDefinitionBuilderTest.php @@ -12,18 +12,19 @@ namespace Tests\League\FlysystemBundle\Adapter\Builder; use League\Flysystem\AwsS3V3\AwsS3V3Adapter; +use League\Flysystem\Visibility; use League\FlysystemBundle\Adapter\Builder\AwsAdapterDefinitionBuilder; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Reference; class AwsAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): AwsAdapterDefinitionBuilder { return new AwsAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'client' => 'my_client', @@ -50,7 +51,7 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $this->assertSame(AwsS3V3Adapter::class, $this->createBuilder()->createDefinition($options)->getClass()); + $this->assertSame(AwsS3V3Adapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); } public function testOptionsBehavior() @@ -63,7 +64,7 @@ public function testOptionsBehavior() 'ServerSideEncryption' => 'AES256', ], 'streamReads' => false, - ]); + ], Visibility::PRIVATE); $this->assertSame(AwsS3V3Adapter::class, $definition->getClass()); $this->assertInstanceOf(Reference::class, $definition->getArgument(0)); @@ -72,5 +73,6 @@ public function testOptionsBehavior() $this->assertSame('prefix/path', $definition->getArgument(2)); $this->assertSame(['ServerSideEncryption' => 'AES256'], $definition->getArgument(5)); $this->assertFalse($definition->getArgument(6)); + $this->assertSame(Visibility::PRIVATE, $definition->getArgument(3)->getArgument(0)); } } diff --git a/tests/Adapter/Builder/AzureAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/AzureAdapterDefinitionBuilderTest.php index 3b3366a..3493d6c 100644 --- a/tests/Adapter/Builder/AzureAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/AzureAdapterDefinitionBuilderTest.php @@ -18,12 +18,12 @@ class AzureAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): AzureAdapterDefinitionBuilder { return new AzureAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'client' => 'my_client', @@ -42,7 +42,7 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $this->assertSame(AzureBlobStorageAdapter::class, $this->createBuilder()->createDefinition($options)->getClass()); + $this->assertSame(AzureBlobStorageAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); } public function testOptionsBehavior() @@ -51,7 +51,7 @@ public function testOptionsBehavior() 'client' => 'my_client', 'container' => 'container_name', 'prefix' => 'prefix/path', - ]); + ], null); $this->assertSame(AzureBlobStorageAdapter::class, $definition->getClass()); $this->assertInstanceOf(Reference::class, $definition->getArgument(0)); diff --git a/tests/Adapter/Builder/FtpAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/FtpAdapterDefinitionBuilderTest.php index 54e94b8..30e60f4 100644 --- a/tests/Adapter/Builder/FtpAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/FtpAdapterDefinitionBuilderTest.php @@ -12,17 +12,18 @@ namespace Tests\League\FlysystemBundle\Adapter\Builder; use League\Flysystem\Ftp\FtpAdapter; +use League\Flysystem\Visibility; use League\FlysystemBundle\Adapter\Builder\FtpAdapterDefinitionBuilder; use PHPUnit\Framework\TestCase; class FtpAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): FtpAdapterDefinitionBuilder { return new FtpAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'host' => 'ftp.example.com', @@ -49,7 +50,7 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $this->assertSame(FtpAdapter::class, $this->createBuilder()->createDefinition($options)->getClass()); + $this->assertSame(FtpAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); } public function testOptionsBehavior() @@ -65,7 +66,7 @@ public function testOptionsBehavior() 'timeout' => 30, 'ignore_passive_address' => true, 'utf8' => false, - ]); + ], Visibility::PUBLIC); $expected = [ 'port' => 21, @@ -74,6 +75,16 @@ public function testOptionsBehavior() 'ssl' => true, 'timeout' => 30, 'utf8' => false, + 'permissions' => [ + 'file' => [ + 'public' => 0644, + 'private' => 0600, + ], + 'dir' => [ + 'public' => 0755, + 'private' => 0700, + ], + ], 'host' => 'ftp.example.com', 'username' => 'username', 'password' => 'password', @@ -86,5 +97,6 @@ public function testOptionsBehavior() $this->assertSame(FtpAdapter::class, $definition->getClass()); $this->assertSame($expected, $definition->getArgument(0)->getArgument(0)); + $this->assertSame(Visibility::PUBLIC, $definition->getArgument(3)->getArgument(1)); } } diff --git a/tests/Adapter/Builder/GcloudAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/GcloudAdapterDefinitionBuilderTest.php index 664a947..6b8b741 100644 --- a/tests/Adapter/Builder/GcloudAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/GcloudAdapterDefinitionBuilderTest.php @@ -19,12 +19,12 @@ class GcloudAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): GcloudAdapterDefinitionBuilder { return new GcloudAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'client' => 'my_client', @@ -43,7 +43,7 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $this->assertSame(GoogleCloudStorageAdapter::class, $this->createBuilder()->createDefinition($options)->getClass()); + $this->assertSame(GoogleCloudStorageAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); } public function testOptionsBehavior() @@ -52,7 +52,7 @@ public function testOptionsBehavior() 'client' => 'my_client', 'bucket' => 'bucket_name', 'prefix' => 'prefix/path', - ]); + ], null); $this->assertSame(GoogleCloudStorageAdapter::class, $definition->getClass()); diff --git a/tests/Adapter/Builder/LocalAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/LocalAdapterDefinitionBuilderTest.php index 8e41d4d..1b6998a 100644 --- a/tests/Adapter/Builder/LocalAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/LocalAdapterDefinitionBuilderTest.php @@ -12,17 +12,18 @@ namespace Tests\League\FlysystemBundle\Adapter\Builder; use League\Flysystem\Local\LocalFilesystemAdapter; +use League\Flysystem\Visibility; use League\FlysystemBundle\Adapter\Builder\LocalAdapterDefinitionBuilder; use PHPUnit\Framework\TestCase; class LocalAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): LocalAdapterDefinitionBuilder { return new LocalAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'directory' => __DIR__, @@ -89,7 +90,7 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $this->assertSame(LocalFilesystemAdapter::class, $this->createBuilder()->createDefinition($options)->getClass()); + $this->assertSame(LocalFilesystemAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); } public function testOptionsBehavior() @@ -111,7 +112,7 @@ public function testOptionsBehavior() 'skip_links' => true, 'permissions' => $permissions, 'lazy_root_creation' => true, - ]); + ], Visibility::PUBLIC); $this->assertSame(LocalFilesystemAdapter::class, $definition->getClass()); $this->assertSame(__DIR__, $definition->getArgument(0)); @@ -119,5 +120,6 @@ public function testOptionsBehavior() $this->assertSame(LOCK_EX, $definition->getArgument(2)); $this->assertSame(LocalFilesystemAdapter::SKIP_LINKS, $definition->getArgument(3)); $this->assertSame(true, $definition->getArgument(5)); + $this->assertSame(Visibility::PUBLIC, $definition->getArgument(1)->getArgument(1)); } } diff --git a/tests/Adapter/Builder/MemoryAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/MemoryAdapterDefinitionBuilderTest.php index 208f727..aa24cf9 100644 --- a/tests/Adapter/Builder/MemoryAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/MemoryAdapterDefinitionBuilderTest.php @@ -17,13 +17,13 @@ class MemoryAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): MemoryAdapterDefinitionBuilder { return new MemoryAdapterDefinitionBuilder(); } public function testOptionsBehavior() { - $this->assertSame(InMemoryFilesystemAdapter::class, $this->createBuilder()->createDefinition([])->getClass()); + $this->assertSame(InMemoryFilesystemAdapter::class, $this->createBuilder()->createDefinition([], null)->getClass()); } } diff --git a/tests/Adapter/Builder/SftpAdapterDefinitionBuilderTest.php b/tests/Adapter/Builder/SftpAdapterDefinitionBuilderTest.php index ba02634..c09a735 100644 --- a/tests/Adapter/Builder/SftpAdapterDefinitionBuilderTest.php +++ b/tests/Adapter/Builder/SftpAdapterDefinitionBuilderTest.php @@ -12,17 +12,18 @@ namespace Tests\League\FlysystemBundle\Adapter\Builder; use League\Flysystem\PhpseclibV3\SftpAdapter; +use League\Flysystem\Visibility; use League\FlysystemBundle\Adapter\Builder\SftpAdapterDefinitionBuilder; use PHPUnit\Framework\TestCase; class SftpAdapterDefinitionBuilderTest extends TestCase { - public function createBuilder() + public function createBuilder(): SftpAdapterDefinitionBuilder { return new SftpAdapterDefinitionBuilder(); } - public function provideValidOptions() + public function provideValidOptions(): \Generator { yield 'minimal' => [[ 'host' => 'ftp.example.com', @@ -47,7 +48,7 @@ public function provideValidOptions() */ public function testCreateDefinition($options) { - $this->assertSame(SftpAdapter::class, $this->createBuilder()->createDefinition($options)->getClass()); + $this->assertSame(SftpAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); } public function testOptionsBehavior() @@ -65,7 +66,7 @@ public function testOptionsBehavior() 'directoryPerm' => 0755, 'permPrivate' => 0700, 'permPublic' => 0744, - ]); + ], Visibility::PUBLIC); $expected = [ 'password' => 'password', @@ -79,6 +80,16 @@ public function testOptionsBehavior() 'permPrivate' => 0700, 'permPublic' => 0744, 'connectivityChecker' => null, + 'permissions' => [ + 'file' => [ + 'public' => 0644, + 'private' => 0600, + ], + 'dir' => [ + 'public' => 0755, + 'private' => 0700, + ], + ], 'host' => 'ftp.example.com', 'username' => 'username', ]; @@ -86,5 +97,6 @@ public function testOptionsBehavior() $this->assertSame(SftpAdapter::class, $definition->getClass()); $this->assertSame($expected, $definition->getArgument(0)->getArgument(0)); $this->assertSame($expected['root'], $definition->getArgument(1)); + $this->assertSame(Visibility::PUBLIC, $definition->getArgument(2)->getArgument(1)); } } diff --git a/tests/DependencyInjection/FlysystemExtensionTest.php b/tests/DependencyInjection/FlysystemExtensionTest.php index 8f3eee7..376a551 100644 --- a/tests/DependencyInjection/FlysystemExtensionTest.php +++ b/tests/DependencyInjection/FlysystemExtensionTest.php @@ -104,7 +104,7 @@ public function testUrlGenerators() self::assertSame('https://example.org/temporary/test1.txt?expiresAt=1670846026', $fs->temporaryUrl('test1.txt', new \DateTimeImmutable('@1670846026'))); } - private function createFysystemKernel() + private function createFysystemKernel(): FlysystemAppKernel { (new Dotenv())->populate([ 'AWS_BUCKET' => 'bucket-name', @@ -126,7 +126,7 @@ private function createFysystemKernel() return $kernel; } - private function getClientMocks() + private function getClientMocks(): array { $gcloud = $this->createMock(StorageClient::class); $gcloud->method('bucket')->willReturn($this->createMock(Bucket::class)); diff --git a/tests/FlysystemBundleTest.php b/tests/FlysystemBundleTest.php index 5d3634e..dadcda5 100644 --- a/tests/FlysystemBundleTest.php +++ b/tests/FlysystemBundleTest.php @@ -18,7 +18,7 @@ class FlysystemBundleTest extends TestCase { - public function provideKernels() + public function provideKernels(): \Generator { yield 'empty' => [new EmptyAppKernel('test', true)]; yield 'framework' => [new FrameworkAppKernel('test', true)]; diff --git a/tests/Kernel/EmptyAppKernel.php b/tests/Kernel/EmptyAppKernel.php index 7ff0dd8..05c2010 100644 --- a/tests/Kernel/EmptyAppKernel.php +++ b/tests/Kernel/EmptyAppKernel.php @@ -25,7 +25,7 @@ public function registerBundles(): iterable return [new FlysystemBundle()]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(function (ContainerBuilder $container) { $container->loadFromExtension('flysystem', [ diff --git a/tests/Kernel/FlysystemAppKernel.php b/tests/Kernel/FlysystemAppKernel.php index 3b05dfc..0993f1d 100644 --- a/tests/Kernel/FlysystemAppKernel.php +++ b/tests/Kernel/FlysystemAppKernel.php @@ -22,14 +22,14 @@ class FlysystemAppKernel extends Kernel { use AppKernelTrait; - private $adapterClients = []; + private array $adapterClients = []; public function registerBundles(): iterable { return [new FrameworkBundle(), new FlysystemBundle()]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $adapterClients = $this->adapterClients; @@ -48,7 +48,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) } } - public function setAdapterClients(array $adapterClients) + public function setAdapterClients(array $adapterClients): void { $this->adapterClients = $adapterClients; } diff --git a/tests/Kernel/FrameworkAppKernel.php b/tests/Kernel/FrameworkAppKernel.php index bb9d0fa..042f75d 100644 --- a/tests/Kernel/FrameworkAppKernel.php +++ b/tests/Kernel/FrameworkAppKernel.php @@ -26,7 +26,7 @@ public function registerBundles(): iterable return [new FrameworkBundle(), new FlysystemBundle()]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(function (ContainerBuilder $container) { $container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);