Skip to content

Commit baec3cb

Browse files
committed
minor #891 [tests] housekeeping (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- [tests] housekeeping - removes `override_url` config logic (feature has was introduced && deprecated in doctrine-bundle 2.3) - remove duplicate directory getter - run generated projects `bin/phpunit` instead of "makers" `simple-phpunit` - add return types to touched classes Commits ------- 5681a5f [tests] housekeeping
2 parents 5da4340 + 5681a5f commit baec3cb

File tree

2 files changed

+26
-65
lines changed

2 files changed

+26
-65
lines changed

src/Test/MakerTestEnvironment.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function readFile(string $path): string
7878
return file_get_contents($this->path.'/'.$path);
7979
}
8080

81-
private function changeRootNamespaceIfNeeded()
81+
private function changeRootNamespaceIfNeeded(): void
8282
{
8383
if ('App' === ($rootNamespace = $this->testDetails->getRootNamespace())) {
8484
return;
@@ -128,7 +128,7 @@ private function changeRootNamespaceIfNeeded()
128128
$this->processReplacements($replacements, $this->path);
129129
}
130130

131-
public function prepare()
131+
public function prepare(): void
132132
{
133133
if (!$this->fs->exists($this->flexPath)) {
134134
$this->buildFlexSkeleton();
@@ -198,15 +198,15 @@ public function prepare()
198198
->run();
199199
}
200200

201-
private function preMake()
201+
private function preMake(): void
202202
{
203203
foreach ($this->testDetails->getPreMakeCommands() as $preCommand) {
204204
MakerTestProcess::create($preCommand, $this->path)
205205
->run();
206206
}
207207
}
208208

209-
public function runMaker()
209+
public function runMaker(): MakerTestProcess
210210
{
211211
// Lets remove cache
212212
$this->fs->remove($this->path.'/var/cache');
@@ -248,7 +248,7 @@ public function runMaker()
248248
return $this->runnedMakerProcess;
249249
}
250250

251-
public function getGeneratedFilesFromOutputText()
251+
public function getGeneratedFilesFromOutputText(): array
252252
{
253253
$output = $this->runnedMakerProcess->getOutput();
254254

@@ -259,37 +259,37 @@ public function getGeneratedFilesFromOutputText()
259259
return array_map('trim', $matches[3]);
260260
}
261261

262-
public function fileExists(string $file)
262+
public function fileExists(string $file): bool
263263
{
264264
return $this->fs->exists($this->path.'/'.$file);
265265
}
266266

267-
public function runPhpCSFixer(string $file)
267+
public function runPhpCSFixer(string $file): MakerTestProcess
268268
{
269269
return MakerTestProcess::create(sprintf('php vendor/bin/php-cs-fixer --config=%s fix --dry-run --diff %s', __DIR__.'/../Resources/test/.php_cs.test', $this->path.'/'.$file), $this->rootPath)
270270
->run(true);
271271
}
272272

273-
public function runTwigCSLint(string $file)
273+
public function runTwigCSLint(string $file): MakerTestProcess
274274
{
275275
return MakerTestProcess::create(sprintf('php vendor/bin/twigcs --config ./.twig_cs.dist %s', $this->path.'/'.$file), $this->rootPath)
276276
->run(true);
277277
}
278278

279-
public function runInternalTests()
279+
public function runInternalTests(): ?MakerTestProcess
280280
{
281281
$finder = new Finder();
282282
$finder->in($this->path.'/tests')->files();
283283
if ($finder->count() > 0) {
284284
// execute the tests that were moved into the project!
285-
return MakerTestProcess::create(sprintf('php %s', $this->rootPath.'/vendor/bin/simple-phpunit'), $this->path)
285+
return MakerTestProcess::create(sprintf('php %s', $this->path.'/bin/phpunit'), $this->path)
286286
->run(true);
287287
}
288288

289289
return null;
290290
}
291291

292-
private function postMake()
292+
private function postMake(): void
293293
{
294294
$this->processReplacements($this->testDetails->getPostMakeReplacements(), $this->path);
295295

@@ -318,7 +318,7 @@ private function postMake()
318318
}
319319
}
320320

321-
private function buildFlexSkeleton()
321+
private function buildFlexSkeleton(): void
322322
{
323323
$targetVersion = $this->getTargetSkeletonVersion();
324324
$versionString = $targetVersion ? sprintf(':%s', $targetVersion) : '';
@@ -397,7 +397,7 @@ private function buildFlexSkeleton()
397397
)->run();
398398
}
399399

400-
private function processReplacements(array $replacements, $rootDir)
400+
private function processReplacements(array $replacements, $rootDir): void
401401
{
402402
foreach ($replacements as $replacement) {
403403
$path = realpath($rootDir.'/'.$replacement['filename']);

tests/Doctrine/EntityRegeneratorTest.php

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine;
1313

14-
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
1514
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1615
use Doctrine\Persistence\ManagerRegistry;
1716
use PHPUnit\Framework\TestCase;
@@ -41,7 +40,7 @@ class EntityRegeneratorTest extends TestCase
4140
/**
4241
* @dataProvider getRegenerateEntitiesTests
4342
*/
44-
public function testRegenerateEntities(string $expectedDirName, bool $overwrite)
43+
public function testRegenerateEntities(string $expectedDirName, bool $overwrite): void
4544
{
4645
/*
4746
* Prior to symfony/doctrine-bridge 5.0 (which require
@@ -65,7 +64,7 @@ public function testRegenerateEntities(string $expectedDirName, bool $overwrite)
6564
);
6665
}
6766

68-
public function getRegenerateEntitiesTests()
67+
public function getRegenerateEntitiesTests(): \Generator
6968
{
7069
yield 'regenerate_no_overwrite' => [
7170
'expected_no_overwrite',
@@ -78,7 +77,7 @@ public function getRegenerateEntitiesTests()
7877
];
7978
}
8079

81-
public function testXmlRegeneration()
80+
public function testXmlRegeneration(): void
8281
{
8382
$kernel = new TestXmlEntityRegeneratorKernel('dev', true);
8483
$this->doTestRegeneration(
@@ -91,7 +90,7 @@ public function testXmlRegeneration()
9190
);
9291
}
9392

94-
private function doTestRegeneration(string $sourceDir, Kernel $kernel, string $namespace, string $expectedDirName, bool $overwrite, string $targetDirName)
93+
private function doTestRegeneration(string $sourceDir, Kernel $kernel, string $namespace, string $expectedDirName, bool $overwrite, string $targetDirName): void
9594
{
9695
$fs = new Filesystem();
9796
$tmpDir = __DIR__.'/../tmp/'.$targetDirName;
@@ -157,21 +156,20 @@ private function createAllButTraitsIterator(string $sourceDir): \Iterator
157156
class TestEntityRegeneratorKernel extends Kernel
158157
{
159158
use MicroKernelTrait;
160-
use OverrideUrlTraitFixture;
161159

162-
public function registerBundles()
160+
public function registerBundles(): array
163161
{
164162
return [
165163
new FrameworkBundle(),
166164
new DoctrineBundle(),
167165
];
168166
}
169167

170-
protected function configureRoutes(RouteCollectionBuilder $routes)
168+
protected function configureRoutes(RouteCollectionBuilder $routes): void
171169
{
172170
}
173171

174-
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
172+
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
175173
{
176174
$c->loadFromExtension('framework', [
177175
'secret' => 123,
@@ -185,10 +183,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
185183
'url' => 'sqlite:///fake',
186184
];
187185

188-
if ($this->canOverrideUrl($c)) {
189-
$dbal['override_url'] = true;
190-
}
191-
192186
$c->prependExtensionConfig('doctrine', [
193187
'dbal' => $dbal,
194188
'orm' => [
@@ -205,12 +199,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
205199
]);
206200
}
207201

208-
public function getProjectDir()
209-
{
210-
return $this->getRootDir();
211-
}
212-
213-
public function getRootDir()
202+
public function getProjectDir(): string
214203
{
215204
return __DIR__.'/../tmp/current_project';
216205
}
@@ -219,21 +208,20 @@ public function getRootDir()
219208
class TestXmlEntityRegeneratorKernel extends Kernel
220209
{
221210
use MicroKernelTrait;
222-
use OverrideUrlTraitFixture;
223211

224-
public function registerBundles()
212+
public function registerBundles(): array
225213
{
226214
return [
227215
new FrameworkBundle(),
228216
new DoctrineBundle(),
229217
];
230218
}
231219

232-
protected function configureRoutes(RouteCollectionBuilder $routes)
220+
protected function configureRoutes(RouteCollectionBuilder $routes): void
233221
{
234222
}
235223

236-
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
224+
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
237225
{
238226
$c->loadFromExtension('framework', [
239227
'secret' => 123,
@@ -247,10 +235,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
247235
'url' => 'sqlite:///fake',
248236
];
249237

250-
if ($this->canOverrideUrl($c)) {
251-
$dbal['override_url'] = true;
252-
}
253-
254238
$c->prependExtensionConfig('doctrine', [
255239
'dbal' => $dbal,
256240
'orm' => [
@@ -268,39 +252,16 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
268252
]);
269253
}
270254

271-
public function getProjectDir()
272-
{
273-
return $this->getRootDir();
274-
}
275-
276-
public function getRootDir()
255+
public function getProjectDir(): string
277256
{
278257
return __DIR__.'/../tmp/current_project_xml';
279258
}
280259
}
281260

282261
class AllButTraitsIterator extends \RecursiveFilterIterator
283262
{
284-
public function accept()
263+
public function accept(): bool
285264
{
286265
return !\in_array($this->current()->getFilename(), []);
287266
}
288267
}
289-
290-
trait OverrideUrlTraitFixture
291-
{
292-
/**
293-
* Quick and dirty way to check if override_url is required since doctrine-bundle 2.3.
294-
*/
295-
public function canOverrideUrl(ContainerBuilder $builder): bool
296-
{
297-
/** @var DoctrineExtension $ext */
298-
$ext = $builder->getExtension('doctrine');
299-
$method = new \ReflectionMethod(DoctrineExtension::class, 'getConnectionOptions');
300-
$method->setAccessible(true);
301-
302-
$configOptions = $method->invoke($ext, ['override_url' => 'string', 'shards' => [], 'replicas' => [], 'slaves' => []]);
303-
304-
return \array_key_exists('connection_override_options', $configOptions);
305-
}
306-
}

0 commit comments

Comments
 (0)