Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tests/lib/Files/Cache/SearchBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SearchBuilderTest extends TestCase {

protected function setUp(): void {
parent::setUp();
$this->cleanupStorage();
$this->builder = Server::get(IDBConnection::class)->getQueryBuilder();
$this->mimetypeLoader = $this->createMock(IMimeTypeLoader::class);
$this->filesMetadataManager = $this->createMock(IFilesMetadataManager::class);
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function setUp(): void {
]);

$this->searchBuilder = new SearchBuilder($this->mimetypeLoader, $this->filesMetadataManager);
$this->numericStorageId = 10000;
$this->numericStorageId = random_int(1000000, PHP_INT_MAX);

$this->builder->select(['fileid'])
->from('filecache', 'file') // alias needed for QuerySearchHelper#getOperatorFieldAndValue
Expand All @@ -76,26 +77,27 @@ protected function setUp(): void {

protected function tearDown(): void {
parent::tearDown();
$this->cleanupStorage();
}

private function cleanupStorage(): void {
$builder = Server::get(IDBConnection::class)->getQueryBuilder();

$builder->delete('filecache')
->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->numericStorageId, IQueryBuilder::PARAM_INT)));

$builder->executeStatement();
}

private function addCacheEntry(array $data) {
$data['storage'] = $this->numericStorageId;
$data['etag'] = 'unimportant';
$data['storage_mtime'] = $data['mtime'];
if (!isset($data['path'])) {
$data['path'] = 'random/' . $this->getUniqueID();
}
$data['path_hash'] = md5($data['path']);
if (!isset($data['mtime'])) {
$data['mtime'] = 100;
}
$data['storage_mtime'] = $data['mtime'];
if (!isset($data['size'])) {
$data['size'] = 100;
}
Expand Down
Loading