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 <91878298+come-nc@users.noreply.github.com>2022-08-30 15:47:05 +0300
committerGitHub <noreply@github.com>2022-08-30 15:47:05 +0300
commitf56ecf92426026c913497bea9f7ca99e8d3ac631 (patch)
tree4e3f02de1eae3ff03e5f23e15b12195b4aee4255 /tests
parent66648011c6bc278ace57230db44fd6d63d67b864 (diff)
parent0b9a878250d79101756d881d15d22acda2dbeddc (diff)
Merge pull request #33640 from nextcloud/fix/fix-symfony-event-typing
Port Repair and Migrator events to IEventDispatcher
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/DB/MigratorTest.php2
-rw-r--r--tests/lib/Migration/BackgroundRepairTest.php30
-rw-r--r--tests/lib/RepairTest.php (renamed from tests/lib/RepairStepTest.php)45
3 files changed, 43 insertions, 34 deletions
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php
index af44159efa3..af56730f9f6 100644
--- a/tests/lib/DB/MigratorTest.php
+++ b/tests/lib/DB/MigratorTest.php
@@ -62,7 +62,7 @@ class MigratorTest extends \Test\TestCase {
private function getMigrator(): Migrator {
$platform = $this->connection->getDatabasePlatform();
$random = \OC::$server->getSecureRandom();
- $dispatcher = \OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
if ($platform instanceof SqlitePlatform) {
return new SQLiteMigrator($this->connection, $this->config, $dispatcher);
} elseif ($platform instanceof OraclePlatform) {
diff --git a/tests/lib/Migration/BackgroundRepairTest.php b/tests/lib/Migration/BackgroundRepairTest.php
index 7da9b18de30..e14b3179b27 100644
--- a/tests/lib/Migration/BackgroundRepairTest.php
+++ b/tests/lib/Migration/BackgroundRepairTest.php
@@ -21,15 +21,17 @@
namespace Test\Migration;
-use OC\Migration\BackgroundRepair;
-use OC\NeedsUpdateException;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
-use Test\TestCase;
+use OC\BackgroundJob\JobList;
+use OC\Migration\BackgroundRepair;
+use OC\NeedsUpdateException;
+use OC\Repair\Events\RepairStepEvent;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
+use Test\TestCase;
class TestRepairStep implements IRepairStep {
@@ -57,16 +59,16 @@ class TestRepairStep implements IRepairStep {
class BackgroundRepairTest extends TestCase {
- /** @var \OC\BackgroundJob\JobList|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var JobList|MockObject */
private $jobList;
- /** @var BackgroundRepair|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var BackgroundRepair|MockObject */
private $job;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var LoggerInterface|MockObject */
private $logger;
- /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject $dispatcher */
+ /** @var IEventDispatcher|MockObject $dispatcher */
private $dispatcher;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $dispatcher */
@@ -75,13 +77,13 @@ class BackgroundRepairTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->jobList = $this->getMockBuilder('OC\BackgroundJob\JobList')
+ $this->jobList = $this->getMockBuilder(JobList::class)
->disableOriginalConstructor()
->getMock();
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->time = $this->createMock(ITimeFactory::class);
$this->time->method('getTime')
->willReturn(999999);
@@ -107,7 +109,7 @@ class BackgroundRepairTest extends TestCase {
}
public function testUnknownStep() {
- $this->dispatcher->expects($this->never())->method('dispatch');
+ $this->dispatcher->expects($this->never())->method('dispatchTyped');
$this->jobList->expects($this->once())->method('remove');
$this->logger->expects($this->once())->method('error');
@@ -120,8 +122,8 @@ class BackgroundRepairTest extends TestCase {
}
public function testWorkingStep() {
- $this->dispatcher->expects($this->once())->method('dispatch')
- ->with('\OC\Repair::step', new GenericEvent('\OC\Repair::step', ['A test repair step']));
+ $this->dispatcher->expects($this->once())->method('dispatchTyped')
+ ->with($this->equalTo(new RepairStepEvent('A test repair step')));
$this->jobList->expects($this->once())->method('remove');
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
);