Skip to content

Commit

Permalink
chore: Cleanup and prepare \OC\Repair\RepairMimeTypes tests for PHP…
Browse files Browse the repository at this point in the history
…Unit 10

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Sep 19, 2024
1 parent 8c60ffa commit 9b5c314
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 220 deletions.
41 changes: 18 additions & 23 deletions tests/lib/Repair/CleanTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
namespace Test\Repair;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Migration\IOutput;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Tests for the cleaning the tags tables
Expand All @@ -19,33 +21,26 @@
* @see \OC\Repair\CleanTags
*/
class CleanTagsTest extends \Test\TestCase {
/** @var \OC\Repair\CleanTags */
protected $repair;

/** @var \OCP\IDBConnection */
protected $connection;
private ?int $createdFile = null;
private \OC\Repair\CleanTags $repair;
private IDBConnection $connection;

/** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */
protected $userManager;

/** @var int */
protected $createdFile;

/** @var IOutput */
private $outputMock;
private IUserManager&MockObject $userManager;
private IOutput&MockObject $outputMock;

protected function setUp(): void {
parent::setUp();

$this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
$this->outputMock = $this->getMockBuilder(IOutput::class)
->disableOriginalConstructor()
->getMock();

$this->userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()
->getMock();

$this->connection = \OC::$server->getDatabaseConnection();
$this->connection = \OCP\Server::get(IDBConnection::class);
$this->repair = new \OC\Repair\CleanTags($this->connection, $this->userManager);
$this->cleanUpTables();
}
Expand All @@ -59,14 +54,14 @@ protected function tearDown(): void {
protected function cleanUpTables() {
$qb = $this->connection->getQueryBuilder();
$qb->delete('vcategory')
->execute();
->executeStatement();

$qb->delete('vcategory_to_object')
->execute();
->executeStatement();

$qb->delete('filecache')
->runAcrossAllShards()
->execute();
->executeStatement();
}

public function testRun(): void {
Expand Down Expand Up @@ -119,7 +114,7 @@ protected function assertEntryCount($tableName, $expected, $message = '') {
$qb = $this->connection->getQueryBuilder();
$result = $qb->select($qb->func()->count('*'))
->from($tableName)
->execute();
->executeQuery();

$this->assertEquals($expected, $result->fetchOne(), $message);
}
Expand All @@ -140,7 +135,7 @@ protected function addTagCategory($category, $type, $user = 'TestRepairCleanTags
'category' => $qb->createNamedParameter($category),
'type' => $qb->createNamedParameter($type),
])
->execute();
->executeStatement();

return $qb->getLastInsertId();
}
Expand All @@ -159,15 +154,15 @@ protected function addTagEntry($objectId, $category, $type) {
'categoryid' => $qb->createNamedParameter($category, IQueryBuilder::PARAM_INT),
'type' => $qb->createNamedParameter($type),
])
->execute();
->executeStatement();
}

/**
* Gets the last fileid from the file cache
* @return int
*/
protected function getFileID() {
if ($this->createdFile) {
if ($this->createdFile !== null) {
return $this->createdFile;
}

Expand All @@ -181,15 +176,15 @@ protected function getFileID() {
'path' => $qb->createNamedParameter($fileName),
'path_hash' => $qb->createNamedParameter(md5($fileName)),
])
->execute();
->executeStatement();
$fileName = $this->getUniqueID('TestRepairCleanTags', 12);
$qb->insert('filecache')
->values([
'storage' => $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT),
'path' => $qb->createNamedParameter($fileName),
'path_hash' => $qb->createNamedParameter(md5($fileName)),
])
->execute();
->executeStatement();

$this->createdFile = $qb->getLastInsertId();
return $this->createdFile;
Expand Down
14 changes: 5 additions & 9 deletions tests/lib/Repair/ClearFrontendCachesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\Migration\IOutput;
use PHPUnit\Framework\MockObject\MockObject;

class ClearFrontendCachesTest extends \Test\TestCase {
/** @var ICacheFactory */
private $cacheFactory;

/** @var JSCombiner */
private $jsCombiner;
private ICacheFactory&MockObject $cacheFactory;
private JSCombiner&MockObject $jsCombiner;
private IOutput&MockObject $outputMock;

/** @var \OC\Repair\ClearFrontendCaches */
protected $repair;

/** @var IOutput */
private $outputMock;
protected \OC\Repair\ClearFrontendCaches $repair;

protected function setUp(): void {
parent::setUp();
Expand Down
15 changes: 4 additions & 11 deletions tests/lib/Repair/ClearGeneratedAvatarCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,19 @@
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\Migration\IOutput;
use PHPUnit\Framework\MockObject\MockObject;

class ClearGeneratedAvatarCacheTest extends \Test\TestCase {
/** @var AvatarManager */
private $avatarManager;

/** @var IOutput */
private $outputMock;

/** @var IConfig */
private $config;

/** @var IJobList */
private $jobList;
private AvatarManager&MockObject $avatarManager;
private IConfig&MockObject $config;
private IJobList&MockObject $jobList;

protected ClearGeneratedAvatarCache $repair;

protected function setUp(): void {
parent::setUp();

$this->outputMock = $this->createMock(IOutput::class);
$this->avatarManager = $this->createMock(AvatarManager::class);
$this->config = $this->createMock(IConfig::class);
$this->jobList = $this->createMock(IJobList::class);
Expand Down
27 changes: 12 additions & 15 deletions tests/lib/Repair/OldGroupMembershipSharesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
namespace Test\Repair;

use OC\Repair\OldGroupMembershipShares;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\Migration\IOutput;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class OldGroupMembershipSharesTest
Expand All @@ -19,23 +22,17 @@
* @package Test\Repair
*/
class OldGroupMembershipSharesTest extends \Test\TestCase {
/** @var OldGroupMembershipShares */
protected $repair;

/** @var \OCP\IDBConnection */
protected $connection;

/** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
protected $groupManager;
private IDBConnection $connection;
private IGroupManager&MockObject $groupManager;

protected function setUp(): void {
parent::setUp();

/** \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
$this->groupManager = $this->getMockBuilder('OCP\IGroupManager')
$this->groupManager = $this->getMockBuilder(IGroupManager::class)
->disableOriginalConstructor()
->getMock();
$this->connection = \OC::$server->getDatabaseConnection();
$this->connection = \OCP\Server::get(IDBConnection::class);

$this->deleteAllShares();
}
Expand All @@ -48,7 +45,7 @@ protected function tearDown(): void {

protected function deleteAllShares() {
$qb = $this->connection->getQueryBuilder();
$qb->delete('share')->execute();
$qb->delete('share')->executeStatement();
}

public function testRun(): void {
Expand Down Expand Up @@ -76,7 +73,7 @@ public function testRun(): void {
$result = $query->select('id')
->from('share')
->orderBy('id', 'ASC')
->execute();
->executeQuery();
$rows = $result->fetchAll();
$this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows);
$result->closeCursor();
Expand All @@ -92,7 +89,7 @@ public function testRun(): void {
$result = $query->select('id')
->from('share')
->orderBy('id', 'ASC')
->execute();
->executeQuery();
$rows = $result->fetchAll();
$this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member]], $rows);
$result->closeCursor();
Expand Down Expand Up @@ -127,8 +124,8 @@ protected function createShare($shareType, $shareWith, $parent) {
$qb = $this->connection->getQueryBuilder();
$qb->insert('share')
->values($shareValues)
->execute();
->executeStatement();

return $this->connection->lastInsertId('*PREFIX*share');
return $qb->getLastInsertId();
}
}
Loading

0 comments on commit 9b5c314

Please sign in to comment.