7
7
use Symfony \Bundle \FrameworkBundle \FrameworkBundle ;
8
8
use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
9
9
use Symfony \Bundle \MakerBundle \Command \MakerCommand ;
10
+ use Symfony \Bundle \MakerBundle \EventRegistry ;
11
+ use Symfony \Bundle \MakerBundle \FileManager ;
12
+ use Symfony \Bundle \MakerBundle \Generator ;
10
13
use Symfony \Bundle \MakerBundle \Maker \MakeAuthenticator ;
11
14
use Symfony \Bundle \MakerBundle \Maker \MakeCommand ;
12
15
use Symfony \Bundle \MakerBundle \Maker \MakeController ;
19
22
use Symfony \Bundle \MakerBundle \Maker \MakeUnitTest ;
20
23
use Symfony \Bundle \MakerBundle \Maker \MakeValidator ;
21
24
use Symfony \Bundle \MakerBundle \Maker \MakeVoter ;
22
- use Symfony \Bundle \MakerBundle \EventRegistry ;
23
- use Symfony \Bundle \MakerBundle \FileManager ;
24
- use Symfony \Bundle \MakerBundle \Generator ;
25
25
use Symfony \Bundle \MakerBundle \MakerBundle ;
26
26
use Symfony \Bundle \MakerBundle \MakerInterface ;
27
27
use Symfony \Component \Config \Loader \LoaderInterface ;
38
38
39
39
class FunctionalTest extends TestCase
40
40
{
41
+ private $ fs ;
41
42
private $ targetDir ;
42
43
43
44
public function setUp ()
44
45
{
45
- $ tmpDir = sys_get_temp_dir ().'/sf ' .random_int (111111 , 999999 );
46
- @mkdir ($ tmpDir , 0777 , true );
47
-
48
- $ this ->targetDir = $ tmpDir ;
46
+ $ this ->targetDir = sys_get_temp_dir ().'/ ' .uniqid ('sf_maker_ ' , true );
47
+ $ this ->fs = new Filesystem ();
48
+ $ this ->fs ->mkdir ($ this ->targetDir );
49
49
}
50
50
51
51
public function tearDown ()
52
52
{
53
- $ fs = new Filesystem ();
54
- $ fs ->remove ($ this ->targetDir );
53
+ $ this ->fs ->remove ($ this ->targetDir );
55
54
}
56
55
57
56
/**
@@ -60,7 +59,6 @@ public function tearDown()
60
59
public function testCommands (MakerInterface $ maker , array $ inputs )
61
60
{
62
61
$ command = new MakerCommand ($ maker , $ this ->createGenerator ());
63
-
64
62
$ command ->setCheckDependencies (false );
65
63
66
64
$ tester = new CommandTester ($ command );
@@ -81,9 +79,7 @@ public function testCommands(MakerInterface $maker, array $inputs)
81
79
82
80
public function getCommandTests ()
83
81
{
84
- $ makers = array ();
85
-
86
- $ makers ['command ' ] = array (
82
+ yield 'command ' => array (
87
83
new MakeCommand (),
88
84
array (
89
85
// command name
@@ -95,31 +91,31 @@ public function getCommandTests()
95
91
$ router ->expects ($ this ->once ())
96
92
->method ('getRouteCollection ' )
97
93
->willReturn (new RouteCollection ());
98
- $ makers [ 'controller ' ] = array (
94
+ yield 'controller ' => array (
99
95
new MakeController ($ router ),
100
96
array (
101
97
// controller class name
102
98
'FooBar ' ,
103
99
),
104
100
);
105
101
106
- $ makers [ 'entity ' ] = array (
102
+ yield 'entity ' => array (
107
103
new MakeEntity (),
108
104
array (
109
105
// entity class name
110
106
'FooBar ' ,
111
107
),
112
108
);
113
109
114
- $ makers [ 'form ' ] = array (
110
+ yield 'form ' => array (
115
111
new MakeForm (),
116
112
array (
117
113
// form name
118
114
'FooBar ' ,
119
115
),
120
116
);
121
117
122
- $ makers [ 'functional ' ] = array (
118
+ yield 'functional ' => array (
123
119
new MakeFunctionalTest (),
124
120
array (
125
121
// functional test class
@@ -135,7 +131,7 @@ public function getCommandTests()
135
131
->method ('getEventClassName ' )
136
132
->with ('kernel.request ' )
137
133
->willReturn (GetResponseEvent::class);
138
- $ makers [ 'subscriber ' ] = array (
134
+ yield 'subscriber ' => array (
139
135
new MakeSubscriber ($ eventRegistry ),
140
136
array (
141
137
// subscriber name
@@ -152,7 +148,7 @@ public function getCommandTests()
152
148
$ eventRegistry2 ->expects ($ this ->once ())
153
149
->method ('getEventClassName ' )
154
150
->willReturn (null );
155
- $ makers [ 'subscriber_unknown_event_class ' ] = array (
151
+ yield 'subscriber_unknown_event_class ' => array (
156
152
new MakeSubscriber ($ eventRegistry2 ),
157
153
array (
158
154
// subscriber name
@@ -162,7 +158,7 @@ public function getCommandTests()
162
158
),
163
159
);
164
160
165
- $ makers [ 'serializer_encoder ' ] = array (
161
+ yield 'serializer_encoder ' => array (
166
162
new MakeSerializerEncoder (),
167
163
array (
168
164
// encoder class name
@@ -172,47 +168,45 @@ public function getCommandTests()
172
168
),
173
169
);
174
170
175
- $ makers [ 'twig_extension ' ] = array (
171
+ yield 'twig_extension ' => array (
176
172
new MakeTwigExtension (),
177
173
array (
178
174
// extension class name
179
175
'FooBar ' ,
180
176
),
181
177
);
182
178
183
- $ makers [ 'unit_test ' ] = array (
179
+ yield 'unit_test ' => array (
184
180
new MakeUnitTest (),
185
181
array (
186
182
// class name
187
183
'FooBar ' ,
188
184
),
189
185
);
190
186
191
- $ makers [ 'validator ' ] = array (
187
+ yield 'validator ' => array (
192
188
new MakeValidator (),
193
189
array (
194
190
// validator name
195
191
'FooBar ' ,
196
192
),
197
193
);
198
194
199
- $ makers [ 'voter ' ] = array (
195
+ yield 'voter ' => array (
200
196
new MakeVoter (),
201
197
array (
202
198
// voter class name
203
199
'FooBar ' ,
204
200
),
205
201
);
206
202
207
- $ makers [ 'auth_empty ' ] = array (
203
+ yield 'auth_empty ' => array (
208
204
new MakeAuthenticator (),
209
205
array (
210
206
// class name
211
207
'AppCustomAuthenticator ' ,
212
208
),
213
209
);
214
-
215
- return $ makers ;
216
210
}
217
211
218
212
/**
@@ -228,7 +222,7 @@ public function testWiring()
228
222
229
223
$ application = new Application ($ kernel );
230
224
foreach ($ finder as $ file ) {
231
- $ class = 'Symfony\Bundle\MakerBundle\Maker \\' .substr ( $ file ->getFilename (), 0 , strlen ( $ file -> getFilename ()) - 4 );
225
+ $ class = 'Symfony\Bundle\MakerBundle\Maker \\' .$ file ->getBasename ( ' .php ' );
232
226
233
227
$ commandName = $ class ::getCommandName ();
234
228
// if the command does not exist, this will explode
@@ -263,8 +257,6 @@ class FunctionalTestKernel extends Kernel
263
257
{
264
258
use MicroKernelTrait;
265
259
266
- private $ cacheDir ;
267
-
268
260
public function registerBundles ()
269
261
{
270
262
return array (
@@ -282,12 +274,8 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
282
274
$ c ->setParameter ('kernel.secret ' , 123 );
283
275
}
284
276
285
- public function getCacheDir ()
277
+ public function getRootDir ()
286
278
{
287
- if (null === $ this ->cacheDir ) {
288
- $ this ->cacheDir = sys_get_temp_dir ().'/ ' .rand (100 , 999 );
289
- }
290
-
291
- return $ this ->cacheDir ;
279
+ return sys_get_temp_dir ().'/ ' .uniqid ('sf_maker_ ' , true );
292
280
}
293
281
}
0 commit comments