瀏覽代碼

Fix unit test

Null is not longer possible as value for $dispatcher.

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
tags/v16.0.0alpha1
Daniel Kesselberg 5 年之前
父節點
當前提交
e090973e64
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 22 行新增12 行删除
  1. 7
    3
      lib/private/Migration/BackgroundRepair.php
  2. 15
    9
      tests/lib/Migration/BackgroundRepairTest.php

+ 7
- 3
lib/private/Migration/BackgroundRepair.php 查看文件

@@ -29,7 +29,7 @@ use OC\Repair;
use OC_App;
use OCP\BackgroundJob\IJobList;
use OCP\ILogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class BackgroundRepair
@@ -44,12 +44,16 @@ class BackgroundRepair extends TimedJob {
/** @var ILogger */
private $logger;

/** @var EventDispatcher */
/** @var EventDispatcherInterface */
private $dispatcher;

public function setDispatcher(EventDispatcher $dispatcher) {
/**
* @param EventDispatcherInterface $dispatcher
*/
public function setDispatcher(EventDispatcherInterface $dispatcher): void {
$this->dispatcher = $dispatcher;
}

/**
* run the job, then remove it from the job list
*

+ 15
- 9
tests/lib/Migration/BackgroundRepairTest.php 查看文件

@@ -21,13 +21,12 @@

namespace Test\Migration;


use OC\Migration\BackgroundRepair;
use OC\NeedsUpdateException;
use OCP\ILogger;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;

@@ -57,15 +56,18 @@ class TestRepairStep implements IRepairStep {

class BackgroundRepairTest extends TestCase {

/** @var \OC\BackgroundJob\JobList | \PHPUnit_Framework_MockObject_MockObject */
/** @var \OC\BackgroundJob\JobList|\PHPUnit_Framework_MockObject_MockObject */
private $jobList;

/** @var BackgroundRepair | \PHPUnit_Framework_MockObject_MockObject */
/** @var BackgroundRepair|\PHPUnit_Framework_MockObject_MockObject */
private $job;

/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;

/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject $dispatcher */
private $dispatcher;

public function setUp() {
parent::setUp();

@@ -78,6 +80,9 @@ class BackgroundRepairTest extends TestCase {
$this->job = $this->getMockBuilder(BackgroundRepair::class)
->setMethods(['loadApp'])
->getMock();

$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->job->setDispatcher($this->dispatcher);
}

public function testNoArguments() {
@@ -96,8 +101,11 @@ class BackgroundRepairTest extends TestCase {
}

public function testUnknownStep() {
$this->dispatcher->expects($this->never())->method('dispatch');

$this->jobList->expects($this->once())->method('remove');
$this->logger->expects($this->once())->method('logException');

$this->job->setArgument([
'app' => 'test',
'step' => 'j'
@@ -106,13 +114,11 @@ class BackgroundRepairTest extends TestCase {
}

public function testWorkingStep() {
/** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject $dispatcher */
$dispatcher = $this->createMock(EventDispatcher::class);
$dispatcher->expects($this->once())->method('dispatch')
$this->dispatcher->expects($this->once())->method('dispatch')
->with('\OC\Repair::step', new GenericEvent('\OC\Repair::step', ['A test repair step']));

$this->jobList->expects($this->once())->method('remove');
$this->job->setDispatcher($dispatcher);
$this->job->setArgument([
'app' => 'test',
'step' => '\Test\Migration\TestRepairStep'

Loading…
取消
儲存