diff --git a/src/GithubIssueHandlerFactory.php b/src/GithubIssueHandlerFactory.php index fe649da..2472cc3 100644 --- a/src/GithubIssueHandlerFactory.php +++ b/src/GithubIssueHandlerFactory.php @@ -11,8 +11,12 @@ class GithubIssueHandlerFactory { public function __invoke(array $config): Logger { - if (Arr::has($config, ['repo', 'token'])) { - throw new InvalidArgumentException('GitHub repository and token are required'); + if (! Arr::has($config, 'repo')) { + throw new InvalidArgumentException('GitHub repository is required'); + } + + if (! Arr::has($config, 'token')) { + throw new InvalidArgumentException('GitHub token is required'); } $handler = new GithubIssueLoggerHandler( diff --git a/tests/GithubIssueHandlerFactoryTest.php b/tests/GithubIssueHandlerFactoryTest.php index 74eb03e..419ec5c 100644 --- a/tests/GithubIssueHandlerFactoryTest.php +++ b/tests/GithubIssueHandlerFactoryTest.php @@ -1,5 +1,6 @@ toBeInstanceOf(Logger::class) @@ -27,10 +28,10 @@ test('it throws exception for missing required config', function () { $factory = new GithubIssueHandlerFactory; - expect(fn () => $factory([])) + expect(fn() => $factory([])) ->toThrow(InvalidArgumentException::class, 'GitHub repository is required'); - expect(fn () => $factory(['repo' => 'test/repo'])) + expect(fn() => $factory(['repo' => 'test/repo'])) ->toThrow(InvalidArgumentException::class, 'GitHub token is required'); }); @@ -41,7 +42,9 @@ ]; $factory = new GithubIssueHandlerFactory; - $handler = $factory($config); + $logger = $factory($config); + /** @var GithubIssueLoggerHandler $handler */ + $handler = $logger->getHandlers()[0]; expect($handler) ->toBeInstanceOf(GithubIssueLoggerHandler::class) @@ -58,7 +61,9 @@ ]; $factory = new GithubIssueHandlerFactory; - $handler = $factory($config); + $logger = $factory($config); + /** @var GithubIssueLoggerHandler $handler */ + $handler = $logger->getHandlers()[0]; expect($handler->getLevel())->toBe(Level::Debug); });