|
| 1 | +<?php |
| 2 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +namespace AwsUtilities; |
| 6 | + |
| 7 | +use Aws\CommandInterface; |
| 8 | +use Aws\S3\S3Client; |
| 9 | + |
| 10 | +/** |
| 11 | + * This class allows you to mock any AWSClient even when PHPUnit fails due to hidden, dynamic, or private |
| 12 | + * method calls which cannot be mocked normally. |
| 13 | + * |
| 14 | + * WARNING: This class *does not* do any type checking, so if you set the return values to an incompatible data type, |
| 15 | + * your tests will fail spectacularly. |
| 16 | + */ |
| 17 | +class MockS3Client extends S3Client { |
| 18 | + |
| 19 | + protected array $returnValues = []; |
| 20 | + |
| 21 | + public function set($methodName, $returnValue){ |
| 22 | + $this->returnValues[$methodName] = $returnValue; |
| 23 | + } |
| 24 | + |
| 25 | + public function __construct() |
| 26 | + { |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + public function __call($name, array $arguments) |
| 31 | + { |
| 32 | + return $this->returnValues[__FUNCTION__]; |
| 33 | + } |
| 34 | + |
| 35 | + public function getCommand($name, array $args = []) |
| 36 | + { |
| 37 | + return $this->returnValues[__FUNCTION__]; |
| 38 | + } |
| 39 | + |
| 40 | + public function execute(CommandInterface $command) |
| 41 | + { |
| 42 | + return $this->returnValues[__FUNCTION__]; |
| 43 | + } |
| 44 | + |
| 45 | + public function executeAsync(CommandInterface $command) |
| 46 | + { |
| 47 | + return $this->returnValues[__FUNCTION__]; |
| 48 | + } |
| 49 | + |
| 50 | + public function getCredentials() |
| 51 | + { |
| 52 | + return $this->returnValues[__FUNCTION__]; |
| 53 | + } |
| 54 | + |
| 55 | + public function getRegion() |
| 56 | + { |
| 57 | + return $this->returnValues[__FUNCTION__]; |
| 58 | + } |
| 59 | + |
| 60 | + public function getEndpoint() |
| 61 | + { |
| 62 | + return $this->returnValues[__FUNCTION__]; |
| 63 | + } |
| 64 | + |
| 65 | + public function getApi() |
| 66 | + { |
| 67 | + return $this->returnValues[__FUNCTION__]; |
| 68 | + } |
| 69 | + |
| 70 | + public function getConfig($option = null) |
| 71 | + { |
| 72 | + return $this->returnValues[__FUNCTION__]; |
| 73 | + } |
| 74 | + |
| 75 | + public function getHandlerList() |
| 76 | + { |
| 77 | + return $this->returnValues[__FUNCTION__]; |
| 78 | + } |
| 79 | + |
| 80 | + public function getIterator($name, array $args = []) |
| 81 | + { |
| 82 | + return $this->returnValues[__FUNCTION__]; |
| 83 | + } |
| 84 | + |
| 85 | + public function getPaginator($name, array $args = []) |
| 86 | + { |
| 87 | + return $this->returnValues[__FUNCTION__]; |
| 88 | + } |
| 89 | + |
| 90 | + public function waitUntil($name, array $args = []) |
| 91 | + { |
| 92 | + return $this->returnValues[__FUNCTION__]; |
| 93 | + } |
| 94 | + |
| 95 | + public function getWaiter($name, array $args = []) |
| 96 | + { |
| 97 | + return $this->returnValues[__FUNCTION__]; |
| 98 | + } |
| 99 | + |
| 100 | + public function createPresignedRequest(CommandInterface $command, $expires, array $options = []) |
| 101 | + { |
| 102 | + return $this->returnValues[__FUNCTION__]; |
| 103 | + } |
| 104 | + |
| 105 | + public function getObjectUrl($bucket, $key) |
| 106 | + { |
| 107 | + return $this->returnValues[__FUNCTION__]; |
| 108 | + } |
| 109 | + |
| 110 | + public function doesBucketExist($bucket) |
| 111 | + { |
| 112 | + return $this->returnValues[__FUNCTION__]; |
| 113 | + } |
| 114 | + |
| 115 | + public function doesBucketExistV2($bucket, $accept403 = false) |
| 116 | + { |
| 117 | + return $this->returnValues[__FUNCTION__]; |
| 118 | + } |
| 119 | + |
| 120 | + public function doesObjectExist($bucket, $key, array $options = []) |
| 121 | + { |
| 122 | + return $this->returnValues[__FUNCTION__]; |
| 123 | + } |
| 124 | + |
| 125 | + public function doesObjectExistV2($bucket, $key, $includeDeleteMarkers = false, array $options = []) |
| 126 | + { |
| 127 | + return $this->returnValues[__FUNCTION__]; |
| 128 | + } |
| 129 | + |
| 130 | + public function registerStreamWrapper() |
| 131 | + { |
| 132 | + return $this->returnValues[__FUNCTION__]; |
| 133 | + } |
| 134 | + |
| 135 | + public function registerStreamWrapperV2() |
| 136 | + { |
| 137 | + return $this->returnValues[__FUNCTION__]; |
| 138 | + } |
| 139 | + |
| 140 | + public function deleteMatchingObjects($bucket, $prefix = '', $regex = '', array $options = []) |
| 141 | + { |
| 142 | + return $this->returnValues[__FUNCTION__]; |
| 143 | + } |
| 144 | + |
| 145 | + public function deleteMatchingObjectsAsync($bucket, $prefix = '', $regex = '', array $options = []) |
| 146 | + { |
| 147 | + return $this->returnValues[__FUNCTION__]; |
| 148 | + } |
| 149 | + |
| 150 | + public function upload($bucket, $key, $body, $acl = 'private', array $options = []) |
| 151 | + { |
| 152 | + return $this->returnValues[__FUNCTION__]; |
| 153 | + } |
| 154 | + |
| 155 | + public function uploadAsync($bucket, $key, $body, $acl = 'private', array $options = []) |
| 156 | + { |
| 157 | + return $this->returnValues[__FUNCTION__]; |
| 158 | + } |
| 159 | + |
| 160 | + public function copy($fromBucket, $fromKey, $destBucket, $destKey, $acl = 'private', array $options = []) |
| 161 | + { |
| 162 | + return $this->returnValues[__FUNCTION__]; |
| 163 | + } |
| 164 | + |
| 165 | + public function copyAsync($fromBucket, $fromKey, $destBucket, $destKey, $acl = 'private', array $options = []) |
| 166 | + { |
| 167 | + return $this->returnValues[__FUNCTION__]; |
| 168 | + } |
| 169 | + |
| 170 | + public function uploadDirectory($directory, $bucket, $keyPrefix = null, array $options = []) |
| 171 | + { |
| 172 | + return $this->returnValues[__FUNCTION__]; |
| 173 | + } |
| 174 | + |
| 175 | + public function uploadDirectoryAsync($directory, $bucket, $keyPrefix = null, array $options = []) |
| 176 | + { |
| 177 | + return $this->returnValues[__FUNCTION__]; |
| 178 | + } |
| 179 | + |
| 180 | + public function downloadBucket($directory, $bucket, $keyPrefix = '', array $options = []) |
| 181 | + { |
| 182 | + return $this->returnValues[__FUNCTION__]; |
| 183 | + } |
| 184 | + |
| 185 | + public function downloadBucketAsync($directory, $bucket, $keyPrefix = '', array $options = []) |
| 186 | + { |
| 187 | + return $this->returnValues[__FUNCTION__]; |
| 188 | + } |
| 189 | + |
| 190 | + public function determineBucketRegion($bucketName) |
| 191 | + { |
| 192 | + return $this->returnValues[__FUNCTION__]; |
| 193 | + } |
| 194 | + |
| 195 | + public function determineBucketRegionAsync($bucketName) |
| 196 | + { |
| 197 | + return $this->returnValues[__FUNCTION__]; |
| 198 | + } |
| 199 | +} |
0 commit comments