Skip to content

Commit cf62a28

Browse files
committed
minor #70 Simplification and minor fixes to functional test (yceruto)
This PR was merged into the 1.0-dev branch. Discussion ---------- Simplification and minor fixes to functional test Commits ------- 83bbaee Improving functional test
2 parents 57c8372 + 83bbaee commit cf62a28

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

tests/Command/FunctionalTest.php

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
88
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
99
use Symfony\Bundle\MakerBundle\Command\MakerCommand;
10+
use Symfony\Bundle\MakerBundle\EventRegistry;
11+
use Symfony\Bundle\MakerBundle\FileManager;
12+
use Symfony\Bundle\MakerBundle\Generator;
1013
use Symfony\Bundle\MakerBundle\Maker\MakeAuthenticator;
1114
use Symfony\Bundle\MakerBundle\Maker\MakeCommand;
1215
use Symfony\Bundle\MakerBundle\Maker\MakeController;
@@ -19,9 +22,6 @@
1922
use Symfony\Bundle\MakerBundle\Maker\MakeUnitTest;
2023
use Symfony\Bundle\MakerBundle\Maker\MakeValidator;
2124
use Symfony\Bundle\MakerBundle\Maker\MakeVoter;
22-
use Symfony\Bundle\MakerBundle\EventRegistry;
23-
use Symfony\Bundle\MakerBundle\FileManager;
24-
use Symfony\Bundle\MakerBundle\Generator;
2525
use Symfony\Bundle\MakerBundle\MakerBundle;
2626
use Symfony\Bundle\MakerBundle\MakerInterface;
2727
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -38,20 +38,19 @@
3838

3939
class FunctionalTest extends TestCase
4040
{
41+
private $fs;
4142
private $targetDir;
4243

4344
public function setUp()
4445
{
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);
4949
}
5050

5151
public function tearDown()
5252
{
53-
$fs = new Filesystem();
54-
$fs->remove($this->targetDir);
53+
$this->fs->remove($this->targetDir);
5554
}
5655

5756
/**
@@ -60,7 +59,6 @@ public function tearDown()
6059
public function testCommands(MakerInterface $maker, array $inputs)
6160
{
6261
$command = new MakerCommand($maker, $this->createGenerator());
63-
6462
$command->setCheckDependencies(false);
6563

6664
$tester = new CommandTester($command);
@@ -81,9 +79,7 @@ public function testCommands(MakerInterface $maker, array $inputs)
8179

8280
public function getCommandTests()
8381
{
84-
$makers = array();
85-
86-
$makers['command'] = array(
82+
yield 'command' => array(
8783
new MakeCommand(),
8884
array(
8985
// command name
@@ -95,31 +91,31 @@ public function getCommandTests()
9591
$router->expects($this->once())
9692
->method('getRouteCollection')
9793
->willReturn(new RouteCollection());
98-
$makers['controller'] = array(
94+
yield 'controller' => array(
9995
new MakeController($router),
10096
array(
10197
// controller class name
10298
'FooBar',
10399
),
104100
);
105101

106-
$makers['entity'] = array(
102+
yield 'entity' => array(
107103
new MakeEntity(),
108104
array(
109105
// entity class name
110106
'FooBar',
111107
),
112108
);
113109

114-
$makers['form'] = array(
110+
yield 'form' => array(
115111
new MakeForm(),
116112
array(
117113
// form name
118114
'FooBar',
119115
),
120116
);
121117

122-
$makers['functional'] = array(
118+
yield 'functional' => array(
123119
new MakeFunctionalTest(),
124120
array(
125121
// functional test class
@@ -135,7 +131,7 @@ public function getCommandTests()
135131
->method('getEventClassName')
136132
->with('kernel.request')
137133
->willReturn(GetResponseEvent::class);
138-
$makers['subscriber'] = array(
134+
yield 'subscriber' => array(
139135
new MakeSubscriber($eventRegistry),
140136
array(
141137
// subscriber name
@@ -152,7 +148,7 @@ public function getCommandTests()
152148
$eventRegistry2->expects($this->once())
153149
->method('getEventClassName')
154150
->willReturn(null);
155-
$makers['subscriber_unknown_event_class'] = array(
151+
yield 'subscriber_unknown_event_class' => array(
156152
new MakeSubscriber($eventRegistry2),
157153
array(
158154
// subscriber name
@@ -162,7 +158,7 @@ public function getCommandTests()
162158
),
163159
);
164160

165-
$makers['serializer_encoder'] = array(
161+
yield 'serializer_encoder' => array(
166162
new MakeSerializerEncoder(),
167163
array(
168164
// encoder class name
@@ -172,47 +168,45 @@ public function getCommandTests()
172168
),
173169
);
174170

175-
$makers['twig_extension'] = array(
171+
yield 'twig_extension' => array(
176172
new MakeTwigExtension(),
177173
array(
178174
// extension class name
179175
'FooBar',
180176
),
181177
);
182178

183-
$makers['unit_test'] = array(
179+
yield 'unit_test' => array(
184180
new MakeUnitTest(),
185181
array(
186182
// class name
187183
'FooBar',
188184
),
189185
);
190186

191-
$makers['validator'] = array(
187+
yield 'validator' => array(
192188
new MakeValidator(),
193189
array(
194190
// validator name
195191
'FooBar',
196192
),
197193
);
198194

199-
$makers['voter'] = array(
195+
yield 'voter' => array(
200196
new MakeVoter(),
201197
array(
202198
// voter class name
203199
'FooBar',
204200
),
205201
);
206202

207-
$makers['auth_empty'] = array(
203+
yield 'auth_empty' => array(
208204
new MakeAuthenticator(),
209205
array(
210206
// class name
211207
'AppCustomAuthenticator',
212208
),
213209
);
214-
215-
return $makers;
216210
}
217211

218212
/**
@@ -228,7 +222,7 @@ public function testWiring()
228222

229223
$application = new Application($kernel);
230224
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');
232226

233227
$commandName = $class::getCommandName();
234228
// if the command does not exist, this will explode
@@ -263,8 +257,6 @@ class FunctionalTestKernel extends Kernel
263257
{
264258
use MicroKernelTrait;
265259

266-
private $cacheDir;
267-
268260
public function registerBundles()
269261
{
270262
return array(
@@ -282,12 +274,8 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
282274
$c->setParameter('kernel.secret', 123);
283275
}
284276

285-
public function getCacheDir()
277+
public function getRootDir()
286278
{
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);
292280
}
293281
}

0 commit comments

Comments
 (0)