diff --git a/Classes/Domain/Service/ZoomApiAccessTokenFactory.php b/Classes/Domain/Service/ZoomApiAccessTokenFactory.php index 28aaaee..1a68c4c 100644 --- a/Classes/Domain/Service/ZoomApiAccessTokenFactory.php +++ b/Classes/Domain/Service/ZoomApiAccessTokenFactory.php @@ -69,10 +69,9 @@ public function createFromConfiguration(): ZoomApiAccessToken throw new ZoomApiException('Please ensure your Zoom app has the following scopes: user:read:admin, recording:read:admin, meeting:read:admin', 1695040540417); } - $zoomApiAccessToken = new ZoomApiAccessToken( + return new ZoomApiAccessToken( $responseBodyAsArray['access_token'], explode(',', $responseBodyAsArray['scope'])); - return $zoomApiAccessToken; } /** diff --git a/Classes/Domain/Service/ZoomApiService.php b/Classes/Domain/Service/ZoomApiService.php index e9254f5..8accb59 100644 --- a/Classes/Domain/Service/ZoomApiService.php +++ b/Classes/Domain/Service/ZoomApiService.php @@ -107,21 +107,7 @@ public function getUpcomingMeetings(bool $skipCache = false): array */ public function getRecordings(DateTime|string $from, DateTime|string $to, bool $skipCache = false): array { - if (is_string($from)) { - $from = new DateTimeImmutable($from); - } else { - $from = DateTimeImmutable::createFromMutable($from); - } - - if (is_string($to)) { - $to = new DateTimeImmutable($to); - } else { - $to = DateTimeImmutable::createFromMutable($to); - } - - if ($from > $to) { - throw new InvalidArgumentException('The from date must be after the to date'); - } + list($from, $to) = $this->convertFromAndToAsDateTimeImmutable($from, $to); $cacheEntryIdentifier = sprintf('recordings_%s_%s', $from->format('Y-m-d'), $to->format('Y-m-d')); $recordings = $this->getCacheEntry($cacheEntryIdentifier); @@ -257,4 +243,31 @@ private function getCacheEntry(string $entryIdentifier): array|bool { return $this->requestsCache->get($entryIdentifier); } + + /** + * @param DateTime|string $from + * @param DateTime|string $to + * + * @return DateTimeImmutable[] + * @throws Exception + */ + protected function convertFromAndToAsDateTimeImmutable(DateTime|string $from, DateTime|string $to): array + { + if (is_string($from)) { + $from = new DateTimeImmutable($from); + } else { + $from = DateTimeImmutable::createFromMutable($from); + } + + if (is_string($to)) { + $to = new DateTimeImmutable($to); + } else { + $to = DateTimeImmutable::createFromMutable($to); + } + + if ($from > $to) { + throw new InvalidArgumentException('The from date must be after the to date'); + } + return array($from, $to); + } } diff --git a/Tests/Unit/ZoomApiAccessTokenFactoryTest.php b/Tests/Unit/ZoomApiAccessTokenFactoryTest.php index 734f6e2..84eb93f 100644 --- a/Tests/Unit/ZoomApiAccessTokenFactoryTest.php +++ b/Tests/Unit/ZoomApiAccessTokenFactoryTest.php @@ -4,6 +4,7 @@ use CodeQ\ZoomApi\Domain\Model\ZoomApiAccessToken; use CodeQ\ZoomApi\Domain\Service\ZoomApiAccessTokenFactory; +use CodeQ\ZoomApi\ZoomApiException; use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; @@ -22,10 +23,30 @@ public function createFromConfigurationWillReturnAccessToken(): void ]) ); $factoryMock = $this->getFactory($handlerStack); + + $accessToken = $factoryMock->createFromConfiguration(); $this->assertInstanceOf(ZoomApiAccessToken::class, $accessToken); } + /** @test */ + public function invalidConfigurationWillThrowException(): void + { + $this->expectException(ZoomApiException::class); + $this->expectExceptionMessage('Please set a Zoom Account ID, Client ID and Secret for CodeQ.ZoomApi to be able to authenticate.'); + + + $factoryMock = $this->getFactory(); + $this->inject( + $factoryMock, + 'settings', + ['auth' => ['accountId' => '', 'clientId' => null, 'clientSecret' => false]] + ); + + + $factoryMock->initializeObject(); + } + private function getFactory(HandlerStack $handlerStack = null): ZoomApiAccessTokenFactory|MockObject { $factory = $this->getAccessibleMock(ZoomApiAccessTokenFactory::class, ['buildClient'], [], '', false); diff --git a/Tests/Unit/ZoomApiServiceTest.php b/Tests/Unit/ZoomApiServiceTest.php index 23a6cdc..769b77c 100644 --- a/Tests/Unit/ZoomApiServiceTest.php +++ b/Tests/Unit/ZoomApiServiceTest.php @@ -35,7 +35,7 @@ protected function setUp(): void } /** @test */ - public function it_can_fetch_data() + public function canFetchData(): void { $handlerStack = HandlerStack::create( new MockHandler([