|
2 | 2 |
|
3 | 3 | namespace PlatformCommunity\Flysystem\BunnyCDN\Tests;
|
4 | 4 |
|
| 5 | +use Faker\Factory; |
5 | 6 | use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase;
|
6 | 7 | use League\Flysystem\Config;
|
7 | 8 | use League\Flysystem\Filesystem;
|
8 | 9 | use League\Flysystem\FilesystemAdapter;
|
9 | 10 | use League\Flysystem\FilesystemException;
|
10 | 11 | use League\Flysystem\UnableToCopyFile;
|
11 | 12 | use League\Flysystem\UnableToMoveFile;
|
| 13 | +use League\Flysystem\UnableToProvideChecksum; |
12 | 14 | use League\Flysystem\UnableToRetrieveMetadata;
|
13 | 15 | use League\Flysystem\Visibility;
|
14 | 16 | use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;
|
15 | 17 | use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
|
16 | 18 | use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion;
|
| 19 | +use PlatformCommunity\Flysystem\BunnyCDN\Util; |
17 | 20 | use Throwable;
|
18 | 21 |
|
19 | 22 | class FlysystemAdapterTest extends FilesystemAdapterTestCase
|
@@ -235,6 +238,51 @@ public function get_checksum(): void
|
235 | 238 | );
|
236 | 239 | }
|
237 | 240 |
|
| 241 | + public function test_checksum_throws_error_with_non_existing_file_on_default_algo(): void |
| 242 | + { |
| 243 | + $adapter = $this->adapter(); |
| 244 | + |
| 245 | + $this->expectException(UnableToProvideChecksum::class); |
| 246 | + $adapter->checksum('path.txt', new Config(['checksum_algo' => 'sha256'])); |
| 247 | + } |
| 248 | + |
| 249 | + //test_checksum_throws_error_with_empty_checksum_from_client |
| 250 | + public function test_checksum_throws_error_with_empty_checksum_from_client(): void |
| 251 | + { |
| 252 | + $client = $this->createMock(BunnyCDNClient::class); |
| 253 | + $client->expects(self::exactly(1))->method('list')->willReturnCallback( |
| 254 | + function () { |
| 255 | + ['file' => $file, 'dir' => $dir] = Util::splitPathIntoDirectoryAndFile('file.txt'); |
| 256 | + $dir = Util::normalizePath($dir); |
| 257 | + $faker = Factory::create(); |
| 258 | + $storage_zone = $faker->word; |
| 259 | + |
| 260 | + return [[ |
| 261 | + 'Guid' => $faker->uuid, |
| 262 | + 'StorageZoneName' => $storage_zone, |
| 263 | + 'Path' => Util::normalizePath('/'.$storage_zone.'/'.$dir.'/'), |
| 264 | + 'ObjectName' => $file, |
| 265 | + 'Length' => $faker->numberBetween(0, 10240), |
| 266 | + 'LastChanged' => date('Y-m-d\TH:i:s.v'), |
| 267 | + 'ServerId' => $faker->numberBetween(0, 10240), |
| 268 | + 'ArrayNumber' => 0, |
| 269 | + 'IsDirectory' => false, |
| 270 | + 'UserId' => 'bf91bc4e-0e60-411a-b475-4416926d20f7', |
| 271 | + 'ContentType' => '', |
| 272 | + 'DateCreated' => date('Y-m-d\TH:i:s.v'), |
| 273 | + 'StorageZoneId' => $faker->numberBetween(0, 102400), |
| 274 | + 'Checksum' => null, |
| 275 | + 'ReplicatedZones' => '', |
| 276 | + ]]; |
| 277 | + } |
| 278 | + ); |
| 279 | + |
| 280 | + $adapter = new BunnyCDNAdapter($client); |
| 281 | + $this->expectException(UnableToProvideChecksum::class); |
| 282 | + $this->expectExceptionMessage('Unable to get checksum for file.txt: Checksum not available.'); |
| 283 | + $adapter->checksum('file.txt', new Config(['checksum_algo' => 'sha256'])); |
| 284 | + } |
| 285 | + |
238 | 286 | /**
|
239 | 287 | * @test
|
240 | 288 | */
|
|
0 commit comments