From 523011ff0b896319a1406c2f1eed7e56da457ce5 Mon Sep 17 00:00:00 2001 From: Nick Dawson Date: Fri, 28 Jun 2024 14:11:17 -0400 Subject: [PATCH 1/5] Dates return null if provided XML is blank or null --- src/Client.php | 29 ++++-- src/DataTypes/LearnerReport.php | 30 +++--- tests/Client/GetLearnerReportClientTest.php | 106 ++++++++++++++++++-- 3 files changed, 131 insertions(+), 34 deletions(-) diff --git a/src/Client.php b/src/Client.php index b3e5fa5..fe745d2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1039,8 +1039,8 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { ->setGivenName((string) $report->FirstName) ->setLearningModuleId((string) $report->LearningModuleID) ->setUserId((string) $report->UserID) - ->setCreatedDate(new DateTime((string) $report->CreatedDate)) - ->setModifiedDate(new DateTime((string)$report->ModifiedDate)); + ->setCreatedDate($this->setDateToBlankOrDateTimeObject((string)$report->CreatedDate)) + ->setModifiedDate($this->setDateToBlankOrDateTimeObject((string)$report->ModifiedDate)); // Other values may or may not be returned, depending on the input. if (isset($report->AlternateEmail)) { @@ -1050,7 +1050,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->CompletedDate)) { $currentReport->setCompletedDate( - new DateTime((string) $report->CompletedDate) + $this->setDateToBlankOrDateTimeObject((string) $report->CompletedDate) ); } if (isset($report->CourseDuration)) { @@ -1068,7 +1068,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->DueDate)) { $currentReport->setDueDate( - new DateTime((string) $report->DueDate) + $this->setDateToBlankOrDateTimeObject((string) $report->DueDate) ); } if (isset($report->EmployeeID)) { @@ -1078,7 +1078,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->EnrolledDate)) { $currentReport->setEnrolledDate( - new DateTime((string) $report->EnrolledDate) + $this->setDateToBlankOrDateTimeObject((string) $report->EnrolledDate) ); } if (isset($report->Grade)) { @@ -1097,7 +1097,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->LastAccessedDate)) { $currentReport->setLastAccessedDate( - new DateTime((string) $report->LastAccessedDate) + $this->setDateToBlankOrDateTimeObject((string) $report->LastAccessedDate) ); } if (isset($report->Points)) { @@ -1111,7 +1111,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->StartedDate)) { $currentReport->setStartedDate( - new DateTime((string) $report->StartedDate) + $this->setDateToBlankOrDateTimeObject((string) $report->StartedDate) ); } if (isset($report->SubscriptionName)) { @@ -1127,7 +1127,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->VariantEndDate)) { $currentReport->setVariantEndDate( - new DateTime((string) $report->VariantEndDate) + $this->setDateToBlankOrDateTimeObject((string) $report->VariantEndDate) ); } if (isset($report->VariantName)) { @@ -1135,7 +1135,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->VariantStartDate)) { $currentReport->setVariantStartDate( - new DateTime((string) $report->VariantStartDate) + $this->setDateToBlankOrDateTimeObject((string) $report->VariantStartDate) ); } $learnerReports[] = $currentReport; @@ -1143,6 +1143,17 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { return $learnerReports; } + + /** + * Sets the provided date to either a blank string or a DateTime object. + */ + private function setDateToBlankOrDateTimeObject(string $dateString): ?DateTime { + if ($dateString === null || $dateString === '') { + return null; + } else { + return new DateTime((string) $dateString); + } + } /** * Make a RequestExternalAuthorization query to the SmarterU API using the diff --git a/src/DataTypes/LearnerReport.php b/src/DataTypes/LearnerReport.php index 50e0428..5f5abc5 100644 --- a/src/DataTypes/LearnerReport.php +++ b/src/DataTypes/LearnerReport.php @@ -104,12 +104,12 @@ class LearnerReport { /** * The UTC date the enrollment was created. */ - protected DateTimeInterface $createdDate; + protected ?DateTimeInterface $createdDate; /** * The UTC date the enrollment was last updated. */ - protected DateTimeInterface $modifiedDate; + protected ?DateTimeInterface $modifiedDate; /** * The UTC date the User was enrolled in the Course. @@ -489,9 +489,9 @@ public function setCourseSessionId(string $courseSessionId): self { /** * Get the UTC date the enrollment was created. * - * @return DateTimeInterface The UTC date the enrollment was created. + * @return ?DateTimeInterface The UTC date the enrollment was created. */ - public function getCreatedDate(): DateTimeInterface { + public function getCreatedDate(): ?DateTimeInterface { return $this->createdDate; } @@ -502,7 +502,7 @@ public function getCreatedDate(): DateTimeInterface { * created. * @return self */ - public function setCreatedDate(DateTimeInterface $createdDate): self { + public function setCreatedDate(?DateTimeInterface $createdDate): self { $this->createdDate = $createdDate; return $this; } @@ -510,9 +510,9 @@ public function setCreatedDate(DateTimeInterface $createdDate): self { /** * Get the UTC date the enrollment was last updated. * - * @return DateTimeInterface The UTC date the enrollment was last updated. + * @return ?DateTimeInterface The UTC date the enrollment was last updated. */ - public function getModifiedDate(): DateTimeInterface { + public function getModifiedDate(): ?DateTimeInterface { return $this->modifiedDate; } @@ -523,7 +523,7 @@ public function getModifiedDate(): DateTimeInterface { * last updated. * @return self */ - public function setModifiedDate(DateTimeInterface $modifiedDate): self { + public function setModifiedDate(?DateTimeInterface $modifiedDate): self { $this->modifiedDate = $modifiedDate; return $this; } @@ -590,7 +590,7 @@ public function getEnrolledDate(): ?DateTimeInterface { * @param DateTimeInterface $enrolledDate The UTC date the User was enrolled. * @return self */ - public function setEnrolledDate(DateTimeInterface $enrolledDate): self { + public function setEnrolledDate(?DateTimeInterface $enrolledDate): self { $this->enrolledDate = $enrolledDate; return $this; } @@ -610,7 +610,7 @@ public function getDueDate(): ?DateTimeInterface { * @param DateTimeInterface $dueDate The UTC date the Course is due. * @return self */ - public function setDueDate(DateTimeInterface $dueDate): self { + public function setDueDate(?DateTimeInterface $dueDate): self { $this->dueDate = $dueDate; return $this; } @@ -630,7 +630,7 @@ public function getStartedDate(): ?DateTimeInterface { * @param DateTimeInterface $startedDate The UTC date the User started the Course. * @return self */ - public function setStartedDate(DateTimeInterface $startedDate): self { + public function setStartedDate(?DateTimeInterface $startedDate): self { $this->startedDate = $startedDate; return $this; } @@ -651,7 +651,7 @@ public function getLastAccessedDate(): ?DateTimeInterface { * accessed the Course. * @return self */ - public function setLastAccessedDate(DateTimeInterface $lastAccessedDate): self { + public function setLastAccessedDate(?DateTimeInterface $lastAccessedDate): self { $this->lastAccessedDate = $lastAccessedDate; return $this; } @@ -672,7 +672,7 @@ public function getCompletedDate(): ?DateTimeInterface { * the Course. * @return self */ - public function setCompletedDate(DateTimeInterface $completedDate): self { + public function setCompletedDate(?DateTimeInterface $completedDate): self { $this->completedDate = $completedDate; return $this; } @@ -813,7 +813,7 @@ public function getVariantStartDate(): ?DateTimeInterface { * variant started. * @return self */ - public function setVariantStartDate(DateTimeInterface $variantStartDate): self { + public function setVariantStartDate(?DateTimeInterface $variantStartDate): self { $this->variantStartDate = $variantStartDate; return $this; } @@ -834,7 +834,7 @@ public function getVariantEndDate(): ?DateTimeInterface { * variant ends. * @return self */ - public function setVariantEndDate(DateTimeInterface $variantEndDate): self { + public function setVariantEndDate(?DateTimeInterface $variantEndDate): self { $this->variantEndDate = $variantEndDate; return $this; } diff --git a/tests/Client/GetLearnerReportClientTest.php b/tests/Client/GetLearnerReportClientTest.php index 4b901cc..cf578e3 100644 --- a/tests/Client/GetLearnerReportClientTest.php +++ b/tests/Client/GetLearnerReportClientTest.php @@ -294,7 +294,7 @@ public function testGetLearnerReportProducesCorrectOutputWithoutOptionalInfoSing $modifiedDate, $report->getModifiedDate()->format('d-M-y') ); - self::assertNull($report->getUserEmail()); + self::assertNull($report->getLearnerEmail()); self::assertNull($report->getAlternateEmail()); self::assertNull($report->getEmployeeId()); self::assertNull($report->getDivision()); @@ -319,6 +319,91 @@ public function testGetLearnerReportProducesCorrectOutputWithoutOptionalInfoSing self::assertNull($report->getRoleId()); } + /** + * Test that Client::getLearnerReport() produces the correct output when + * the query does not contain any optional information and the SmarterU API + * returns a single LearnerReport. + */ + public function testGetLearnerReportProducesCorrectOutputWithBlankDates() { + $accountApi = 'account'; + $userApi = 'user'; + $client = new Client($accountApi, $userApi); + + $query = (new GetLearnerReportQuery()) + ->setEnrollmentId('1') + ->setGroupStatus('Active') + ->setUserStatus('Active'); + + $id = '1'; + $courseName = 'My Course'; + $lastName = 'User'; + $firstName = 'Test'; + $learningModuleId = '2'; + $userId = '3'; + $createdDate = ''; + $modifiedDate = null; + + $xmlString = << + Success + + + + $id + $courseName + $lastName + $firstName + $learningModuleId + $userId + $createdDate + $modifiedDate + + + + + + + XML; + + // Set up the container to capture the request. + $response = new Response(200, [], $xmlString); + $container = []; + $history = Middleware::history($container); + $mock = (new MockHandler([$response])); + $handlerStack = HandlerStack::create($mock); + $handlerStack->push($history); + $httpClient = new HttpClient(['handler' => $handlerStack]); + $client->setHttpClient($httpClient); + + // Make the request. + $result = $client->getLearnerReport($query); + + // Make sure there is only 1 request, then translate it to XML. + self::assertCount(1, $container); + $request = $container[0]['request']; + $decodedBody = urldecode((string) $request->getBody()); + $expectedBody = 'Package=' . $client->getXMLGenerator()->getLearnerReport( + $accountApi, + $userApi, + $query + ); + self::assertEquals($decodedBody, $expectedBody); + + // Make sure the expected value is returned. + self::assertIsArray($result); + self::assertCount(1, $result); + $report = $result[0]; + self::assertInstanceOf(LearnerReport::class, $report); + self::assertEquals($id, $report->getId()); + self::assertEquals($courseName, $report->getCourseName()); + self::assertEquals($lastName, $report->getSurname()); + self::assertEquals($firstName, $report->getGivenName()); + self::assertEquals($learningModuleId, $report->getLearningModuleId()); + self::assertEquals($userId, $report->getUserId()); + self::assertNull($report->getCreatedDate()); + self::assertNull($report->getModifiedDate()); + } + /** * Test that Client::getLearnerReport() produces the correct output when * the query contains all optional information and the SmarterU API @@ -468,7 +553,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoSingleR $startedDate $subscriptionName $title - $userEmail + $userEmail $variantEndDate $variantName $variantStartDate @@ -523,7 +608,8 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoSingleR $modifiedDate, $report->getModifiedDate()->format('d-M-y') ); - self::assertEquals($userEmail, $report->getUserEmail()); + + self::assertEquals($userEmail, $report->getLearnerEmail()); self::assertEquals($alternateEmail, $report->getAlternateEmail()); self::assertEquals($employeeId, $report->getEmployeeId()); self::assertEquals($division, $report->getDivision()); @@ -677,7 +763,7 @@ public function testGetLearnerReportProducesCorrectOutputWithoutOptionalInfoMult $modifiedDate, $report->getModifiedDate()->format('d-M-y') ); - self::assertNull($report->getUserEmail()); + self::assertNull($report->getLearnerEmail()); self::assertNull($report->getAlternateEmail()); self::assertNull($report->getEmployeeId()); self::assertNull($report->getDivision()); @@ -923,7 +1009,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoMultipl $startedDate $subscriptionName $title - $userEmail + $userEmail $variantEndDate $variantName $variantStartDate @@ -956,7 +1042,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoMultipl $startedDate2 $subscriptionName2 $title2 - $userEmail2 + $userEmail2 $variantEndDate2 $variantName2 $variantStartDate2 @@ -989,7 +1075,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoMultipl $startedDate3 $subscriptionName3 $title3 - $userEmail3 + $userEmail3 $variantEndDate3 $variantName3 $variantStartDate3 @@ -1046,7 +1132,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoMultipl $modifiedDate, $report1->getModifiedDate()->format('d-M-y') ); - self::assertEquals($userEmail, $report1->getUserEmail()); + self::assertEquals($userEmail, $report1->getLearnerEmail()); self::assertEquals($alternateEmail, $report1->getAlternateEmail()); self::assertEquals($employeeId, $report1->getEmployeeId()); self::assertEquals($division, $report1->getDivision()); @@ -1102,7 +1188,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoMultipl $modifiedDate2, $report2->getModifiedDate()->format('d-M-y') ); - self::assertEquals($userEmail2, $report2->getUserEmail()); + self::assertEquals($userEmail2, $report2->getLearnerEmail()); self::assertEquals($alternateEmail2, $report2->getAlternateEmail()); self::assertEquals($employeeId2, $report2->getEmployeeId()); self::assertEquals($division2, $report2->getDivision()); @@ -1158,7 +1244,7 @@ public function testGetLearnerReportProducesCorrectOutputWithOptionalInfoMultipl $modifiedDate3, $report3->getModifiedDate()->format('d-M-y') ); - self::assertEquals($userEmail3, $report3->getUserEmail()); + self::assertEquals($userEmail3, $report3->getLearnerEmail()); self::assertEquals($alternateEmail3, $report3->getAlternateEmail()); self::assertEquals($employeeId3, $report3->getEmployeeId()); self::assertEquals($division3, $report3->getDivision()); From 8246237841190d6643b1cf108f4e506b4e8ed892 Mon Sep 17 00:00:00 2001 From: Nick Dawson Date: Mon, 1 Jul 2024 07:49:10 -0400 Subject: [PATCH 2/5] changed function name --- src/Client.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Client.php b/src/Client.php index fe745d2..3998631 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1039,8 +1039,8 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { ->setGivenName((string) $report->FirstName) ->setLearningModuleId((string) $report->LearningModuleID) ->setUserId((string) $report->UserID) - ->setCreatedDate($this->setDateToBlankOrDateTimeObject((string)$report->CreatedDate)) - ->setModifiedDate($this->setDateToBlankOrDateTimeObject((string)$report->ModifiedDate)); + ->setCreatedDate($this->setDateToNullOrDateTimeObject((string)$report->CreatedDate)) + ->setModifiedDate($this->setDateToNullOrDateTimeObject((string)$report->ModifiedDate)); // Other values may or may not be returned, depending on the input. if (isset($report->AlternateEmail)) { @@ -1050,7 +1050,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->CompletedDate)) { $currentReport->setCompletedDate( - $this->setDateToBlankOrDateTimeObject((string) $report->CompletedDate) + $this->setDateToNullOrDateTimeObject((string) $report->CompletedDate) ); } if (isset($report->CourseDuration)) { @@ -1068,7 +1068,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->DueDate)) { $currentReport->setDueDate( - $this->setDateToBlankOrDateTimeObject((string) $report->DueDate) + $this->setDateToNullOrDateTimeObject((string) $report->DueDate) ); } if (isset($report->EmployeeID)) { @@ -1078,7 +1078,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->EnrolledDate)) { $currentReport->setEnrolledDate( - $this->setDateToBlankOrDateTimeObject((string) $report->EnrolledDate) + $this->setDateToNullOrDateTimeObject((string) $report->EnrolledDate) ); } if (isset($report->Grade)) { @@ -1097,7 +1097,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->LastAccessedDate)) { $currentReport->setLastAccessedDate( - $this->setDateToBlankOrDateTimeObject((string) $report->LastAccessedDate) + $this->setDateToNullOrDateTimeObject((string) $report->LastAccessedDate) ); } if (isset($report->Points)) { @@ -1111,7 +1111,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->StartedDate)) { $currentReport->setStartedDate( - $this->setDateToBlankOrDateTimeObject((string) $report->StartedDate) + $this->setDateToNullOrDateTimeObject((string) $report->StartedDate) ); } if (isset($report->SubscriptionName)) { @@ -1127,7 +1127,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->VariantEndDate)) { $currentReport->setVariantEndDate( - $this->setDateToBlankOrDateTimeObject((string) $report->VariantEndDate) + $this->setDateToNullOrDateTimeObject((string) $report->VariantEndDate) ); } if (isset($report->VariantName)) { @@ -1135,7 +1135,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->VariantStartDate)) { $currentReport->setVariantStartDate( - $this->setDateToBlankOrDateTimeObject((string) $report->VariantStartDate) + $this->setDateToNullOrDateTimeObject((string) $report->VariantStartDate) ); } $learnerReports[] = $currentReport; @@ -1147,7 +1147,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { /** * Sets the provided date to either a blank string or a DateTime object. */ - private function setDateToBlankOrDateTimeObject(string $dateString): ?DateTime { + private function setDateToNullOrDateTimeObject(string $dateString): ?DateTime { if ($dateString === null || $dateString === '') { return null; } else { From 58927e0404cc0b5a2ab69fc16c79cbbe1fe82e5f Mon Sep 17 00:00:00 2001 From: Nick Dawson Date: Mon, 1 Jul 2024 08:18:14 -0400 Subject: [PATCH 3/5] updated docblock --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 3998631..b40ecc5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1145,7 +1145,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } /** - * Sets the provided date to either a blank string or a DateTime object. + * Sets the provided date to either null or a DateTime object. */ private function setDateToNullOrDateTimeObject(string $dateString): ?DateTime { if ($dateString === null || $dateString === '') { From e081cd0bfb19d30fa33bd0dade41d08faff51691 Mon Sep 17 00:00:00 2001 From: Nick Dawson Date: Mon, 1 Jul 2024 10:01:23 -0400 Subject: [PATCH 4/5] PR changes --- src/Client.php | 42 +++++++++++---------- src/DataTypes/LearnerReport.php | 4 +- tests/Client/GetLearnerReportClientTest.php | 2 - 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Client.php b/src/Client.php index b40ecc5..e6b06d4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -26,6 +26,8 @@ use CBS\SmarterU\Queries\ListGroupsQuery; use CBS\SmarterU\Queries\ListUsersQuery; use DateTime; +use DateTimeInterface; +use DateTimeImmutable; use GuzzleHttp\Client as HttpClient; use GuzzleHttp\Exception\ClientException; use Psr\Log\LoggerAwareTrait; @@ -1039,8 +1041,8 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { ->setGivenName((string) $report->FirstName) ->setLearningModuleId((string) $report->LearningModuleID) ->setUserId((string) $report->UserID) - ->setCreatedDate($this->setDateToNullOrDateTimeObject((string)$report->CreatedDate)) - ->setModifiedDate($this->setDateToNullOrDateTimeObject((string)$report->ModifiedDate)); + ->setCreatedDate($this->toDateTimeInterface((string)$report->CreatedDate)) + ->setModifiedDate($this->toDateTimeInterface((string)$report->ModifiedDate)); // Other values may or may not be returned, depending on the input. if (isset($report->AlternateEmail)) { @@ -1050,7 +1052,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->CompletedDate)) { $currentReport->setCompletedDate( - $this->setDateToNullOrDateTimeObject((string) $report->CompletedDate) + $this->toDateTimeInterface((string) $report->CompletedDate) ); } if (isset($report->CourseDuration)) { @@ -1068,7 +1070,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->DueDate)) { $currentReport->setDueDate( - $this->setDateToNullOrDateTimeObject((string) $report->DueDate) + $this->toDateTimeInterface((string) $report->DueDate) ); } if (isset($report->EmployeeID)) { @@ -1078,7 +1080,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->EnrolledDate)) { $currentReport->setEnrolledDate( - $this->setDateToNullOrDateTimeObject((string) $report->EnrolledDate) + $this->toDateTimeInterface((string) $report->EnrolledDate) ); } if (isset($report->Grade)) { @@ -1097,7 +1099,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->LastAccessedDate)) { $currentReport->setLastAccessedDate( - $this->setDateToNullOrDateTimeObject((string) $report->LastAccessedDate) + $this->toDateTimeInterface((string) $report->LastAccessedDate) ); } if (isset($report->Points)) { @@ -1111,7 +1113,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->StartedDate)) { $currentReport->setStartedDate( - $this->setDateToNullOrDateTimeObject((string) $report->StartedDate) + $this->toDateTimeInterface((string) $report->StartedDate) ); } if (isset($report->SubscriptionName)) { @@ -1127,7 +1129,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->VariantEndDate)) { $currentReport->setVariantEndDate( - $this->setDateToNullOrDateTimeObject((string) $report->VariantEndDate) + $this->toDateTimeInterface((string) $report->VariantEndDate) ); } if (isset($report->VariantName)) { @@ -1135,7 +1137,7 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { } if (isset($report->VariantStartDate)) { $currentReport->setVariantStartDate( - $this->setDateToNullOrDateTimeObject((string) $report->VariantStartDate) + $this->toDateTimeInterface((string) $report->VariantStartDate) ); } $learnerReports[] = $currentReport; @@ -1143,17 +1145,6 @@ public function getLearnerReport(GetLearnerReportQuery $query): array { return $learnerReports; } - - /** - * Sets the provided date to either null or a DateTime object. - */ - private function setDateToNullOrDateTimeObject(string $dateString): ?DateTime { - if ($dateString === null || $dateString === '') { - return null; - } else { - return new DateTime((string) $dateString); - } - } /** * Make a RequestExternalAuthorization query to the SmarterU API using the @@ -1518,6 +1509,17 @@ private function getErrorCodesFromXmlElement(SimpleXMLElement $errors): array { return $errorCodes; } + /** + * Sets the provided date to either null or a DateTimeInterface. + */ + private function toDateTimeInterface(string $dateString): DateTimeInterface|null { + if ($dateString === null || $dateString === '') { + return null; + } else { + return new DateTimeImmutable((string) $dateString); + } + } + /** * Accepts a request XML string and sanitizes it for logging purposes. * diff --git a/src/DataTypes/LearnerReport.php b/src/DataTypes/LearnerReport.php index 5f5abc5..b381ae6 100644 --- a/src/DataTypes/LearnerReport.php +++ b/src/DataTypes/LearnerReport.php @@ -104,12 +104,12 @@ class LearnerReport { /** * The UTC date the enrollment was created. */ - protected ?DateTimeInterface $createdDate; + protected ?DateTimeInterface $createdDate = null; /** * The UTC date the enrollment was last updated. */ - protected ?DateTimeInterface $modifiedDate; + protected ?DateTimeInterface $modifiedDate = null; /** * The UTC date the User was enrolled in the Course. diff --git a/tests/Client/GetLearnerReportClientTest.php b/tests/Client/GetLearnerReportClientTest.php index cf578e3..f688151 100644 --- a/tests/Client/GetLearnerReportClientTest.php +++ b/tests/Client/GetLearnerReportClientTest.php @@ -341,7 +341,6 @@ public function testGetLearnerReportProducesCorrectOutputWithBlankDates() { $learningModuleId = '2'; $userId = '3'; $createdDate = ''; - $modifiedDate = null; $xmlString = << @@ -356,7 +355,6 @@ public function testGetLearnerReportProducesCorrectOutputWithBlankDates() { $learningModuleId $userId $createdDate - $modifiedDate From 2af10485ae9a05c11213ef4522529464b5aa1888 Mon Sep 17 00:00:00 2001 From: nickdawsontcs <60976517+nickdawsontcs@users.noreply.github.com> Date: Mon, 1 Jul 2024 11:26:11 -0400 Subject: [PATCH 5/5] Update src/Client.php Co-authored-by: Tom Egan <61425509+tomegantcs@users.noreply.github.com> --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index e6b06d4..c9a0ba2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1513,7 +1513,7 @@ private function getErrorCodesFromXmlElement(SimpleXMLElement $errors): array { * Sets the provided date to either null or a DateTimeInterface. */ private function toDateTimeInterface(string $dateString): DateTimeInterface|null { - if ($dateString === null || $dateString === '') { + if ($dateString === '') { return null; } else { return new DateTimeImmutable((string) $dateString);