Skip to content

Commit 3e891f5

Browse files
committed
Created a new case
1 parent f69514a commit 3e891f5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/AppBundle/Form/DataTransformer/TagArrayToStringTransformer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public function reverseTransform($string)
5454
return [];
5555
}
5656

57-
$names = array_unique(array_map('trim', explode(',', $string)));
58-
57+
$names = array_filter(array_unique(array_map('trim', explode(',', $string))), function ($name) {
58+
return !empty($name);
59+
});
5960

6061
// Get the current tags and find the new ones that should be created.
6162
$tags = $this->manager->getRepository(Tag::class)->findBy([

tests/AppBundle/Form/DataTransformer/TagArrayToStringTransformerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public function testCreateTheRightAmountOfTags()
5858
$this->assertSame('Hello', $tags[0]->getName());
5959
}
6060

61+
/**
62+
* Too many commas.
63+
*/
64+
public function testCreateTheRightAmountOfTagsWithTooManyCommas()
65+
{
66+
$transformer = $this->getMockedTransformer();
67+
$this->assertCount(3, $transformer->reverseTransform('Hello, Demo,, How'));
68+
$this->assertCount(3, $transformer->reverseTransform('Hello, Demo, How,'));
69+
}
70+
6171
/**
6272
* Spaces at the end (and begining) of a world shouldn't matter.
6373
*/

0 commit comments

Comments
 (0)