Skip to content

Commit 7289a7f

Browse files
committed
fix: Fix PHPUnit tests — delete EmailServiceTest, fix constructor mocks
- Delete EmailServiceTest (references non-existent EmailService class) - Fix SoftwareCatalogEventListenerTest to mock ObjectEntity properly - Fix OrganisationUserWorkflowTest constructor argument order - Fix ContactPersonHandlerTest constructor argument order
1 parent ffdd1c8 commit 7289a7f

4 files changed

Lines changed: 31 additions & 348 deletions

File tree

tests/Unit/EventListener/SoftwareCatalogEventListenerTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,23 @@ public function testHandleGebruikerRevertedEvent(): void
368368
*
369369
* @return void
370370
*/
371-
public function testHandleEventWithNullObject(): void
371+
public function testHandleEventWithUnmatchedSchema(): void
372372
{
373-
// Create ObjectCreatedEvent with null object
374-
$event = new ObjectCreatedEvent(null);
373+
// Create a mock ObjectEntity with a schema that doesn't match any configured schema
374+
$object = $this->createMock(ObjectEntity::class);
375+
$object->method('getSchema')->willReturn(999999);
376+
$object->method('getUuid')->willReturn('test-uuid');
377+
$object->method('getRegister')->willReturn(1);
375378

376-
// No service methods should be called
379+
// Create ObjectCreatedEvent with a valid object but unmatched schema
380+
$event = new ObjectCreatedEvent($object);
381+
382+
// No service methods should be called since schema doesn't match
377383
$this->softwareCatalogueService
378384
->expects($this->never())
379385
->method($this->anything());
380386

381-
// Handle the event - should return early
387+
// Handle the event - should return early since schema doesn't match
382388
$this->eventListener->handle($event);
383389
}
384390

tests/Unit/OrganisationUserWorkflowTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
use OCP\IUser;
3333
use OCP\IGroup;
3434
use OCP\IRequest;
35+
use OCP\IUserSession;
3536
use OCP\Security\ISecureRandom;
37+
use Psr\Container\ContainerInterface;
3638
use PHPUnit\Framework\TestCase;
3739
use PHPUnit\Framework\MockObject\MockObject;
3840
use Psr\Log\LoggerInterface;
@@ -146,6 +148,8 @@ protected function setUp(): void
146148
$this->contactpersoonService,
147149
$this->userManager,
148150
$this->groupManager,
151+
$this->createMock(IUserSession::class),
152+
$this->createMock(ContainerInterface::class),
149153
$this->createMock(ISecureRandom::class),
150154
$this->logger
151155
);

tests/Unit/Service/ContactPersonHandlerTest.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
use OCA\SoftwareCatalog\Service\SoftwareCatalogue\ContactPersonHandler;
88
use OCA\SoftwareCatalog\Service\SettingsService;
9+
use OCA\SoftwareCatalog\Service\SymfonyEmailService;
10+
use OCP\App\IAppManager;
11+
use OCP\IAppConfig;
12+
use OCP\IConfig;
913
use OCP\IUserManager;
1014
use OCP\IGroupManager;
1115
use OCP\IUser;
1216
use OCP\IGroup;
13-
use OCP\IContainer;
17+
use OCP\Security\ISecureRandom;
18+
use Psr\Container\ContainerInterface;
1419
use PHPUnit\Framework\TestCase;
1520
use PHPUnit\Framework\MockObject\MockObject;
1621
use Psr\Log\LoggerInterface;
@@ -47,11 +52,11 @@ class ContactPersonHandlerTest extends TestCase
4752
private IGroupManager|MockObject $groupManager;
4853

4954
/**
50-
* Mock of the IContainer service
55+
* Mock of the ContainerInterface service
5156
*
52-
* @var IContainer|MockObject
57+
* @var ContainerInterface|MockObject
5358
*/
54-
private IContainer|MockObject $container;
59+
private ContainerInterface|MockObject $container;
5560

5661
/**
5762
* Mock of the LoggerInterface
@@ -86,7 +91,7 @@ protected function setUp(): void
8691
// Create mocks
8792
$this->userManager = $this->createMock(IUserManager::class);
8893
$this->groupManager = $this->createMock(IGroupManager::class);
89-
$this->container = $this->createMock(IContainer::class);
94+
$this->container = $this->createMock(ContainerInterface::class);
9095
$this->logger = $this->createMock(LoggerInterface::class);
9196
$this->settingsService = $this->createMock(SettingsService::class);
9297

@@ -98,9 +103,14 @@ protected function setUp(): void
98103
// Create the ContactPersonHandler instance
99104
$this->contactPersonHandler = new ContactPersonHandler(
100105
$this->userManager,
106+
$this->createMock(ISecureRandom::class),
101107
$this->groupManager,
108+
$this->createMock(IAppConfig::class),
102109
$this->container,
103-
$this->logger
110+
$this->createMock(IAppManager::class),
111+
$this->logger,
112+
$this->createMock(SymfonyEmailService::class),
113+
$this->createMock(IConfig::class)
104114
);
105115
}
106116

0 commit comments

Comments
 (0)