Skip to content

Commit 176a358

Browse files
Merge branch '6.0' into 6.1
* 6.0: [Form] fix UUID tranformer [Uid] Ensure ULIDs are monotonic even when the time goes backward [HttpClient] fix merge [HttpClient] fix merge
2 parents aa92f52 + 3cfc51b commit 176a358

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

Extension/Core/DataTransformer/UuidToStringTransformer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ public function reverseTransform(mixed $value): ?Uuid
6060
throw new TransformationFailedException('Expected a string.');
6161
}
6262

63+
if (!Uuid::isValid($value)) {
64+
throw new TransformationFailedException(sprintf('The value "%s" is not a valid UUID.', $value));
65+
}
66+
6367
try {
64-
$uuid = new Uuid($value);
68+
return Uuid::fromString($value);
6569
} catch (\InvalidArgumentException $e) {
6670
throw new TransformationFailedException(sprintf('The value "%s" is not a valid UUID.', $value), $e->getCode(), $e);
6771
}
68-
69-
return $uuid;
7072
}
7173
}

Tests/Extension/Core/DataTransformer/UuidToStringTransformerTest.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,15 @@
1515
use Symfony\Component\Form\Exception\TransformationFailedException;
1616
use Symfony\Component\Form\Extension\Core\DataTransformer\UuidToStringTransformer;
1717
use Symfony\Component\Uid\Uuid;
18+
use Symfony\Component\Uid\UuidV1;
1819

1920
class UuidToStringTransformerTest extends TestCase
2021
{
21-
public function provideValidUuid()
22-
{
23-
return [
24-
['123e4567-e89b-12d3-a456-426655440000', new Uuid('123e4567-e89b-12d3-a456-426655440000')],
25-
];
26-
}
27-
28-
/**
29-
* @dataProvider provideValidUuid
30-
*/
31-
public function testTransform($output, $input)
22+
public function testTransform()
3223
{
3324
$transformer = new UuidToStringTransformer();
3425

35-
$input = new Uuid($input);
36-
37-
$this->assertEquals($output, $transformer->transform($input));
26+
$this->assertEquals('123e4567-e89b-12d3-a456-426655440000', $transformer->transform(new UuidV1('123e4567-e89b-12d3-a456-426655440000')));
3827
}
3928

4029
public function testTransformEmpty()
@@ -53,16 +42,11 @@ public function testTransformExpectsUuid()
5342
$transformer->transform('1234');
5443
}
5544

56-
/**
57-
* @dataProvider provideValidUuid
58-
*/
59-
public function testReverseTransform($input, $output)
45+
public function testReverseTransform()
6046
{
61-
$reverseTransformer = new UuidToStringTransformer();
62-
63-
$output = new Uuid($output);
47+
$transformer = new UuidToStringTransformer();
6448

65-
$this->assertEquals($output, $reverseTransformer->reverseTransform($input));
49+
$this->assertEquals(new UuidV1('123e4567-e89b-12d3-a456-426655440000'), $transformer->reverseTransform('123e4567-e89b-12d3-a456-426655440000'));
6650
}
6751

6852
public function testReverseTransformEmpty()
@@ -78,7 +62,7 @@ public function testReverseTransformExpectsString()
7862

7963
$this->expectException(TransformationFailedException::class);
8064

81-
$reverseTransformer->reverseTransform(1234);
65+
$reverseTransformer->reverseTransform(Uuid::fromString('123e4567-e89b-12d3-a456-426655440000')->toBase32());
8266
}
8367

8468
public function testReverseTransformExpectsValidUuidString()

0 commit comments

Comments
 (0)