fix: Adapt notifications and activity tests to new DI dependency

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/48137/head
Côme Chilliet 1 year ago
parent 117c7ee654
commit b926df4730
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
  1. 17
      tests/lib/Activity/ManagerTest.php
  2. 20
      tests/lib/Notification/ManagerTest.php
  3. 15
      tests/lib/Notification/NotificationTest.php

@ -14,21 +14,20 @@ use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator; use OCP\RichObjectStrings\IValidator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class ManagerTest extends TestCase { class ManagerTest extends TestCase {
/** @var \OC\Activity\Manager */ /** @var \OC\Activity\Manager */
private $activityManager; private $activityManager;
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ protected IRequest&MockObject $request;
protected $request; protected IUserSession&MockObject $session;
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ protected IConfig&MockObject $config;
protected $session; protected IValidator&MockObject $validator;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected IRichTextFormatter&MockObject $richTextFormatter;
protected $config;
/** @var IValidator|\PHPUnit\Framework\MockObject\MockObject */
protected $validator;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -37,12 +36,14 @@ class ManagerTest extends TestCase {
$this->session = $this->createMock(IUserSession::class); $this->session = $this->createMock(IUserSession::class);
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->validator = $this->createMock(IValidator::class); $this->validator = $this->createMock(IValidator::class);
$this->richTextFormatter = $this->createMock(IRichTextFormatter::class);
$this->activityManager = new \OC\Activity\Manager( $this->activityManager = new \OC\Activity\Manager(
$this->request, $this->request,
$this->session, $this->session,
$this->config, $this->config,
$this->validator, $this->validator,
$this->richTextFormatter,
$this->createMock(IL10N::class) $this->createMock(IL10N::class)
); );

@ -18,6 +18,7 @@ use OCP\ICacheFactory;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator; use OCP\RichObjectStrings\IValidator;
use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\IRegistry;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
@ -28,8 +29,8 @@ class ManagerTest extends TestCase {
/** @var IManager */ /** @var IManager */
protected $manager; protected $manager;
/** @var IValidator|MockObject */ protected IValidator&MockObject $validator;
protected $validator; protected IRichTextFormatter&MockObject $richTextFormatter;
/** @var IUserManager|MockObject */ /** @var IUserManager|MockObject */
protected $userManager; protected $userManager;
/** @var ICacheFactory|MockObject */ /** @var ICacheFactory|MockObject */
@ -49,6 +50,7 @@ class ManagerTest extends TestCase {
parent::setUp(); parent::setUp();
$this->validator = $this->createMock(IValidator::class); $this->validator = $this->createMock(IValidator::class);
$this->richTextFormatter = $this->createMock(IRichTextFormatter::class);
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->cache = $this->createMock(ICache::class); $this->cache = $this->createMock(ICache::class);
$this->subscriptionRegistry = $this->createMock(IRegistry::class); $this->subscriptionRegistry = $this->createMock(IRegistry::class);
@ -64,7 +66,15 @@ class ManagerTest extends TestCase {
$this->coordinator->method('getRegistrationContext') $this->coordinator->method('getRegistrationContext')
->willReturn($this->registrationContext); ->willReturn($this->registrationContext);
$this->manager = new Manager($this->validator, $this->userManager, $this->cacheFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator); $this->manager = new Manager(
$this->validator,
$this->userManager,
$this->cacheFactory,
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
$this->richTextFormatter,
);
} }
public function testRegisterApp(): void { public function testRegisterApp(): void {
@ -141,6 +151,7 @@ class ManagerTest extends TestCase {
$this->subscriptionRegistry, $this->subscriptionRegistry,
$this->logger, $this->logger,
$this->coordinator, $this->coordinator,
$this->richTextFormatter,
]) ])
->setMethods(['getApps']) ->setMethods(['getApps'])
->getMock(); ->getMock();
@ -172,6 +183,7 @@ class ManagerTest extends TestCase {
$this->subscriptionRegistry, $this->subscriptionRegistry,
$this->logger, $this->logger,
$this->coordinator, $this->coordinator,
$this->richTextFormatter,
]) ])
->setMethods(['getApps']) ->setMethods(['getApps'])
->getMock(); ->getMock();
@ -196,6 +208,7 @@ class ManagerTest extends TestCase {
$this->subscriptionRegistry, $this->subscriptionRegistry,
$this->logger, $this->logger,
$this->coordinator, $this->coordinator,
$this->richTextFormatter,
]) ])
->setMethods(['getApps']) ->setMethods(['getApps'])
->getMock(); ->getMock();
@ -221,6 +234,7 @@ class ManagerTest extends TestCase {
$this->subscriptionRegistry, $this->subscriptionRegistry,
$this->logger, $this->logger,
$this->coordinator, $this->coordinator,
$this->richTextFormatter,
]) ])
->setMethods(['getApps']) ->setMethods(['getApps'])
->getMock(); ->getMock();

@ -12,19 +12,22 @@ namespace Test\Notification;
use OC\Notification\Notification; use OC\Notification\Notification;
use OCP\Notification\IAction; use OCP\Notification\IAction;
use OCP\Notification\INotification; use OCP\Notification\INotification;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator; use OCP\RichObjectStrings\IValidator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class NotificationTest extends TestCase { class NotificationTest extends TestCase {
/** @var INotification */ /** @var INotification */
protected $notification; protected $notification;
/** @var IValidator|\PHPUnit\Framework\MockObject\MockObject */ protected IValidator&MockObject $validator;
protected $validator; protected IRichTextFormatter&MockObject $richTextFormatter;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->validator = $this->createMock(IValidator::class); $this->validator = $this->createMock(IValidator::class);
$this->notification = new Notification($this->validator); $this->richTextFormatter = $this->createMock(IRichTextFormatter::class);
$this->notification = new Notification($this->validator, $this->richTextFormatter);
} }
protected function dataValidString($maxLength) { protected function dataValidString($maxLength) {
@ -529,7 +532,7 @@ class NotificationTest extends TestCase {
'getSubject', 'getSubject',
'getParsedSubject', 'getParsedSubject',
]) ])
->setConstructorArgs([$this->validator]) ->setConstructorArgs([$this->validator, $this->richTextFormatter])
->getMock(); ->getMock();
$notification->expects($this->once()) $notification->expects($this->once())
@ -562,7 +565,7 @@ class NotificationTest extends TestCase {
'getParsedSubject', 'getParsedSubject',
'getSubject', 'getSubject',
]) ])
->setConstructorArgs([$this->validator]) ->setConstructorArgs([$this->validator, $this->richTextFormatter])
->getMock(); ->getMock();
$notification->expects($this->once()) $notification->expects($this->once())
@ -611,7 +614,7 @@ class NotificationTest extends TestCase {
'getObjectType', 'getObjectType',
'getObjectId', 'getObjectId',
]) ])
->setConstructorArgs([$this->validator]) ->setConstructorArgs([$this->validator, $this->richTextFormatter])
->getMock(); ->getMock();
$notification->expects($this->any()) $notification->expects($this->any())

Loading…
Cancel
Save