Add maxbot.logging.channel config (env MAXBOT_LOGGING_CHANNEL)

This commit is contained in:
Alex
2026-10-27 21:00:47 +03:00
parent b0d87b80b0
commit fbfd93a04c
4 changed files with 146 additions and 24 deletions
@@ -17,6 +17,7 @@ use BushlanovDev\MaxMessengerBot\LongPollingHandler;
use BushlanovDev\MaxMessengerBot\ModelFactory;
use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
use BushlanovDev\MaxMessengerBot\WebhookHandler;
use Illuminate\Log\LogManager;
use Illuminate\Support\Facades\Artisan;
use InvalidArgumentException;
use LogicException;
@@ -388,6 +389,66 @@ final class MaxBotServiceProviderTest extends TestCase
$this->assertSame($mockLogger, $actualLogger);
}
#[Test]
public function clientIsConfiguredWithChannelLoggerWhenLoggingChannelIsConfigured(): void
{
$this->app['config']->set('maxbot.logging.enabled', true);
$this->app['config']->set('maxbot.logging.channel', 'maxbot');
$this->app['config']->set('logging.channels.maxbot', [
'driver' => 'single',
'path' => storage_path('logs/maxbot.log'),
'level' => 'debug',
]);
/** @var Client $client */
$client = $this->app->make(ClientApiInterface::class);
$reflection = new ReflectionClass($client);
$loggerProp = $reflection->getProperty('logger');
$actualLogger = $loggerProp->getValue($client);
$expectedLogger = $this->app->make(LogManager::class)->channel('maxbot');
$this->assertSame($expectedLogger, $actualLogger);
}
#[Test]
public function webhookHandlerIsConfiguredWithChannelLoggerWhenLoggingChannelIsConfigured(): void
{
$this->app['config']->set('maxbot.logging.enabled', true);
$this->app['config']->set('maxbot.logging.channel', 'maxbot');
$this->app['config']->set('logging.channels.maxbot', [
'driver' => 'single',
'path' => storage_path('logs/maxbot.log'),
'level' => 'debug',
]);
/** @var WebhookHandler $handler */
$handler = $this->app->make(WebhookHandler::class);
$reflection = new ReflectionClass($handler);
$loggerProp = $reflection->getProperty('logger');
$actualLogger = $loggerProp->getValue($handler);
$expectedLogger = $this->app->make(LogManager::class)->channel('maxbot');
$this->assertSame($expectedLogger, $actualLogger);
}
#[Test]
public function clientIsConfiguredWithNullLoggerWhenLoggingIsDisabledEvenWithChannel(): void
{
$this->app['config']->set('maxbot.logging.enabled', false);
$this->app['config']->set('maxbot.logging.channel', 'maxbot');
/** @var Client $client */
$client = $this->app->make(ClientApiInterface::class);
$reflection = new ReflectionClass($client);
$loggerProp = $reflection->getProperty('logger');
$actualLogger = $loggerProp->getValue($client);
$this->assertInstanceOf(NullLogger::class, $actualLogger);
}
/**
* @return array<string, array{0: string}>
*/