public function StreamWrapperTest::testAutomaticUri in AmazonS3 7.2
@covers \Drupal\amazons3\StreamWrapper::dir_opendir @covers \Drupal\amazons3\StreamWrapper::mkdir @covers \Drupal\amazons3\StreamWrapper::rename @covers \Drupal\amazons3\StreamWrapper::rmdir @covers \Drupal\amazons3\StreamWrapper::stream_open @covers \Drupal\amazons3\StreamWrapper::url_stat @covers \Drupal\amazons3\StreamWrapper::unlink
File
- tests/
StreamWrapperTest.php, line 558
Class
Namespace
Drupal\amazons3TestCode
public function testAutomaticUri() {
$wrapper = new StreamWrapper();
$path = NULL;
$uri = 's3://bucket.example.com/image.jpg';
try {
$wrapper
->stream_open($uri, 'r', 0, $path);
} catch (\PHPUnit_Framework_Error_Warning $e) {
// This throws a warning because we aren't mocking any calls, but we don't
// care because we just want to call getUri().
}
$this
->assertEquals($uri, $wrapper
->getUri());
// Instantiate the AWS service builder.
$config = array(
'includes' => array(
0 => '_aws',
),
'services' => array(
'default_settings' => array(
'params' => array(
'region' => 'us-east-1',
),
),
'cloudfront' => array(
'extends' => 'cloudfront',
'params' => array(
'private_key' => 'change_me',
'key_pair_id' => 'change_me',
),
),
),
'credentials' => array(
'key' => 'placeholder',
'secret' => 'placeholder',
),
);
$aws = \Aws\Common\Aws::factory($config);
// Configure the tests to use the instantiated AWS service builder
\Guzzle\Tests\GuzzleTestCase::setServiceBuilder($aws);
$client = $this
->getServiceBuilder()
->get('s3', true);
// The 404 is for the first check to mkdir() that checks to see if a
// directory exists.
$this
->setMockResponse($client, array(
new Response(200),
new Response(404),
new Response(200),
));
$wrapper = new StreamWrapper();
$wrapper
->setClient($client);
$wrapper
->url_stat($uri, 0);
$this
->assertEquals($uri, $wrapper
->getUri());
$dir_uri = 's3://bucket.example.com/directory';
$wrapper
->mkdir($dir_uri, 0, 0);
$this
->assertEquals($dir_uri, $wrapper
->getUri());
$this
->setMockResponse($client, array(
new Response(200),
));
$wrapper = new StreamWrapper();
$wrapper
->setClient($client);
$wrapper
->dir_opendir($dir_uri, "");
$this
->assertEquals($dir_uri, $wrapper
->getUri());
$this
->setMockResponse($client, array(
new Response(200),
));
$wrapper = new StreamWrapper();
$wrapper
->setClient($client);
$wrapper
->rmdir($dir_uri, 0);
$this
->assertEquals($dir_uri, $wrapper
->getUri());
$this
->setMockResponse($client, array(
new Response(200),
));
$wrapper = new StreamWrapper();
$wrapper
->setClient($client);
$wrapper
->unlink($uri);
$this
->assertEquals($uri, $wrapper
->getUri());
$this
->setMockResponse($client, array(
new Response(200),
new Response(200),
));
$wrapper = new StreamWrapper();
$wrapper
->setClient($client);
$wrapper
->rename($uri, 's3://bucket.example.com/renamed.jpg');
$this
->assertEquals('s3://bucket.example.com/renamed.jpg', $wrapper
->getUri());
}