@@ -162,17 +162,98 @@ public function testClearUriExternalIds(): void
162162 self ::assertSame ('/v9/test/<EXTERNAL-ID>/bar/<NUMBER> ' , Uri::sanitize ('/v9/test/RR2101818220123720H9KJTERfw1a/bar/12345 ' ));
163163 }
164164
165- public function testClearUriBillUuid (): void
165+ public function testClearUriPrefixedUuid (): void
166166 {
167+ // Gera prefixos completamente aleatórios
168+ $ generateRandomPrefix = function (): string {
169+ $ wordCount = rand (1 , 3 ); // 1 a 3 palavras no prefixo
170+ $ words = [];
171+
172+ for ($ i = 0 ; $ i < $ wordCount ; $ i ++) {
173+ $ wordLength = rand (3 , 8 ); // palavras de 3 a 8 caracteres
174+ $ word = '' ;
175+ for ($ j = 0 ; $ j < $ wordLength ; $ j ++) {
176+ $ word .= chr (rand (65 , 90 )); // A-Z (65-90 na tabela ASCII)
177+ }
178+ $ words [] = $ word ;
179+ }
180+
181+ return implode ('- ' , $ words );
182+ };
183+
184+ $ randomPrefix = $ generateRandomPrefix ();
185+
186+ // Gera UUIDs aleatórios (incluindo caracteres não-hexadecimais para testar a regex)
187+ $ uuidChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ' ;
188+ $ randomUuid = sprintf (
189+ '%s-%s-%s-%s-%s ' ,
190+ substr (str_shuffle ($ uuidChars ), 0 , 8 ),
191+ substr (str_shuffle ($ uuidChars ), 0 , 4 ),
192+ substr (str_shuffle ($ uuidChars ), 0 , 4 ),
193+ substr (str_shuffle ($ uuidChars ), 0 , 4 ),
194+ substr (str_shuffle ($ uuidChars ), 0 , 12 )
195+ );
196+
197+ $ prefixedUuid = "{$ randomPrefix }- {$ randomUuid }" ;
198+
199+ // Casos de teste estático para garantir consistência
167200 $ billUuid = 'BILL-123e4567-e89b-12d3-a456-426614174000 ' ;
201+ $ userUuid = 'USER-abc1234d-e56f-78g9-h012-345678901234 ' ;
202+ $ companyUuid = 'COMPANY-ADMIN-456e7890-f12a-34b5-c678-901234567890 ' ;
168203
204+ // Gera mais alguns prefixos aleatórios para testes variados
205+ $ randomPrefix2 = $ generateRandomPrefix ();
206+ $ randomUuid2 = sprintf (
207+ '%s-%s-%s-%s-%s ' ,
208+ substr (str_shuffle ($ uuidChars ), 0 , 8 ),
209+ substr (str_shuffle ($ uuidChars ), 0 , 4 ),
210+ substr (str_shuffle ($ uuidChars ), 0 , 4 ),
211+ substr (str_shuffle ($ uuidChars ), 0 , 4 ),
212+ substr (str_shuffle ($ uuidChars ), 0 , 12 )
213+ );
214+ $ prefixedUuid2 = "{$ randomPrefix2 }- {$ randomUuid2 }" ;
215+
216+ // Testes básicos
169217 self ::assertSame ('/v1/test ' , Uri::sanitize ('/v1/test ' ));
170- self ::assertSame ('/v2/test/<BILL-UUID> ' , Uri::sanitize ("/v2/test/ {$ billUuid }" ));
171- self ::assertSame ('/v3/test/<BILL-UUID>/bar ' , Uri::sanitize ("/v3/test/ {$ billUuid }/bar " ));
172- self ::assertSame ('/v4/test/<BILL-UUID>/bar/<BILL-UUID>/ ' , Uri::sanitize ("/v4/test/ {$ billUuid }/bar/ {$ billUuid }/ " ));
173- self ::assertSame ('/v5/test/<BILL-UUID>/<BILL-UUID> ' , Uri::sanitize ("/v5/test/ {$ billUuid }/ {$ billUuid }" ));
174- self ::assertSame ('/v6/test/<BILL-UUID>/<BILL-UUID>/ ' , Uri::sanitize ("/v6/test/ {$ billUuid }/ {$ billUuid }/ " ));
175- self ::assertSame ('/v7/test/<BILL-UUID>/<BILL-UUID>/<BILL-UUID> ' , Uri::sanitize ("/v7/test/ {$ billUuid }/ {$ billUuid }/ {$ billUuid }" ));
176- self ::assertSame ('/v8/test/<BILL-UUID>/<BILL-UUID>/<BILL-UUID>/ ' , Uri::sanitize ("/v8/test/ {$ billUuid }/ {$ billUuid }/ {$ billUuid }/ " ));
218+
219+ // Testes com prefixos randômicos
220+ self ::assertSame ('/v2/test/<PREFIXED-UUID> ' , Uri::sanitize ("/v2/test/ {$ prefixedUuid }" ));
221+ self ::assertSame ('/v3/test/<PREFIXED-UUID>/bar ' , Uri::sanitize ("/v3/test/ {$ prefixedUuid }/bar " ));
222+ self ::assertSame ('/v4/test/<PREFIXED-UUID>/bar/<PREFIXED-UUID>/ ' , Uri::sanitize ("/v4/test/ {$ prefixedUuid }/bar/ {$ prefixedUuid }/ " ));
223+
224+ // Testes com casos estáticos conhecidos
225+ self ::assertSame ('/v2/test/<PREFIXED-UUID> ' , Uri::sanitize ("/v2/test/ {$ billUuid }" ));
226+ self ::assertSame ('/v3/test/<PREFIXED-UUID>/bar ' , Uri::sanitize ("/v3/test/ {$ billUuid }/bar " ));
227+ self ::assertSame ('/v4/test/<PREFIXED-UUID>/bar/<PREFIXED-UUID>/ ' , Uri::sanitize ("/v4/test/ {$ billUuid }/bar/ {$ billUuid }/ " ));
228+
229+ // Testes com UUID não-hexadecimal
230+ self ::assertSame ('/v2/test/<PREFIXED-UUID> ' , Uri::sanitize ("/v2/test/ {$ userUuid }" ));
231+ self ::assertSame ('/v3/test/<PREFIXED-UUID>/bar ' , Uri::sanitize ("/v3/test/ {$ userUuid }/bar " ));
232+
233+ // Testes com prefixo composto
234+ self ::assertSame ('/v2/test/<PREFIXED-UUID> ' , Uri::sanitize ("/v2/test/ {$ companyUuid }" ));
235+ self ::assertSame ('/v3/test/<PREFIXED-UUID>/bar ' , Uri::sanitize ("/v3/test/ {$ companyUuid }/bar " ));
236+
237+ // Testes com múltiplos UUIDs (randômicos + estáticos)
238+ self ::assertSame ('/v5/test/<PREFIXED-UUID>/<PREFIXED-UUID> ' , Uri::sanitize ("/v5/test/ {$ prefixedUuid }/ {$ billUuid }" ));
239+ self ::assertSame ('/v6/test/<PREFIXED-UUID>/<PREFIXED-UUID>/ ' , Uri::sanitize ("/v6/test/ {$ billUuid }/ {$ prefixedUuid }/ " ));
240+ self ::assertSame ('/v7/test/<PREFIXED-UUID>/<PREFIXED-UUID>/<PREFIXED-UUID> ' , Uri::sanitize ("/v7/test/ {$ prefixedUuid }/ {$ billUuid }/ {$ userUuid }" ));
241+ self ::assertSame ('/v8/test/<PREFIXED-UUID>/<PREFIXED-UUID>/<PREFIXED-UUID>/ ' , Uri::sanitize ("/v8/test/ {$ billUuid }/ {$ userUuid }/ {$ prefixedUuid }/ " ));
242+
243+ // Testes com dois prefixos aleatórios diferentes
244+ self ::assertSame ('/v9/test/<PREFIXED-UUID>/<PREFIXED-UUID> ' , Uri::sanitize ("/v9/test/ {$ prefixedUuid }/ {$ prefixedUuid2 }" ));
245+ self ::assertSame ('/v10/test/<PREFIXED-UUID>/<PREFIXED-UUID>/<PREFIXED-UUID>/ ' , Uri::sanitize ("/v10/test/ {$ prefixedUuid }/ {$ prefixedUuid2 }/ {$ companyUuid }/ " ));
246+
247+ // Casos edge: diferentes contextos de API
248+ self ::assertSame ('/users/<PREFIXED-UUID>/profile ' , Uri::sanitize ("/users/ {$ prefixedUuid }/profile " ));
249+ self ::assertSame ('/api/v1/bills/<PREFIXED-UUID>/details ' , Uri::sanitize ("/api/v1/bills/ {$ billUuid }/details " ));
250+ self ::assertSame ('/companies/<PREFIXED-UUID>/admin/<PREFIXED-UUID>/settings ' , Uri::sanitize ("/companies/ {$ prefixedUuid2 }/admin/ {$ prefixedUuid }/settings " ));
251+
252+ // Teste sem barra final
253+ self ::assertSame ('/test/<PREFIXED-UUID> ' , Uri::sanitize ("/test/ {$ prefixedUuid }" ));
254+
255+ // Testes com prefixos de diferentes tamanhos
256+ self ::assertSame ('/short/<PREFIXED-UUID> ' , Uri::sanitize ("/short/ {$ prefixedUuid }" ));
257+ self ::assertSame ('/long/<PREFIXED-UUID>/path ' , Uri::sanitize ("/long/ {$ prefixedUuid2 }/path " ));
177258 }
178259}
0 commit comments