Skip to content

Commit 34d1b44

Browse files
committed
Fix unit tests
1 parent 3c4675a commit 34d1b44

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

tests/Unit/Schedule/ScheduleClientTestCase.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Temporal\Tests\Unit\Schedule;
66

7-
use DateTimeImmutable;
87
use PHPUnit\Framework\Attributes\CoversClass;
98
use Spiral\Attributes\AttributeReader;
109
use Temporal\Api\Workflowservice\V1\CreateScheduleRequest;
@@ -43,9 +42,10 @@ public function testCreateSchedule(): void
4342
};
4443
// Prepare mocks
4544
$clientMock = $this->createMock(ServiceClientInterface::class);
45+
$clientMock->expects($this->once())->method('withContext')->willReturnSelf();
4646
$clientMock->expects($this->once())
4747
->method('CreateSchedule')
48-
->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
48+
->with($this->callback(static fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
4949
->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token'));
5050
$scheduleClient = $this->createScheduleClient(
5151
client: $clientMock,
@@ -71,9 +71,10 @@ public function testCreateScheduleNamespaceFromOptions(): void
7171
};
7272
// Prepare mocks
7373
$clientMock = $this->createMock(ServiceClientInterface::class);
74+
$clientMock->expects($this->once())->method('withContext')->willReturnSelf();
7475
$clientMock->expects($this->once())
7576
->method('CreateSchedule')
76-
->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
77+
->with($this->callback(static fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
7778
->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token'));
7879
$scheduleClient = $this->createScheduleClient(
7980
client: $clientMock,
@@ -97,9 +98,10 @@ public function testCreateScheduleNamespaceFromServiceClient(): void
9798
};
9899
// Prepare mocks
99100
$clientMock = $this->createMock(ServiceClientInterface::class);
101+
$clientMock->expects($this->once())->method('withContext')->willReturnSelf();
100102
$clientMock->expects($this->once())
101103
->method('CreateSchedule')
102-
->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
104+
->with($this->callback(static fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
103105
->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token'));
104106
$scheduleClient = $this->createScheduleClient(
105107
client: $clientMock,
@@ -124,16 +126,17 @@ public function testCreateScheduleWithoutWorkflowId(): void
124126
};
125127
// Prepare mocks
126128
$clientMock = $this->createMock(ServiceClientInterface::class);
129+
$clientMock->expects($this->once())->method('withContext')->willReturnSelf();
127130
$clientMock->expects($this->once())
128131
->method('CreateSchedule')
129-
->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
132+
->with($this->callback(static fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
130133
->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token'));
131134
$scheduleClient = $this->createScheduleClient(
132135
client: $clientMock,
133136
);
134137
$result = $scheduleClient->createSchedule(
135138
Schedule::new()->withAction(
136-
StartWorkflowAction::new('PingSite')
139+
StartWorkflowAction::new('PingSite'),
137140
),
138141
scheduleId: 'test-id',
139142
);
@@ -149,9 +152,10 @@ public function testListSchedules(): void
149152
};
150153
// Prepare mocks
151154
$clientMock = $this->createMock(ServiceClientInterface::class);
155+
$clientMock->expects($this->once())->method('withContext')->willReturnSelf();
152156
$clientMock->expects($this->once())
153157
->method('ListSchedules')
154-
->with($this->callback(fn(ListSchedulesRequest $request) => $testContext->request = $request or true))
158+
->with($this->callback(static fn(ListSchedulesRequest $request) => $testContext->request = $request or true))
155159
->willReturn((new ListSchedulesResponse()));
156160
$scheduleClient = $this->createScheduleClient(
157161
client: $clientMock,
@@ -176,9 +180,10 @@ public function testScheduleMarshalling(): void
176180
};
177181
// Prepare mocks
178182
$clientMock = $this->createMock(ServiceClientInterface::class);
183+
$clientMock->expects($this->once())->method('withContext')->willReturnSelf();
179184
$clientMock->expects($this->once())
180185
->method('CreateSchedule')
181-
->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
186+
->with($this->callback(static fn(CreateScheduleRequest $request) => $testContext->request = $request or true))
182187
->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token'));
183188
$scheduleClient = $this->createScheduleClient(
184189
client: $clientMock,
@@ -279,35 +284,36 @@ private function getScheduleDto(): Schedule
279284
->withMemo(['foo' => 'memo'])
280285
->withSearchAttributes(['foo' => 'search'])
281286
->withWorkflowId('workflow-id')
282-
->withWorkflowIdReusePolicy(WorkflowIdReusePolicy::AllowDuplicateFailedOnly)
287+
->withWorkflowIdReusePolicy(WorkflowIdReusePolicy::AllowDuplicateFailedOnly),
283288
)->withSpec(
284289
ScheduleSpec::new()
285290
->withStructuredCalendarList(
286291
StructuredCalendarSpec::new()
287292
->withDaysOfWeek(Range::new(1, 5))
288-
->withHours(Range::new(9, 9), Range::new(12, 12))
293+
->withHours(Range::new(9, 9), Range::new(12, 12)),
289294
)
290295
->withCalendarList(
291296
CalendarSpec::new()
292297
->withSecond(6)
293298
->withMinute('*/6')
294-
->withComment('test comment')
299+
->withComment('test comment'),
295300
)
296301
->withCronStringList('0 12 * * 5', '0 12 * * 1')
297-
->withStartTime(new DateTimeImmutable('2024-10-01T00:00:00Z'))
298-
->withEndTime(new DateTimeImmutable('2024-10-31T00:00:00Z'))
302+
->withStartTime(new \DateTimeImmutable('2024-10-01T00:00:00Z'))
303+
->withEndTime(new \DateTimeImmutable('2024-10-31T00:00:00Z'))
299304
->withJitter('10m')
300-
->withTimezoneName('UTC')
301-
)->withPolicies(SchedulePolicies::new()
302-
->withCatchupWindow('10m')
303-
->withPauseOnFailure(true)
304-
->withOverlapPolicy(ScheduleOverlapPolicy::CancelOther)
305+
->withTimezoneName('UTC'),
306+
)->withPolicies(
307+
SchedulePolicies::new()
308+
->withCatchupWindow('10m')
309+
->withPauseOnFailure(true)
310+
->withOverlapPolicy(ScheduleOverlapPolicy::CancelOther),
305311
)->withState(
306312
ScheduleState::new()
307313
->withLimitedActions(true)
308314
->withRemainingActions(10)
309315
->withPaused(true)
310-
->withNotes('test notes')
316+
->withNotes('test notes'),
311317
);
312318
}
313319
}

0 commit comments

Comments
 (0)