mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
fix: Make Repair object injectable and fix BackgroundRepair test
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
ceff16bbf9
commit
2bfb6fc731
2 changed files with 13 additions and 21 deletions
|
|
@ -32,7 +32,6 @@ use OC_App;
|
|||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\BackgroundJob\TimedJob;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +41,7 @@ use Psr\Log\LoggerInterface;
|
|||
*/
|
||||
class BackgroundRepair extends TimedJob {
|
||||
public function __construct(
|
||||
private IEventDispatcher $dispatcher,
|
||||
private Repair $repair,
|
||||
ITimeFactory $time,
|
||||
private LoggerInterface $logger,
|
||||
private IJobList $jobList,
|
||||
|
|
@ -73,9 +72,9 @@ class BackgroundRepair extends TimedJob {
|
|||
}
|
||||
|
||||
$step = $argument['step'];
|
||||
$repair = \OCP\Server::get(Repair::class);
|
||||
$this->repair->setRepairSteps([]);
|
||||
try {
|
||||
$repair->addStep($step);
|
||||
$this->repair->addStep($step);
|
||||
} catch (\Exception $ex) {
|
||||
$this->logger->error($ex->getMessage(), [
|
||||
'app' => 'migration',
|
||||
|
|
@ -88,7 +87,7 @@ class BackgroundRepair extends TimedJob {
|
|||
}
|
||||
|
||||
// execute the repair step
|
||||
$repair->run();
|
||||
$this->repair->run();
|
||||
|
||||
// remove the job once executed successfully
|
||||
$this->jobList->remove($this, $this->argument);
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ namespace Test\Migration;
|
|||
use OC\BackgroundJob\JobList;
|
||||
use OC\Migration\BackgroundRepair;
|
||||
use OC\NeedsUpdateException;
|
||||
use OC\Repair;
|
||||
use OC\Repair\Events\RepairStepEvent;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
|
|
@ -57,20 +57,12 @@ class TestRepairStep implements IRepairStep {
|
|||
}
|
||||
|
||||
class BackgroundRepairTest extends TestCase {
|
||||
/** @var JobList|MockObject */
|
||||
private $jobList;
|
||||
|
||||
/** @var BackgroundRepair|MockObject */
|
||||
private $job;
|
||||
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
|
||||
/** @var IEventDispatcher|MockObject $dispatcher */
|
||||
private $dispatcher;
|
||||
|
||||
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $dispatcher */
|
||||
private $time;
|
||||
private JobList $jobList;
|
||||
private BackgroundRepair $job;
|
||||
private LoggerInterface $logger;
|
||||
private IEventDispatcher $dispatcher;
|
||||
private ITimeFactory $time;
|
||||
private Repair $repair;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -85,8 +77,9 @@ class BackgroundRepairTest extends TestCase {
|
|||
$this->time = $this->createMock(ITimeFactory::class);
|
||||
$this->time->method('getTime')
|
||||
->willReturn(999999);
|
||||
$this->repair = new Repair($this->dispatcher, $this->logger);
|
||||
$this->job = $this->getMockBuilder(BackgroundRepair::class)
|
||||
->setConstructorArgs([$this->dispatcher, $this->time, $this->logger, $this->jobList])
|
||||
->setConstructorArgs([$this->repair, $this->time, $this->logger, $this->jobList])
|
||||
->setMethods(['loadApp'])
|
||||
->getMock();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue