Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jan 10, 2025
1 parent d178e43 commit 63ca475
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/GithubIssueHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 10 additions & 5 deletions tests/GithubIssueHandlerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Monolog\Handler\HandlerInterface;
use Monolog\Level;
use Monolog\Logger;
use Naoray\LaravelGithubMonolog\GithubIssueFormatter;
Expand All @@ -15,7 +16,7 @@
];

$factory = new GithubIssueHandlerFactory;
$handler = $factory($config);
$logger = $factory($config);

expect($logger)
->toBeInstanceOf(Logger::class)
Expand All @@ -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');
});

Expand All @@ -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)
Expand All @@ -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);
});

0 comments on commit 63ca475

Please sign in to comment.