Skip to content

Commit 9fa2986

Browse files
committed
Add service tagged collection test
1 parent c8e55b6 commit 9fa2986

6 files changed

Lines changed: 48 additions & 3 deletions

File tree

src/DependencyInjection/Compiler/LazyFactoryPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

19+
/**
20+
* @author Titouan Galopin <galopintitouan@gmail.com>
21+
*
22+
* @internal
23+
*/
1924
class LazyFactoryPass implements CompilerPassInterface
2025
{
2126
/**

src/DependencyInjection/Compiler/PluginPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

19+
/**
20+
* @author BoShurik <boshurik@gmail.com>
21+
*
22+
* @internal
23+
*/
1924
class PluginPass implements CompilerPassInterface
2025
{
2126
/**

src/DependencyInjection/FlysystemExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private function createLazyStorageDefinition(string $storageName, array $options
9090
$definition->setFactory([new Reference('flysystem.adapter.lazy.factory'), 'createStorage']);
9191
$definition->setArgument(0, $resolver->resolve($options)['source']);
9292
$definition->setArgument(1, $storageName);
93+
$definition->addTag('flysystem.storage', ['storage' => $storageName]);
9394

9495
return $definition;
9596
}

tests/DependencyInjection/FlysytemExtensionTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ public function provideFilesystems()
5353
* @dataProvider provideFilesystems
5454
*/
5555
public function testFileystems(string $fsName)
56+
{
57+
$kernel = $this->createFysystemKernel();
58+
$fs = $kernel->getContainer()->get('flysystem.test.'.$fsName);
59+
60+
$this->assertInstanceOf(FilesystemInterface::class, $fs, 'Filesystem "'.$fsName.'" should be an instance of FilesystemInterface');
61+
$this->assertEquals('plugin', $fs->pluginTest());
62+
}
63+
64+
/**
65+
* @dataProvider provideFilesystems
66+
*/
67+
public function testTaggedCollection(string $fsName)
68+
{
69+
$kernel = $this->createFysystemKernel();
70+
71+
if (!$kernel->getContainer()->has('storages_tagged_collection')) {
72+
$this->markTestSkipped('Symfony 4.3+ is required to use indexed tagged service collections');
73+
}
74+
75+
$storages = iterator_to_array($kernel->getContainer()->get('storages_tagged_collection')->locator);
76+
77+
$this->assertInstanceOf(FilesystemInterface::class, $storages[$fsName]);
78+
$this->assertEquals('plugin', $storages[$fsName]->pluginTest());
79+
}
80+
81+
private function createFysystemKernel()
5682
{
5783
(new Dotenv())->populate([
5884
'AWS_BUCKET' => 'bucket-name',
@@ -69,9 +95,7 @@ public function testFileystems(string $fsName)
6995
$container->set($service, $mock);
7096
}
7197

72-
$fs = $container->get('flysystem.test.'.$fsName);
73-
$this->assertInstanceOf(FilesystemInterface::class, $fs, 'Filesystem "'.$fsName.'" should be an instance of FilesystemInterface');
74-
$this->assertEquals('plugin', $fs->pluginTest());
98+
return $kernel;
7599
}
76100

77101
private function getClientMocks()

tests/Kernel/FlysystemAppKernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function registerContainerConfiguration(LoaderInterface $loader)
4242
$loader->load(__DIR__.'/config/framework.yaml', 'yaml');
4343
$loader->load(__DIR__.'/config/flysystem.yaml', 'yaml');
4444
$loader->load(__DIR__.'/config/services.yaml', 'yaml');
45+
46+
if (self::VERSION_ID > 40300) {
47+
$loader->load(__DIR__.'/config/tagged_collection.yaml', 'yaml');
48+
}
4549
}
4650

4751
public function setAdapterClients(array $adapterClients)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
storages_tagged_collection:
3+
class: 'stdClass'
4+
public: true
5+
properties:
6+
locator: !tagged { tag: 'flysystem.storage', index_by: 'storage' }

0 commit comments

Comments
 (0)