mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-23 13:00:35 +00:00
Laravel support tests
This commit is contained in:
@@ -113,6 +113,7 @@ class MaxBotManager
|
||||
* It will run indefinitely until stopped.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function startLongPolling(int $timeout = 90, ?int $marker = null): void
|
||||
{
|
||||
@@ -129,6 +130,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function addHandler(UpdateType $type, callable|string $handler): void
|
||||
{
|
||||
@@ -142,6 +144,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onCommand(string $command, callable|string $handler): void
|
||||
{
|
||||
@@ -154,6 +157,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onMessageCreated(callable|string $handler): void
|
||||
{
|
||||
@@ -166,6 +170,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onMessageCallback(callable|string $handler): void
|
||||
{
|
||||
@@ -178,6 +183,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onMessageEdited(callable|string $handler): void
|
||||
{
|
||||
@@ -190,6 +196,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onMessageRemoved(callable|string $handler): void
|
||||
{
|
||||
@@ -202,6 +209,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onBotAdded(callable|string $handler): void
|
||||
{
|
||||
@@ -214,6 +222,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onBotRemoved(callable|string $handler): void
|
||||
{
|
||||
@@ -226,6 +235,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onUserAdded(callable|string $handler): void
|
||||
{
|
||||
@@ -238,6 +248,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onUserRemoved(callable|string $handler): void
|
||||
{
|
||||
@@ -250,6 +261,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onBotStarted(callable|string $handler): void
|
||||
{
|
||||
@@ -262,6 +274,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onChatTitleChanged(callable|string $handler): void
|
||||
{
|
||||
@@ -274,6 +287,7 @@ class MaxBotManager
|
||||
* @param callable|string $handler Can be a closure, callable, or Laravel container binding.
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function onMessageChatCreated(callable|string $handler): void
|
||||
{
|
||||
@@ -282,6 +296,7 @@ class MaxBotManager
|
||||
|
||||
/**
|
||||
* Get the API instance.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getApi(): Api
|
||||
{
|
||||
@@ -290,6 +305,7 @@ class MaxBotManager
|
||||
|
||||
/**
|
||||
* Get the update dispatcher.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getDispatcher(): UpdateDispatcher
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace BushlanovDev\MaxMessengerBot\Laravel;
|
||||
use BushlanovDev\MaxMessengerBot\Api;
|
||||
use BushlanovDev\MaxMessengerBot\Client;
|
||||
use BushlanovDev\MaxMessengerBot\ClientApiInterface;
|
||||
use BushlanovDev\MaxMessengerBot\Laravel\Commands\PollingStartCommand;
|
||||
use BushlanovDev\MaxMessengerBot\ModelFactory;
|
||||
use BushlanovDev\MaxMessengerBot\UpdateDispatcher;
|
||||
use BushlanovDev\MaxMessengerBot\WebhookHandler;
|
||||
@@ -19,6 +20,7 @@ use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Contracts\Config\Repository as Config;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* Laravel Service Provider for Max Bot API Client.
|
||||
@@ -37,6 +39,7 @@ class MaxBotServiceProvider extends ServiceProvider
|
||||
);
|
||||
|
||||
$this->app->singleton(ClientApiInterface::class, function (Application $app) {
|
||||
/** @var Config $config */
|
||||
$config = $app->make(Config::class);
|
||||
$accessToken = $config->get('maxbot.access_token');
|
||||
|
||||
@@ -52,16 +55,14 @@ class MaxBotServiceProvider extends ServiceProvider
|
||||
);
|
||||
}
|
||||
|
||||
$timeout = $config->get('maxbot.timeout', 10);
|
||||
$connectTimeout = $config->get('maxbot.connect_timeout', 5);
|
||||
$readTimeout = $config->get('maxbot.read_timeout', 10);
|
||||
$baseUrl = $config->get('maxbot.base_url', 'https://botapi.max.ru');
|
||||
$apiVersion = $config->get('maxbot.api_version', Api::API_VERSION);
|
||||
$logger = $config->get('maxbot.logging.enabled', false)
|
||||
? $app->make(LoggerInterface::class)
|
||||
: new NullLogger();
|
||||
|
||||
$guzzle = new \GuzzleHttp\Client([
|
||||
'timeout' => $timeout,
|
||||
'connect_timeout' => $connectTimeout,
|
||||
'read_timeout' => $readTimeout,
|
||||
'timeout' => (int)$config->get('maxbot.timeout', 10),
|
||||
'connect_timeout' => (int)$config->get('maxbot.connect_timeout', 5),
|
||||
'read_timeout' => (int)$config->get('maxbot.read_timeout', 10),
|
||||
'headers' => [
|
||||
'User-Agent' => 'max-bot-api-client-php/' . Api::LIBRARY_VERSION
|
||||
. ' Laravel/' . $app->version() . ' PHP/' . PHP_VERSION
|
||||
@@ -75,9 +76,9 @@ class MaxBotServiceProvider extends ServiceProvider
|
||||
$guzzle,
|
||||
$httpFactory,
|
||||
$httpFactory,
|
||||
$baseUrl,
|
||||
$apiVersion,
|
||||
$app->make(LoggerInterface::class),
|
||||
$config->get('maxbot.base_url', 'https://botapi.max.ru'),
|
||||
$config->get('maxbot.api_version', Api::API_VERSION),
|
||||
$logger,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -90,6 +91,7 @@ class MaxBotServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
$this->app->singleton(Api::class, function (Application $app) {
|
||||
/** @var Config $config */
|
||||
$config = $app->make(Config::class);
|
||||
$accessToken = $config->get('maxbot.access_token');
|
||||
|
||||
@@ -109,6 +111,7 @@ class MaxBotServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
$this->app->bind(WebhookHandler::class, function (Application $app) {
|
||||
/** @var Config $config */
|
||||
$config = $app->make(Config::class);
|
||||
$secret = $config->get('maxbot.webhook_secret');
|
||||
|
||||
@@ -159,6 +162,7 @@ class MaxBotServiceProvider extends ServiceProvider
|
||||
WebhookSubscribeCommand::class,
|
||||
WebhookUnsubscribeCommand::class,
|
||||
WebhookListCommand::class,
|
||||
PollingStartCommand::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -65,3 +66,4 @@ return [
|
||||
'level' => env('MAXBOT_LOGGING_LEVEL', 'debug'),
|
||||
],
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
Reference in New Issue
Block a user