Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 33382c2

Browse filesBrowse files
bug #47528 [Form] fix UUID tranformer (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [Form] fix UUID tranformer | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 4760265 [Form] fix UUID tranformer
2 parents 6e8fc95 + 4760265 commit 33382c2
Copy full SHA for 33382c2

File tree

Expand file treeCollapse file tree

2 files changed

+12
-26
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-26
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/UuidToStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/UuidToStringTransformer.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ public function reverseTransform($value)
6464
throw new TransformationFailedException('Expected a string.');
6565
}
6666

67+
if (!Uuid::isValid($value)) {
68+
throw new TransformationFailedException(sprintf('The value "%s" is not a valid UUID.', $value));
69+
}
70+
6771
try {
68-
$uuid = new Uuid($value);
72+
return Uuid::fromString($value);
6973
} catch (\InvalidArgumentException $e) {
7074
throw new TransformationFailedException(sprintf('The value "%s" is not a valid UUID.', $value), $e->getCode(), $e);
7175
}
72-
73-
return $uuid;
7476
}
7577
}

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/UuidToStringTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/UuidToStringTransformerTest.php
+7-23Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.