Skip to content

Commit 482a49d

Browse files
mowens3claude
andcommitted
Fix test mocks: return int from getCurrentTime, add setCreatedTime to node stub
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 324ca4c commit 482a49d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

modules/mcp_tools_batch/tests/src/Unit/Service/BatchServiceTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#[\PHPUnit\Framework\Attributes\Group('mcp_tools_batch')]
2121
final class BatchServiceTest extends UnitTestCase {
2222

23+
private function mockTime(): TimeInterface {
24+
$time = $this->createMock(TimeInterface::class);
25+
$time->method('getCurrentTime')->willReturn(time());
26+
return $time;
27+
}
28+
2329
private function createService(): BatchService {
2430
return new class(
2531
$this->createMock(EntityTypeManagerInterface::class),
@@ -50,7 +56,7 @@ private function createBatchService(array $overrides = []): BatchService {
5056
$overrides['module_handler'] ?? $this->createMock(ModuleHandlerInterface::class),
5157
$overrides['access_manager'] ?? $this->createMock(AccessManager::class),
5258
$overrides['audit_logger'] ?? $this->createMock(AuditLogger::class),
53-
$overrides['time'] ?? $this->createMock(TimeInterface::class),
59+
$overrides['time'] ?? $this->mockTime(),
5460
);
5561
}
5662

@@ -124,6 +130,8 @@ public function testCreateMultipleContentCreatesItemsViaStorage(): void {
124130
public function save(): void {}
125131
public function id(): int { return 123; }
126132
public function uuid(): string { return 'uuid-123'; }
133+
public function setCreatedTime(int $timestamp): void {}
134+
public function setChangedTime(int $timestamp): void {}
127135
public function toUrl(): object {
128136
return new class() { public function toString(): string { return '/node/123'; } };
129137
}

modules/mcp_tools_content/tests/src/Unit/Service/ContentServiceTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
#[\PHPUnit\Framework\Attributes\Group('mcp_tools_content')]
2727
class ContentServiceTest extends UnitTestCase {
2828

29+
protected function mockTime(): TimeInterface {
30+
$time = $this->createMock(TimeInterface::class);
31+
$time->method('getCurrentTime')->willReturn(time());
32+
return $time;
33+
}
34+
2935
protected EntityTypeManagerInterface $entityTypeManager;
3036
protected EntityFieldManagerInterface $entityFieldManager;
3137
protected AccountProxyInterface $currentUser;
@@ -68,7 +74,7 @@ protected function createContentService(): ContentService {
6874
$this->currentUser,
6975
$this->accessManager,
7076
$this->auditLogger,
71-
$this->createMock(TimeInterface::class),
77+
$this->mockTime(),
7278
);
7379
}
7480

modules/mcp_tools_media/tests/src/Unit/Service/MediaServiceTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#[\PHPUnit\Framework\Attributes\Group('mcp_tools_media')]
2323
class MediaServiceTest extends UnitTestCase {
2424

25+
protected function mockTime(): TimeInterface {
26+
$time = $this->createMock(TimeInterface::class);
27+
$time->method('getCurrentTime')->willReturn(time());
28+
return $time;
29+
}
30+
2531
protected EntityTypeManagerInterface $entityTypeManager;
2632
protected FileSystemInterface $fileSystem;
2733
protected AccessManager $accessManager;
@@ -62,7 +68,7 @@ protected function createMediaService(): MediaService {
6268
$this->fileSystem,
6369
$this->accessManager,
6470
$this->auditLogger,
65-
$this->createMock(TimeInterface::class),
71+
$this->mockTime(),
6672
);
6773
}
6874

0 commit comments

Comments
 (0)