20
20
21
21
class TagFactoryTest extends SuluTestCase
22
22
{
23
+ /**
24
+ * @var TagFactoryInterface
25
+ */
26
+ private $ tagFactory ;
27
+
23
28
protected function setUp (): void
24
29
{
25
30
self ::bootKernel ();
26
31
self ::purgeDatabase ();
27
- }
28
-
29
- /**
30
- * @param string[] $existTagNames
31
- */
32
- protected function createTagFactory (array $ existTagNames = []): TagFactoryInterface
33
- {
34
- /** @var TagRepositoryInterface $tagRepository */
35
- $ tagRepository = self ::$ container ->get ('sulu.repository.tag ' );
36
-
37
- foreach ($ existTagNames as $ existTagName ) {
38
- $ existTag = $ tagRepository ->createNew ();
39
- $ existTag ->setName ($ existTagName );
40
- self ::getEntityManager ()->persist ($ existTag );
41
- }
42
-
43
- if (\count ($ existTagNames )) {
44
- self ::getEntityManager ()->flush ();
45
- self ::getEntityManager ()->clear ();
46
- }
47
32
48
- return self ::$ container ->get ('sulu_content.tag_factory ' );
33
+ $ this -> tagFactory = self ::$ container ->get ('sulu_content.tag_factory ' );
49
34
}
50
35
51
36
/**
@@ -56,19 +41,31 @@ protected function createTagFactory(array $existTagNames = []): TagFactoryInterf
56
41
*/
57
42
public function testCreate (array $ tagNames , array $ existTags ): void
58
43
{
59
- $ tagFactory = $ this ->createTagFactory ($ existTags );
44
+ $ this ->createTags ($ existTags );
45
+
46
+ $ tags = $ this ->tagFactory ->create ($ tagNames );
60
47
61
48
$ this ->assertSame (
62
49
$ tagNames ,
63
50
array_map (
64
51
function (TagInterface $ tag ) {
65
52
return $ tag ->getName ();
66
53
},
67
- $ tagFactory -> create ( $ tagNames )
54
+ $ tags
68
55
)
69
56
);
70
57
}
71
58
59
+ public function testCreateSameTagTwice (): void
60
+ {
61
+ $ tags1 = $ this ->tagFactory ->create (['Tag 1 ' ]);
62
+ $ tags2 = $ this ->tagFactory ->create (['Tag 1 ' ]);
63
+
64
+ $ this ->assertSame ($ tags1 , $ tags2 );
65
+
66
+ $ this ->getEntityManager ()->flush ();
67
+ }
68
+
72
69
/**
73
70
* @return \Generator<mixed[]>
74
71
*/
@@ -114,4 +111,24 @@ public function dataProvider(): \Generator
114
111
],
115
112
];
116
113
}
114
+
115
+ /**
116
+ * @param string[] $existTagNames
117
+ */
118
+ private function createTags (array $ existTagNames = []): void
119
+ {
120
+ /** @var TagRepositoryInterface $tagRepository */
121
+ $ tagRepository = self ::$ container ->get ('sulu.repository.tag ' );
122
+
123
+ foreach ($ existTagNames as $ existTagName ) {
124
+ $ existTag = $ tagRepository ->createNew ();
125
+ $ existTag ->setName ($ existTagName );
126
+ self ::getEntityManager ()->persist ($ existTag );
127
+ }
128
+
129
+ if (\count ($ existTagNames )) {
130
+ self ::getEntityManager ()->flush ();
131
+ self ::getEntityManager ()->clear ();
132
+ }
133
+ }
117
134
}
0 commit comments