Skip to content

Commit 1aade40

Browse files
committed
feat: add test case for reused checksum
1 parent 3c6f4e4 commit 1aade40

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/FlysystemAdapterTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
namespace PlatformCommunity\Flysystem\BunnyCDN\Tests;
44

5+
use Faker\Factory;
56
use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase;
67
use League\Flysystem\Config;
78
use League\Flysystem\Filesystem;
89
use League\Flysystem\FilesystemAdapter;
910
use League\Flysystem\FilesystemException;
1011
use League\Flysystem\UnableToCopyFile;
1112
use League\Flysystem\UnableToMoveFile;
13+
use League\Flysystem\UnableToProvideChecksum;
1214
use League\Flysystem\UnableToRetrieveMetadata;
1315
use League\Flysystem\Visibility;
1416
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;
1517
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
1618
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion;
19+
use PlatformCommunity\Flysystem\BunnyCDN\Util;
1720
use Throwable;
1821

1922
class FlysystemAdapterTest extends FilesystemAdapterTestCase
@@ -235,6 +238,51 @@ public function get_checksum(): void
235238
);
236239
}
237240

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+
238286
/**
239287
* @test
240288
*/

0 commit comments

Comments
 (0)