Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
/ hyperf-tracer Public archive
forked from hyperf/tracer

Commit

Permalink
[CORE-909] Evita que uma barra no final seja adicionada depois da más…
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante authored Dec 7, 2022
1 parent ce1c6a2 commit 76d8c1a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Aspect/HttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
return $result;
}

protected function clearUri(string $uri): string
public function clearUri(string $uri): string
{
return preg_replace(
'/\/[0-9]+\/?/',
'/<NUMBER>/',
['#/\d+/#', '#/\d+$#'],
['/<NUMBER>/', '/<NUMBER>'],
$uri
);
}
Expand Down
42 changes: 42 additions & 0 deletions tests/Aspect/HttpClientAspectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf + PicPay.
*
* @link https://github.com/PicPay/hyperf-tracer
* @document https://github.com/PicPay/hyperf-tracer/wiki
* @contact @PicPay
* @license https://github.com/PicPay/hyperf-tracer/blob/main/LICENSE
*/
namespace HyperfTest\Tracer\Aspect;

use Hyperf\Tracer\Aspect\HttpClientAspect;
use Hyperf\Tracer\SpanTagManager;
use Hyperf\Tracer\SwitchManager;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use OpenTracing\Tracer;
use PHPUnit\Framework\TestCase;

/**
* @internal
*/
final class HttpClientAspectTest extends TestCase
{
use MockeryPHPUnitIntegration;

public function testClearUri(): void
{
$aspect = new HttpClientAspect(
Mockery::spy(Tracer::class),
Mockery::spy(SwitchManager::class),
Mockery::spy(SpanTagManager::class),
);

self::assertSame('/v1/test', $aspect->clearUri('/v1/test'));
self::assertSame('/v2/test/<NUMBER>', $aspect->clearUri('/v2/test/123'));
self::assertSame('/v3/test/<NUMBER>/bar', $aspect->clearUri('/v3/test/123/bar'));
self::assertSame('/v4/test/<NUMBER>/bar/<NUMBER>/', $aspect->clearUri('/v4/test/123/bar/456/'));
}
}

0 comments on commit 76d8c1a

Please sign in to comment.