Skip to content

Commit

Permalink
fix: Adapt notifications and activity tests to new DI dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Sep 17, 2024
1 parent 117c7ee commit b926df4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
17 changes: 9 additions & 8 deletions tests/lib/Activity/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class ManagerTest extends TestCase {
/** @var \OC\Activity\Manager */
private $activityManager;

/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
protected $request;
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
protected $session;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $config;
/** @var IValidator|\PHPUnit\Framework\MockObject\MockObject */
protected $validator;
protected IRequest&MockObject $request;
protected IUserSession&MockObject $session;
protected IConfig&MockObject $config;
protected IValidator&MockObject $validator;
protected IRichTextFormatter&MockObject $richTextFormatter;

protected function setUp(): void {
parent::setUp();
Expand All @@ -37,12 +36,14 @@ protected function setUp(): void {
$this->session = $this->createMock(IUserSession::class);
$this->config = $this->createMock(IConfig::class);
$this->validator = $this->createMock(IValidator::class);
$this->richTextFormatter = $this->createMock(IRichTextFormatter::class);

$this->activityManager = new \OC\Activity\Manager(
$this->request,
$this->session,
$this->config,
$this->validator,
$this->richTextFormatter,
$this->createMock(IL10N::class)
);

Expand Down
20 changes: 17 additions & 3 deletions tests/lib/Notification/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IUserManager;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use OCP\Support\Subscription\IRegistry;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -28,8 +29,8 @@ class ManagerTest extends TestCase {
/** @var IManager */
protected $manager;

/** @var IValidator|MockObject */
protected $validator;
protected IValidator&MockObject $validator;
protected IRichTextFormatter&MockObject $richTextFormatter;
/** @var IUserManager|MockObject */
protected $userManager;
/** @var ICacheFactory|MockObject */
Expand All @@ -49,6 +50,7 @@ protected function setUp(): void {
parent::setUp();

$this->validator = $this->createMock(IValidator::class);
$this->richTextFormatter = $this->createMock(IRichTextFormatter::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->cache = $this->createMock(ICache::class);
$this->subscriptionRegistry = $this->createMock(IRegistry::class);
Expand All @@ -64,7 +66,15 @@ protected function setUp(): void {
$this->coordinator->method('getRegistrationContext')
->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 {
Expand Down Expand Up @@ -141,6 +151,7 @@ public function testNotify(): void {
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
$this->richTextFormatter,
])
->setMethods(['getApps'])
->getMock();
Expand Down Expand Up @@ -172,6 +183,7 @@ public function testNotifyInvalid(): void {
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
$this->richTextFormatter,
])
->setMethods(['getApps'])
->getMock();
Expand All @@ -196,6 +208,7 @@ public function testMarkProcessed(): void {
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
$this->richTextFormatter,
])
->setMethods(['getApps'])
->getMock();
Expand All @@ -221,6 +234,7 @@ public function testGetCount(): void {
$this->subscriptionRegistry,
$this->logger,
$this->coordinator,
$this->richTextFormatter,
])
->setMethods(['getApps'])
->getMock();
Expand Down
15 changes: 9 additions & 6 deletions tests/lib/Notification/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
use OC\Notification\Notification;
use OCP\Notification\IAction;
use OCP\Notification\INotification;
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class NotificationTest extends TestCase {
/** @var INotification */
protected $notification;
/** @var IValidator|\PHPUnit\Framework\MockObject\MockObject */
protected $validator;
protected IValidator&MockObject $validator;
protected IRichTextFormatter&MockObject $richTextFormatter;

protected function setUp(): void {
parent::setUp();
$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) {
Expand Down Expand Up @@ -529,7 +532,7 @@ public function testIsValid($isValidCommon, $subject, $expected): void {
'getSubject',
'getParsedSubject',
])
->setConstructorArgs([$this->validator])
->setConstructorArgs([$this->validator, $this->richTextFormatter])
->getMock();

$notification->expects($this->once())
Expand Down Expand Up @@ -562,7 +565,7 @@ public function testIsParsedValid($isValidCommon, $subject, $expected): void {
'getParsedSubject',
'getSubject',
])
->setConstructorArgs([$this->validator])
->setConstructorArgs([$this->validator, $this->richTextFormatter])
->getMock();

$notification->expects($this->once())
Expand Down Expand Up @@ -611,7 +614,7 @@ public function testIsValidCommon($app, $user, $timestamp, $objectType, $objectI
'getObjectType',
'getObjectId',
])
->setConstructorArgs([$this->validator])
->setConstructorArgs([$this->validator, $this->richTextFormatter])
->getMock();

$notification->expects($this->any())
Expand Down

0 comments on commit b926df4

Please sign in to comment.