1
0
mirror of synced 2024-11-21 21:06:07 +03:00

Исправлена очистка версии api

This commit is contained in:
Кривич Сергей 2022-10-21 13:52:52 +03:00
parent 1c68383869
commit 66690ac5dd
2 changed files with 38 additions and 1 deletions

View File

@ -28,7 +28,7 @@ class Utils
*/ */
public static function removeVersionFromUri(string $uri): string public static function removeVersionFromUri(string $uri): string
{ {
return (string) preg_replace('/\/v\d{1,3}\/?/', '', $uri); return (string) preg_replace('#api/v\d{1,3}/?#', 'api', $uri);
} }
/** /**

View File

@ -0,0 +1,37 @@
<?php
namespace RetailCrm\Tests\Component;
use PHPUnit\Framework\TestCase;
use RetailCrm\Api\Component\Utils;
class UtilsTest extends TestCase
{
/**
* @dataProvider removeVersionProvider
*/
public function testRemoveVersionFromUri(string $uri, string $expectedResult): void
{
$actualResult = Utils::removeVersionFromUri($uri);
self::assertEquals($expectedResult, $actualResult);
}
public function removeVersionProvider(): array
{
return [
[
'https://v5gv5hv5fv5jv5v5fgv59hbfg9.retailcrm.io/api/v5',
'https://v5gv5hv5fv5jv5v5fgv59hbfg9.retailcrm.io/api',
],
[
'https://v5gv5hv5fv5jv5v5fgv59hbfg9.retailcrm.io/api/v5/',
'https://v5gv5hv5fv5jv5v5fgv59hbfg9.retailcrm.io/api',
],
[
'https://v5gv5hv5fv5jv5v5fgv59hbfg9.retailcrm.io',
'https://v5gv5hv5fv5jv5v5fgv59hbfg9.retailcrm.io',
],
];
}
}