diff --git a/README.md b/README.md index 1352e85..ce73e70 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ $client = new \BushlanovDev\MaxMessengerBot\Client( httpClient: $guzzle, requestFactory: $httpFactory, streamFactory: $httpFactory, - baseUrl: 'https://platform-api2.max.ru', + baseUrl: BushlanovDev\MaxMessengerBot\Api::API_BASE_URL, ); $api = new BushlanovDev\MaxMessengerBot\Api( diff --git a/docs/README.md b/docs/README.md index a0f5e7b..4dae330 100644 --- a/docs/README.md +++ b/docs/README.md @@ -99,7 +99,7 @@ $client = new \BushlanovDev\MaxMessengerBot\Client( httpClient: $guzzle, requestFactory: $httpFactory, streamFactory: $httpFactory, - baseUrl: 'https://platform-api2.max.ru', + baseUrl: BushlanovDev\MaxMessengerBot\Api::API_BASE_URL, ); $api = new BushlanovDev\MaxMessengerBot\Api( diff --git a/src/Api.php b/src/Api.php index 753eded..59ffaef 100644 --- a/src/Api.php +++ b/src/Api.php @@ -48,12 +48,12 @@ use RuntimeException; */ class Api { - public const string LIBRARY_VERSION = '1.6.5'; + public const string API_BASE_URL = 'https://platform-api2.max.ru'; + + public const string LIBRARY_VERSION = '1.6.6'; public const string API_VERSION = '1.2.5'; - private const string API_BASE_URL = 'https://platform-api2.max.ru'; - private const string METHOD_GET = 'GET'; private const string METHOD_POST = 'POST'; private const string METHOD_DELETE = 'DELETE'; diff --git a/src/Enums/ChatAdminPermission.php b/src/Enums/ChatAdminPermission.php index 4ff1a88..3d5a703 100644 --- a/src/Enums/ChatAdminPermission.php +++ b/src/Enums/ChatAdminPermission.php @@ -17,8 +17,8 @@ enum ChatAdminPermission: string case Write = 'write'; case CanCall = 'can_call'; case EditLink = 'edit_link'; - case PostEditDeleteMessage = 'post_edit_delete_message'; - case EditMessage = 'edit_message'; + case PostEditDeleteMessage = 'post_edit_delete_message'; // @deprecated use write + case EditMessage = 'edit_message'; // @deprecated use edit case DeleteMessage = 'delete_message'; case Delete = 'delete'; case Edit = 'edit'; diff --git a/src/Laravel/MaxBotServiceProvider.php b/src/Laravel/MaxBotServiceProvider.php index de647ab..0bf4107 100644 --- a/src/Laravel/MaxBotServiceProvider.php +++ b/src/Laravel/MaxBotServiceProvider.php @@ -76,7 +76,7 @@ class MaxBotServiceProvider extends ServiceProvider $guzzle, $httpFactory, $httpFactory, - $config->get('maxbot.base_url', 'https://platform-api2.max.ru'), + empty($config->get('maxbot.base_url')) ? Api::API_BASE_URL : $config->get('maxbot.base_url'), $config->get('maxbot.api_version'), $logger, ); diff --git a/src/Laravel/config/maxbot.php b/src/Laravel/config/maxbot.php index 1f14e38..61705d3 100644 --- a/src/Laravel/config/maxbot.php +++ b/src/Laravel/config/maxbot.php @@ -36,7 +36,7 @@ return [ | Configuration for the Max Bot API connection. | */ - 'base_url' => env('MAXBOT_BASE_URL', 'https://botapi.max.ru'), + 'base_url' => env('MAXBOT_BASE_URL', \BushlanovDev\MaxMessengerBot\Api::API_BASE_URL), 'api_version' => env('MAXBOT_API_VERSION'), /* diff --git a/tests/ClientTest.php b/tests/ClientTest.php index fde44bb..0fa14c3 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -37,8 +37,8 @@ use Psr\Log\LoggerInterface; final class ClientTest extends TestCase { private const string FAKE_TOKEN = '12345:abcdef'; - private const string API_VERSION = '0.0.6'; - private const string API_BASE_URL = 'https://platform-api.max.ru'; + private const string API_VERSION = '1.2.5'; + private const string API_BASE_URL = 'https://platform-api2.max.ru'; private MockObject&ClientInterface $httpClientMock; private MockObject&RequestFactoryInterface $requestFactoryMock; diff --git a/tests/Laravel/MaxBotServiceProviderTest.php b/tests/Laravel/MaxBotServiceProviderTest.php index 5c0562c..3cebf36 100644 --- a/tests/Laravel/MaxBotServiceProviderTest.php +++ b/tests/Laravel/MaxBotServiceProviderTest.php @@ -182,6 +182,30 @@ final class MaxBotServiceProviderTest extends TestCase $this->assertSame('test-version', $apiVersionProp->getValue($client)); } + /** + * @return array + */ + public static function falsyBaseUrlProvider(): array + { + return [ + 'null (MAXBOT_BASE_URL unset)' => [null], + 'empty string' => [''], + ]; + } + + #[Test] + #[DataProvider('falsyBaseUrlProvider')] + public function clientFallsBackToApiBaseUrlConstantWhenBaseUrlIsFalsy(mixed $falsyBaseUrl): void + { + $this->app['config']->set('maxbot.base_url', $falsyBaseUrl); + + /** @var Client $client */ + $client = $this->app->make(ClientApiInterface::class); + + $baseUrlProp = (new ReflectionClass($client))->getProperty('baseUrl'); + $this->assertSame(Api::API_BASE_URL, $baseUrlProp->getValue($client)); + } + #[Test] public function clientIsConfiguredWithApplicationLoggerWhenLoggingIsEnabled(): void {