class S3Test in Flysystem - S3 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/Flysystem/S3Test.php \NoDrupal\Tests\flysystem_s3\Unit\Flysystem\S3Test
@coversDefaultClass \Drupal\flysystem_s3\Flysystem\S3 @covers \Drupal\flysystem_s3\Flysystem\S3 @group flysystem_s3
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \NoDrupal\Tests\flysystem_s3\Unit\Flysystem\S3Test
Expanded class hierarchy of S3Test
File
- tests/
src/ Unit/ Flysystem/ S3Test.php, line 24
Namespace
NoDrupal\Tests\flysystem_s3\Unit\FlysystemView source
class S3Test extends UnitTestCase {
public function test() {
$configuration = [
'bucket' => 'example-bucket',
'prefix' => 'test prefix',
'cname' => 'example.com',
];
$client = new S3Client([
'version' => 'latest',
'region' => 'beep',
'credentials' => new Credentials('fsdf', 'sfsdf'),
]);
$plugin = new S3($client, new Config($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'] = '';
$plugin = new S3($client, new Config($configuration));
$this
->assertSame('http://example.com/foo%201.html', $plugin
->getExternalUrl('s3://foo 1.html'));
}
/**
* Tests merging defaults into configuration arrays.
*/
public function testMergeConfiguration() {
$container = new ContainerBuilder();
$container
->set('request_stack', new RequestStack());
$container
->get('request_stack')
->push(Request::create('https://example.com/'));
$configuration = [
'key' => 'fee',
'secret' => 'fo',
'region' => 'eu-west-1',
'bucket' => 'example-bucket',
];
$configuration = S3::mergeConfiguration($container, $configuration);
$this
->assertSame('https', $configuration['protocol']);
$client_config = S3::mergeClientConfiguration($container, $configuration);
$this
->assertSame('eu-west-1', $client_config['region']);
$this
->assertNull($client_config['endpoint']);
$this
->assertInstanceOf(Credentials::class, $client_config['credentials']);
}
public function testCreate() {
$container = new ContainerBuilder();
$container
->set('request_stack', new RequestStack());
$container
->get('request_stack')
->push(Request::create('https://example.com/'));
$configuration = [
'key' => 'fee',
'secret' => 'fo',
'region' => 'eu-west-1',
'bucket' => 'example-bucket',
];
$plugin = S3::create($container, $configuration, '', '');
$this
->assertInstanceOf(S3::class, $plugin);
}
public function testCreateUsingNonAwsConfiguration() {
$container = new ContainerBuilder();
$container
->set('request_stack', new RequestStack());
$container
->get('request_stack')
->push(Request::create('https://example.com/'));
$configuration = [
'key' => 'fee',
'secret' => 'fo',
'region' => 'eu-west-1',
'cname' => 'something.somewhere.tld',
'endpoint' => 'https://api.somewhere.tld',
];
$plugin = S3::create($container, $configuration, '', '');
$this
->assertSame('https://something.somewhere.tld/foo%201.html', $plugin
->getExternalUrl('s3://foo 1.html'));
$this
->assertSame('https://api.somewhere.tld', (string) $plugin
->getAdapter()
->getClient()
->getEndpoint());
}
public function testCreateUsingNonAwsConfigurationWithBucket() {
$container = new ContainerBuilder();
$container
->set('request_stack', new RequestStack());
$container
->get('request_stack')
->push(Request::create('http://example.com/'));
$configuration = [
'key' => 'foo',
'secret' => 'bar',
'cname' => 'storage.example.com',
'cname_is_bucket' => FALSE,
'bucket' => 'my-bucket',
'endpoint' => 'https://api.somewhere.tld',
];
$plugin = S3::create($container, $configuration, '', '');
$this
->assertSame('http://storage.example.com/my-bucket/foo%201.html', $plugin
->getExternalUrl('s3://foo 1.html'));
$this
->assertSame('https://api.somewhere.tld', (string) $plugin
->getAdapter()
->getClient()
->getEndpoint());
}
public function testEmptyCnameDoesNotBreakConfiguration() {
$configuration = [
'cname' => NULL,
'bucket' => 'my-bucket',
];
$plugin = new S3($this
->createMock(S3ClientInterface::class), new Config($configuration));
$this
->assertSame('http://s3.amazonaws.com/my-bucket/foo.html', $plugin
->getExternalUrl('s3://foo.html'));
}
public function testEnsure() {
$client = $this
->prophesize(S3ClientInterface::class);
$client
->doesBucketExist(Argument::type('string'))
->willReturn(TRUE);
$plugin = new S3($client
->reveal(), new Config([
'bucket' => 'example-bucket',
]));
$this
->assertSame([], $plugin
->ensure());
$client
->doesBucketExist(Argument::type('string'))
->willReturn(FALSE);
$plugin = new S3($client
->reveal(), new Config([
'bucket' => 'example-bucket',
]));
$result = $plugin
->ensure();
$this
->assertSame(1, count($result));
$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, '', '');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
S3Test:: |
public | function | ||
S3Test:: |
public | function | ||
S3Test:: |
public | function | ||
S3Test:: |
public | function | ||
S3Test:: |
public | function | ||
S3Test:: |
public | function | ||
S3Test:: |
public | function | ||
S3Test:: |
public | function | Tests merging defaults into configuration arrays. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |