forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDistributionS3Test.php
More file actions
104 lines (94 loc) · 3.21 KB
/
Copy pathCreateDistributionS3Test.php
File metadata and controls
104 lines (94 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/*
Relies on PHPUnit to test the functionality in ./CreateDistributionS3.php.
Related custom constants are defined in ./phpunit.xml.
Example PHPUnit run command from this file's parent directory:
./vendor/bin/phpunit --testsuite cloudfront-createdistributions3
*/
namespace Cloudfront;
use Aws\CloudFront\CloudFrontClient;
use Aws\MockHandler;
use Aws\Result;
use PHPUnit\Framework\TestCase;
class CreateDistributionS3Test extends TestCase
{
public function testCreatesAnS3Distribution()
{
require(__DIR__ . '/../CreateDistributionS3.php');
$originName = 'my-unique-origin-name';
$s3BucketURL = 'amzn-s3-demo-bucket.s3.amazonaws.com';
$callerReference = 'my-unique-caller-reference';
$comment = 'my-comment-about-this-distribution';
$defaultCacheBehavior = [
'AllowedMethods' => [
'CachedMethods' => [
'Items' => ['HEAD', 'GET'],
'Quantity' => 2
],
'Items' => ['HEAD', 'GET'],
'Quantity' => 2
],
'Compress' => false,
'DefaultTTL' => 0,
'FieldLevelEncryptionId' => '',
'ForwardedValues' => [
'Cookies' => [
'Forward' => 'none'
],
'Headers' => [
'Quantity' => 0
],
'QueryString' => false,
'QueryStringCacheKeys' => [
'Quantity' => 0
],
],
'LambdaFunctionAssociations' => ['Quantity' => 0],
'MaxTTL' => 0,
'MinTTL' => 0,
'SmoothStreaming' => false,
'TargetOriginId' => $originName,
'TrustedSigners' => [
'Enabled' => false,
'Quantity' => 0
],
'ViewerProtocolPolicy' => 'allow-all'
];
$enabled = false;
$origin = [
'Items' => [
[
'DomainName' => $s3BucketURL,
'Id' => $originName,
'OriginPath' => '',
'CustomHeaders' => ['Quantity' => 0],
'S3OriginConfig' => ['OriginAccessIdentity' => '']
]
],
'Quantity' => 1
];
$distribution = [
'CallerReference' => $callerReference,
'Comment' => $comment,
'DefaultCacheBehavior' => $defaultCacheBehavior,
'Enabled' => $enabled,
'Origins' => $origin
];
$mock = new MockHandler();
$mock->append(new Result(array(true)));
$cloudFrontClient = new CloudFrontClient([
'profile' => AWS_PROFILE,
'version' => CLOUDFRONT_VERSION,
'region' => AWS_REGION,
'handler' => $mock
]);
$result = createS3Distribution($cloudFrontClient, $distribution);
$this->assertStringContainsString(
'https://cloudfront.amazonaws.com/' .
CLOUDFRONT_VERSION . '/distribution',
$result
);
}
}