result = $result; } public function where(...$args) { return $this; } public function first(): ?array { return $this->result; } }; } private function buildGetController( array $getParams, $clientPolicyModel, $reminderMailConfigModel, ?object $notificationModel = null ): EmployeeRestController { $request = $this->createMock(IncomingRequest::class); $request->method('getGet') ->willReturnCallback(function ($key = null) use ($getParams) { if ($key === null) { return $getParams; } return array_key_exists($key, $getParams) ? $getParams[$key] : null; }); return $this->injectReminderMailControllerDependencies( $request, $clientPolicyModel, $reminderMailConfigModel, $notificationModel ); } private function buildJsonPostController( array $jsonData, $clientPolicyModel, $reminderMailConfigModel, bool $isPost = true, ?object $notificationModel = null, ?EmployeeRestController $controller = null ): EmployeeRestController { $request = $this->createMock(IncomingRequest::class); $request->method('is') ->with('post') ->willReturn($isPost); $request->method('getJSON') ->with(true) ->willReturn($jsonData); $request->method('getVar') ->willReturn(null); $controller = $controller ?? new EmployeeRestController(); return $this->injectReminderMailControllerDependencies( $request, $clientPolicyModel, $reminderMailConfigModel, $notificationModel, $controller ); } private function injectReminderMailControllerDependencies( IncomingRequest $request, $clientPolicyModel, $reminderMailConfigModel, ?object $notificationModel = null, ?EmployeeRestController $controller = null ): EmployeeRestController { $controller = $controller ?? new EmployeeRestController(); $controller->initController($request, Services::response(), Services::logger()); $reflection = new ReflectionClass($controller); foreach ([ 'clientPolicyModel' => $clientPolicyModel, 'reminderMailConfigModel' => $reminderMailConfigModel, 'notificationModel' => $notificationModel, ] as $property => $value) { if ($value === null) { continue; } $prop = $reflection->getProperty($property); $prop->setAccessible(true); $prop->setValue($controller, $value); } return $controller; } private function decodeResponse($response): array { return json_decode($response->getBody(), true); } }