Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix RepairTest
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Aug 25, 2022
commit 5d313da7098d82cdf6cc4a5235bf1455b6833435
45 changes: 26 additions & 19 deletions tests/lib/RepairStepTest.php → tests/lib/RepairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@

namespace Test;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\Migration\IRepairStep;
use OC\Repair;
use OC\Repair\Events\RepairInfoEvent;
use OC\Repair\Events\RepairStepEvent;
use OC\Repair\Events\RepairWarningEvent;
use OC\Repair\Events\RepairErrorEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

class RepairStepTest implements IRepairStep {
private $warning;
class TestRepairStep implements IRepairStep {
private bool $warning;

public function __construct($warning = false) {
public function __construct(bool $warning = false) {
$this->warning = $warning;
}

Expand All @@ -33,28 +38,27 @@ public function run(\OCP\Migration\IOutput $out) {
}

class RepairTest extends TestCase {
/** @var \OC\Repair */
private $repair;
private Repair $repair;

/** @var string[] */
private $outputArray;
private array $outputArray = [];

protected function setUp(): void {
parent::setUp();
$dispatcher = new EventDispatcher();
$dispatcher = \OC::$server->get(IEventDispatcher::class);
$this->repair = new \OC\Repair([], $dispatcher, $this->createMock(LoggerInterface::class));

$dispatcher->addListener('\OC\Repair::warning', function ($event) {
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
$this->outputArray[] = 'warning: ' . $event->getArgument(0);
$dispatcher->addListener(RepairWarningEvent::class, function (RepairWarningEvent $event) {
$this->outputArray[] = 'warning: ' . $event->getMessage();
});
$dispatcher->addListener('\OC\Repair::info', function ($event) {
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
$this->outputArray[] = 'info: ' . $event->getArgument(0);
$dispatcher->addListener(RepairInfoEvent::class, function (RepairInfoEvent $event) {
$this->outputArray[] = 'info: ' . $event->getMessage();
});
$dispatcher->addListener('\OC\Repair::step', function ($event) {
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
$this->outputArray[] = 'step: ' . $event->getArgument(0);
$dispatcher->addListener(RepairStepEvent::class, function (RepairStepEvent $event) {
$this->outputArray[] = 'step: ' . $event->getStepName();
});
$dispatcher->addListener(RepairErrorEvent::class, function (RepairErrorEvent $event) {
$this->outputArray[] = 'error: ' . $event->getMessage();
});
}

Expand Down Expand Up @@ -88,7 +92,7 @@ public function testRunRepairStepsWithException() {
$mock = $this->createMock(TestRepairStep::class);
$mock->expects($this->any())
->method('run')
->will($this->throwException(new \Exception()));
->will($this->throwException(new \Exception('Exception text')));
$mock->expects($this->any())
->method('getName')
->willReturn('Exception Test');
Expand All @@ -103,11 +107,14 @@ public function testRunRepairStepsWithException() {
$thrown = true;
}

$this->assertTrue($thrown);
$this->assertFalse($thrown);
// jump out after exception
$this->assertEquals(
[
'step: Exception Test',
'error: Exception text',
'step: Test Name',
'info: Simulated info',
],
$this->outputArray
);
Expand Down