Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-08-23 12:01:01 +0300
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-08-25 17:15:48 +0300
commit5d313da7098d82cdf6cc4a5235bf1455b6833435 (patch)
treec4d6a6b3d689975fade004256786589cebcb4c37 /tests
parenta2a7150d6d87a499e6745651edb27c9795939d0c (diff)
Fix RepairTest
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/RepairTest.php (renamed from tests/lib/RepairStepTest.php)45
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/lib/RepairStepTest.php b/tests/lib/RepairTest.php
index b1d16fdd3fd..1a2fd620e49 100644
--- a/tests/lib/RepairStepTest.php
+++ b/tests/lib/RepairTest.php
@@ -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;
}
@@ -33,28 +38,27 @@ class RepairStepTest implements IRepairStep {
}
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();
});
}
@@ -88,7 +92,7 @@ class RepairTest extends TestCase {
$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');
@@ -103,11 +107,14 @@ class RepairTest extends TestCase {
$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
);