|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the flysystem-bundle project. |
| 5 | + * |
| 6 | + * (c) Titouan Galopin <galopintitouan@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Tests\League\FlysystemBundle\Adapter\Builder; |
| 13 | + |
| 14 | +use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter; |
| 15 | +use League\FlysystemBundle\Adapter\Builder\GcloudAdapterDefinitionBuilder; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use Symfony\Component\DependencyInjection\Definition; |
| 18 | +use Symfony\Component\DependencyInjection\Reference; |
| 19 | + |
| 20 | +class GcloudAdapterDefinitionBuilderTest extends TestCase |
| 21 | +{ |
| 22 | + public function createBuilder() |
| 23 | + { |
| 24 | + return new GcloudAdapterDefinitionBuilder(); |
| 25 | + } |
| 26 | + |
| 27 | + public function provideValidOptions() |
| 28 | + { |
| 29 | + yield 'minimal' => [[ |
| 30 | + 'client' => 'my_client', |
| 31 | + 'bucket' => 'bucket', |
| 32 | + ]]; |
| 33 | + |
| 34 | + yield 'full' => [[ |
| 35 | + 'client' => 'my_client', |
| 36 | + 'bucket' => 'bucket', |
| 37 | + 'prefix' => 'prefix/path', |
| 38 | + ]]; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @dataProvider provideValidOptions |
| 43 | + */ |
| 44 | + public function testCreateDefinition($options) |
| 45 | + { |
| 46 | + $this->assertSame(GoogleCloudStorageAdapter::class, $this->createBuilder()->createDefinition($options)->getClass()); |
| 47 | + } |
| 48 | + |
| 49 | + public function testOptionsBehavior() |
| 50 | + { |
| 51 | + $definition = $this->createBuilder()->createDefinition([ |
| 52 | + 'client' => 'my_client', |
| 53 | + 'bucket' => 'bucket_name', |
| 54 | + 'prefix' => 'prefix/path', |
| 55 | + ]); |
| 56 | + |
| 57 | + $this->assertSame(GoogleCloudStorageAdapter::class, $definition->getClass()); |
| 58 | + |
| 59 | + /** @var Definition $bucketDefinition */ |
| 60 | + $bucketDefinition = $definition->getArgument(0); |
| 61 | + $this->assertInstanceOf(Definition::class, $bucketDefinition); |
| 62 | + $this->assertSame('bucket_name', $bucketDefinition->getArgument(0)); |
| 63 | + $this->assertInstanceOf(Reference::class, $bucketDefinition->getFactory()[0]); |
| 64 | + $this->assertSame('my_client', (string) $bucketDefinition->getFactory()[0]); |
| 65 | + $this->assertSame('bucket', $bucketDefinition->getFactory()[1]); |
| 66 | + |
| 67 | + $this->assertSame('prefix/path', $definition->getArgument(1)); |
| 68 | + } |
| 69 | +} |
0 commit comments