nextcloud/tests/lib/Files/ObjectStore/MapperTest.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2016-05-22 15:14:28 -04:00
<?php
2016-05-22 15:14:28 -04:00
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
2016-05-22 15:14:28 -04:00
*/
2016-05-22 15:14:28 -04:00
namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\Mapper;
2016-09-07 14:01:13 -04:00
use OCP\IUser;
2016-05-22 15:14:28 -04:00
class MapperTest extends \Test\TestCase {
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
private $user;
protected function setUp(): void {
parent::setUp();
$this->user = $this->createMock(IUser::class);
}
public static function dataGetBucket(): array {
2016-05-22 15:14:28 -04:00
return [
['user', 64, 0, '17'],
['USER', 64, 0, '0'],
['bc0e8b52-a66c-1035-90c6-d9663bda9e3f', 64, 0, '56'],
['user', 8, 0, '1'],
['user', 2, 0, '1'],
['USER', 2, 0, '0'],
['user', 128, 64, '81'],
2016-05-22 15:14:28 -04:00
];
}
/**
* @param string $username
* @param int $numBuckets
2016-05-22 15:14:28 -04:00
* @param string $expectedBucket
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetBucket')]
public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void {
$mapper = new Mapper($this->user, ['arguments' => ['min_bucket' => $bucketShift]]);
$this->user->expects($this->once())
->method('getUID')
2016-05-22 15:14:28 -04:00
->willReturn($username);
$result = $mapper->getBucket($numBuckets);
$this->assertEquals($expectedBucket, $result);
2016-05-22 15:14:28 -04:00
}
2016-09-07 14:01:13 -04:00
}