1
0
mirror of synced 2024-11-29 00:36:06 +03:00

fix for incorrect version removal from URL

This commit is contained in:
Pavel 2022-10-28 09:56:00 +03:00 committed by GitHub
commit 040cb49d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

4
.gitignore vendored
View File

@ -28,3 +28,7 @@ models/checksum.json
.swp .swp
/nbproject /nbproject
.env .env
.docker
docker*
Makefile

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',
],
];
}
}