Browse Source

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 years ago
parent
commit
e090973e64
No account linked to committer's email address

+ 7
- 3
lib/private/Migration/BackgroundRepair.php View File

use OC_App; use OC_App;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\ILogger; use OCP\ILogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;


/** /**
* Class BackgroundRepair * Class BackgroundRepair
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;


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


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

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

+ 15
- 9
tests/lib/Migration/BackgroundRepairTest.php View File



namespace Test\Migration; namespace Test\Migration;



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




class BackgroundRepairTest extends TestCase { class BackgroundRepairTest extends TestCase {


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


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


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


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

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


$this->job = $this->getMockBuilder(BackgroundRepair::class) $this->job = $this->getMockBuilder(BackgroundRepair::class)
->setMethods(['loadApp']) ->setMethods(['loadApp'])
->getMock(); ->getMock();

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


public function testNoArguments() { public function testNoArguments() {
} }


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

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

$this->job->setArgument([ $this->job->setArgument([
'app' => 'test', 'app' => 'test',
'step' => 'j' 'step' => 'j'
} }


public function testWorkingStep() { 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'])); ->with('\OC\Repair::step', new GenericEvent('\OC\Repair::step', ['A test repair step']));


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

Loading…
Cancel
Save