Loading src/Flysystem/S3.php +2 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\flysystem_s3\Flysystem; use Aws\Credentials\Credentials; use Aws\S3\S3Client; use Aws\S3\Exception\S3Exception; use Aws\S3\S3ClientInterface; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; Loading Loading @@ -77,7 +78,7 @@ class S3 implements FlysystemPluginInterface, ContainerFactoryPluginInterface { * @param \League\Flysystem\Config $config * The configuration. */ public function __construct(S3Client $client, Config $config) { public function __construct(S3ClientInterface $client, Config $config) { $this->client = $client; $this->bucket = $config->get('bucket', ''); $this->prefix = $config->get('prefix', ''); Loading src/S3CorsManagedFileHelper.php +4 −2 Original line number Diff line number Diff line Loading @@ -13,9 +13,11 @@ class S3CorsManagedFileHelper { * Function alterInfo called by hook_element_info_alter(). */ public static function alterInfo(array &$types) { if (isset($types['managed_file'])) { array_unshift($types['managed_file']['#process'], [get_called_class(), 'preProcessCors']); $types['managed_file']['#process'][] = [get_called_class(), 'postProcessCors']; } } /** * Function preProcessCors prepare the field to use CORS upload. Loading src/Tests/ModuleInstallUninstallWebTest.php→tests/src/Functional/ModuleInstallUninstallWebTest.php +2 −2 Original line number Diff line number Diff line <?php namespace Drupal\flysystem_s3\Tests; namespace Drupal\Tests\flysystem_s3\Functional; use Drupal\flysystem\Tests\ModuleInstallUninstallWebTest as Base; use Drupal\Tests\flysystem\Functional\ModuleInstallUninstallWebTest as Base; /** * Tests module installation and uninstallation. Loading tests/src/Unit/AwsCacheAdapterTest.php +3 −2 Original line number Diff line number Diff line <?php namespace NoDrupal\Tests\flysystem_s3\Unit; namespace Drupal\Tests\flysystem_s3\Unit; use Drupal\flysystem_s3\AwsCacheAdapter; use Drupal\Core\Cache\MemoryBackend; use PHPUnit\Framework\Testcase; /** * @coversDefaultClass \Drupal\flysystem_s3\AwsCacheAdapter * @covers \Drupal\flysystem_s3\AwsCacheAdapter * @group flysystem_s3 */ class AwsCacheAdapterTest extends \PHPUnit_Framework_TestCase { class AwsCacheAdapterTest extends Testcase { /** * Loading tests/src/Unit/Flysystem/S3Test.php +57 −26 Original line number Diff line number Diff line <?php namespace NoDrupal\Tests\flysystem_s3\Unit\Flysystem; namespace Drupal\Tests\flysystem_s3\Unit\Flysystem; use Aws\Credentials\Credentials; use Aws\S3\S3Client; Loading @@ -23,33 +23,38 @@ use Symfony\Component\HttpFoundation\RequestStack; */ class S3Test extends UnitTestCase { public function test() { $configuration = [ /** * @covers ::__construct * @covers ::getExternalUrl */ public function testGetExternalUrl() { $configuration = new Config([ 'bucket' => 'example-bucket', 'prefix' => 'test prefix', 'cname' => 'example.com', ]; 'prefix' => 'test prefix', 'public' => TRUE, ]); $client = new S3Client([ 'version' => 'latest', 'region' => 'beep', 'credentials' => new Credentials('fsdf', 'sfsdf'), 'credentials' => new Credentials('foo', 'bar'), ]); $plugin = new S3($client, new Config($configuration)); $plugin = new S3($client, $configuration); $this->assertInstanceOf(AdapterInterface::class, $plugin->getAdapter()); $this->assertSame('http://example.com/test%20prefix/foo%201.html', $plugin->getExternalUrl('s3://foo 1.html')); $configuration['prefix'] = ''; $configuration->set('prefix', ''); $plugin = new S3($client, new Config($configuration)); $plugin = new S3($client, $configuration); $this->assertSame('http://example.com/foo%201.html', $plugin->getExternalUrl('s3://foo 1.html')); } /** * Tests merging defaults into configuration arrays. * @covers ::mergeConfiguration * @covers ::mergeClientConfiguration */ public function testMergeConfiguration() { $container = new ContainerBuilder(); Loading @@ -72,6 +77,9 @@ class S3Test extends UnitTestCase { $this->assertInstanceOf(Credentials::class, $client_config['credentials']); } /** * @covers ::create */ public function testCreate() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); Loading @@ -88,6 +96,10 @@ class S3Test extends UnitTestCase { $this->assertInstanceOf(S3::class, $plugin); } /** * @covers ::create * @covers ::getAdapter */ public function testCreateUsingNonAwsConfiguration() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); Loading @@ -99,6 +111,7 @@ class S3Test extends UnitTestCase { 'region' => 'eu-west-1', 'cname' => 'something.somewhere.tld', 'endpoint' => 'https://api.somewhere.tld', 'public' => TRUE, ]; $plugin = S3::create($container, $configuration, '', ''); Loading @@ -106,6 +119,11 @@ class S3Test extends UnitTestCase { $this->assertSame('https://api.somewhere.tld', (string) $plugin->getAdapter()->getClient()->getEndpoint()); } /** * @covers ::create * @covers ::getExternalUrl * @covers ::getAdapter */ public function testCreateUsingNonAwsConfigurationWithBucket() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); Loading @@ -118,6 +136,7 @@ class S3Test extends UnitTestCase { 'cname_is_bucket' => FALSE, 'bucket' => 'my-bucket', 'endpoint' => 'https://api.somewhere.tld', 'public' => TRUE, ]; $plugin = S3::create($container, $configuration, '', ''); Loading @@ -125,20 +144,43 @@ class S3Test extends UnitTestCase { $this->assertSame('https://api.somewhere.tld', (string) $plugin->getAdapter()->getClient()->getEndpoint()); } /** * @covers ::__construct * @covers ::getExternalUrl */ public function testEmptyCnameDoesNotBreakConfiguration() { $configuration = [ $configuration = new Config([ 'cname' => NULL, 'bucket' => 'my-bucket', ]; 'public' => TRUE, ]); $plugin = new S3($this->createMock(S3ClientInterface::class), new Config($configuration)); $client = new S3Client([ 'version' => 'latest', 'region' => 'beep', 'credentials' => new Credentials('fsdf', 'sfsdf'), ]); $plugin = new S3($client, $configuration); $this->assertSame('http://s3.amazonaws.com/my-bucket/foo.html', $plugin->getExternalUrl('s3://foo.html')); } /** * @covers ::ensure */ public function testEnsure() { $configuration = new Config([ 'cname' => NULL, 'bucket' => 'my-bucket', 'public' => TRUE, ]); $client = $this->prophesize(S3ClientInterface::class); $client->willImplement(S3ClientInterface::class); $client->doesBucketExist(Argument::type('string'))->willReturn(TRUE); $plugin = new S3($client->reveal(), new Config(['bucket' => 'example-bucket'])); $client->getPaginator('ListObjects', Argument::type('array')) ->willReturn([]); $plugin = new S3($client->reveal(), $configuration); $this->assertSame([], $plugin->ensure()); Loading @@ -150,15 +192,4 @@ class S3Test extends UnitTestCase { $this->assertSame(RfcLogLevel::ERROR, $result[0]['severity']); } public function testIamAuth() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); $container->get('request_stack')->push(Request::create('https://example.com/')); $container->set('cache.default', new MemoryBackend('bin')); $configuration = ['bucket' => 'example-bucket']; $plugin = S3::create($container, $configuration, '', ''); } } Loading
src/Flysystem/S3.php +2 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\flysystem_s3\Flysystem; use Aws\Credentials\Credentials; use Aws\S3\S3Client; use Aws\S3\Exception\S3Exception; use Aws\S3\S3ClientInterface; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; Loading Loading @@ -77,7 +78,7 @@ class S3 implements FlysystemPluginInterface, ContainerFactoryPluginInterface { * @param \League\Flysystem\Config $config * The configuration. */ public function __construct(S3Client $client, Config $config) { public function __construct(S3ClientInterface $client, Config $config) { $this->client = $client; $this->bucket = $config->get('bucket', ''); $this->prefix = $config->get('prefix', ''); Loading
src/S3CorsManagedFileHelper.php +4 −2 Original line number Diff line number Diff line Loading @@ -13,9 +13,11 @@ class S3CorsManagedFileHelper { * Function alterInfo called by hook_element_info_alter(). */ public static function alterInfo(array &$types) { if (isset($types['managed_file'])) { array_unshift($types['managed_file']['#process'], [get_called_class(), 'preProcessCors']); $types['managed_file']['#process'][] = [get_called_class(), 'postProcessCors']; } } /** * Function preProcessCors prepare the field to use CORS upload. Loading
src/Tests/ModuleInstallUninstallWebTest.php→tests/src/Functional/ModuleInstallUninstallWebTest.php +2 −2 Original line number Diff line number Diff line <?php namespace Drupal\flysystem_s3\Tests; namespace Drupal\Tests\flysystem_s3\Functional; use Drupal\flysystem\Tests\ModuleInstallUninstallWebTest as Base; use Drupal\Tests\flysystem\Functional\ModuleInstallUninstallWebTest as Base; /** * Tests module installation and uninstallation. Loading
tests/src/Unit/AwsCacheAdapterTest.php +3 −2 Original line number Diff line number Diff line <?php namespace NoDrupal\Tests\flysystem_s3\Unit; namespace Drupal\Tests\flysystem_s3\Unit; use Drupal\flysystem_s3\AwsCacheAdapter; use Drupal\Core\Cache\MemoryBackend; use PHPUnit\Framework\Testcase; /** * @coversDefaultClass \Drupal\flysystem_s3\AwsCacheAdapter * @covers \Drupal\flysystem_s3\AwsCacheAdapter * @group flysystem_s3 */ class AwsCacheAdapterTest extends \PHPUnit_Framework_TestCase { class AwsCacheAdapterTest extends Testcase { /** * Loading
tests/src/Unit/Flysystem/S3Test.php +57 −26 Original line number Diff line number Diff line <?php namespace NoDrupal\Tests\flysystem_s3\Unit\Flysystem; namespace Drupal\Tests\flysystem_s3\Unit\Flysystem; use Aws\Credentials\Credentials; use Aws\S3\S3Client; Loading @@ -23,33 +23,38 @@ use Symfony\Component\HttpFoundation\RequestStack; */ class S3Test extends UnitTestCase { public function test() { $configuration = [ /** * @covers ::__construct * @covers ::getExternalUrl */ public function testGetExternalUrl() { $configuration = new Config([ 'bucket' => 'example-bucket', 'prefix' => 'test prefix', 'cname' => 'example.com', ]; 'prefix' => 'test prefix', 'public' => TRUE, ]); $client = new S3Client([ 'version' => 'latest', 'region' => 'beep', 'credentials' => new Credentials('fsdf', 'sfsdf'), 'credentials' => new Credentials('foo', 'bar'), ]); $plugin = new S3($client, new Config($configuration)); $plugin = new S3($client, $configuration); $this->assertInstanceOf(AdapterInterface::class, $plugin->getAdapter()); $this->assertSame('http://example.com/test%20prefix/foo%201.html', $plugin->getExternalUrl('s3://foo 1.html')); $configuration['prefix'] = ''; $configuration->set('prefix', ''); $plugin = new S3($client, new Config($configuration)); $plugin = new S3($client, $configuration); $this->assertSame('http://example.com/foo%201.html', $plugin->getExternalUrl('s3://foo 1.html')); } /** * Tests merging defaults into configuration arrays. * @covers ::mergeConfiguration * @covers ::mergeClientConfiguration */ public function testMergeConfiguration() { $container = new ContainerBuilder(); Loading @@ -72,6 +77,9 @@ class S3Test extends UnitTestCase { $this->assertInstanceOf(Credentials::class, $client_config['credentials']); } /** * @covers ::create */ public function testCreate() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); Loading @@ -88,6 +96,10 @@ class S3Test extends UnitTestCase { $this->assertInstanceOf(S3::class, $plugin); } /** * @covers ::create * @covers ::getAdapter */ public function testCreateUsingNonAwsConfiguration() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); Loading @@ -99,6 +111,7 @@ class S3Test extends UnitTestCase { 'region' => 'eu-west-1', 'cname' => 'something.somewhere.tld', 'endpoint' => 'https://api.somewhere.tld', 'public' => TRUE, ]; $plugin = S3::create($container, $configuration, '', ''); Loading @@ -106,6 +119,11 @@ class S3Test extends UnitTestCase { $this->assertSame('https://api.somewhere.tld', (string) $plugin->getAdapter()->getClient()->getEndpoint()); } /** * @covers ::create * @covers ::getExternalUrl * @covers ::getAdapter */ public function testCreateUsingNonAwsConfigurationWithBucket() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); Loading @@ -118,6 +136,7 @@ class S3Test extends UnitTestCase { 'cname_is_bucket' => FALSE, 'bucket' => 'my-bucket', 'endpoint' => 'https://api.somewhere.tld', 'public' => TRUE, ]; $plugin = S3::create($container, $configuration, '', ''); Loading @@ -125,20 +144,43 @@ class S3Test extends UnitTestCase { $this->assertSame('https://api.somewhere.tld', (string) $plugin->getAdapter()->getClient()->getEndpoint()); } /** * @covers ::__construct * @covers ::getExternalUrl */ public function testEmptyCnameDoesNotBreakConfiguration() { $configuration = [ $configuration = new Config([ 'cname' => NULL, 'bucket' => 'my-bucket', ]; 'public' => TRUE, ]); $plugin = new S3($this->createMock(S3ClientInterface::class), new Config($configuration)); $client = new S3Client([ 'version' => 'latest', 'region' => 'beep', 'credentials' => new Credentials('fsdf', 'sfsdf'), ]); $plugin = new S3($client, $configuration); $this->assertSame('http://s3.amazonaws.com/my-bucket/foo.html', $plugin->getExternalUrl('s3://foo.html')); } /** * @covers ::ensure */ public function testEnsure() { $configuration = new Config([ 'cname' => NULL, 'bucket' => 'my-bucket', 'public' => TRUE, ]); $client = $this->prophesize(S3ClientInterface::class); $client->willImplement(S3ClientInterface::class); $client->doesBucketExist(Argument::type('string'))->willReturn(TRUE); $plugin = new S3($client->reveal(), new Config(['bucket' => 'example-bucket'])); $client->getPaginator('ListObjects', Argument::type('array')) ->willReturn([]); $plugin = new S3($client->reveal(), $configuration); $this->assertSame([], $plugin->ensure()); Loading @@ -150,15 +192,4 @@ class S3Test extends UnitTestCase { $this->assertSame(RfcLogLevel::ERROR, $result[0]['severity']); } public function testIamAuth() { $container = new ContainerBuilder(); $container->set('request_stack', new RequestStack()); $container->get('request_stack')->push(Request::create('https://example.com/')); $container->set('cache.default', new MemoryBackend('bin')); $configuration = ['bucket' => 'example-bucket']; $plugin = S3::create($container, $configuration, '', ''); } }