|
17 | 17 | use Temporal\Client\Schedule\Policy\ScheduleOverlapPolicy; |
18 | 18 | use Temporal\Client\Schedule\Policy\SchedulePolicies; |
19 | 19 | use Temporal\Client\Schedule\Schedule; |
| 20 | +use Temporal\Client\Schedule\ScheduleOptions; |
20 | 21 | use Temporal\Client\Schedule\Spec\CalendarSpec; |
21 | 22 | use Temporal\Client\Schedule\Spec\Range; |
22 | 23 | use Temporal\Client\Schedule\Spec\ScheduleSpec; |
@@ -63,6 +64,59 @@ public function testCreateSchedule(): void |
63 | 64 | ); |
64 | 65 | } |
65 | 66 |
|
| 67 | + public function testCreateScheduleNamespaceFromOptions(): void |
| 68 | + { |
| 69 | + $testContext = new class { |
| 70 | + public CreateScheduleRequest $request; |
| 71 | + }; |
| 72 | + // Prepare mocks |
| 73 | + $clientMock = $this->createMock(ServiceClientInterface::class); |
| 74 | + $clientMock->expects($this->once()) |
| 75 | + ->method('CreateSchedule') |
| 76 | + ->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true)) |
| 77 | + ->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token')); |
| 78 | + $scheduleClient = $this->createScheduleClient( |
| 79 | + client: $clientMock, |
| 80 | + ); |
| 81 | + $scheduleDto = $this->getScheduleDto(); |
| 82 | + |
| 83 | + $scheduleClient->createSchedule( |
| 84 | + $scheduleDto, |
| 85 | + options: ScheduleOptions::new()->withNamespace('test-namespace'), |
| 86 | + scheduleId: 'test-id', |
| 87 | + ); |
| 88 | + |
| 89 | + $this->assertTrue(isset($testContext->request)); |
| 90 | + $this->assertSame('test-namespace', $testContext->request->getNamespace()); |
| 91 | + } |
| 92 | + |
| 93 | + public function testCreateScheduleNamespaceFromServiceClient(): void |
| 94 | + { |
| 95 | + $testContext = new class { |
| 96 | + public CreateScheduleRequest $request; |
| 97 | + }; |
| 98 | + // Prepare mocks |
| 99 | + $clientMock = $this->createMock(ServiceClientInterface::class); |
| 100 | + $clientMock->expects($this->once()) |
| 101 | + ->method('CreateSchedule') |
| 102 | + ->with($this->callback(fn(CreateScheduleRequest $request) => $testContext->request = $request or true)) |
| 103 | + ->willReturn((new CreateScheduleResponse())->setConflictToken('test-conflict-token')); |
| 104 | + $scheduleClient = $this->createScheduleClient( |
| 105 | + client: $clientMock, |
| 106 | + clientOptions: (new ClientOptions())->withNamespace('test-namespace'), |
| 107 | + ); |
| 108 | + $scheduleDto = $this->getScheduleDto(); |
| 109 | + |
| 110 | + $scheduleClient->createSchedule( |
| 111 | + $scheduleDto, |
| 112 | + options: ScheduleOptions::new(), |
| 113 | + scheduleId: 'test-id', |
| 114 | + ); |
| 115 | + |
| 116 | + $this->assertTrue(isset($testContext->request)); |
| 117 | + $this->assertSame('test-namespace', $testContext->request->getNamespace()); |
| 118 | + } |
| 119 | + |
66 | 120 | public function testCreateScheduleWithoutWorkflowId(): void |
67 | 121 | { |
68 | 122 | $testContext = new class { |
|
0 commit comments