Skip to content

Commit 02280d8

Browse files
committed
remove default from migrations path
1 parent 7f5765e commit 02280d8

File tree

3 files changed

+156
-5
lines changed

3 files changed

+156
-5
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ public function getConfigTreeBuilder() : TreeBuilder
4949
->scalarNode('name')->defaultValue('Application Migrations')->end()
5050

5151
->arrayNode('migrations_paths')
52-
5352
->info('A list of namespace/path pairs where to look for migrations.')
53+
->isRequired()
5454
->requiresAtLeastOneElement()
5555
->useAttributeAsKey('namespace')
56-
->defaultValue(['%kernel.project_dir%/src/Migrations' => 'App\Migrations'])
5756
->prototype('scalar')->end()
5857
->end()
5958

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection;
6+
7+
use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension;
8+
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
9+
use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand;
10+
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
11+
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand;
12+
use Doctrine\Migrations\Tools\Console\Command\LatestCommand;
13+
use Doctrine\Migrations\Tools\Console\Command\ListCommand;
14+
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
15+
use Doctrine\Migrations\Tools\Console\Command\RollupCommand;
16+
use Doctrine\Migrations\Tools\Console\Command\StatusCommand;
17+
use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand;
18+
use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand;
19+
use Doctrine\Migrations\Tools\Console\Command\VersionCommand;
20+
use Doctrine\ORM\EntityManager;
21+
use PHPUnit\Framework\MockObject\MockObject;
22+
use PHPUnit\Framework\TestCase;
23+
use Symfony\Bundle\FrameworkBundle\Console\Application;
24+
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
25+
use Symfony\Component\DependencyInjection\ContainerBuilder;
26+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
27+
use Symfony\Component\HttpKernel\KernelInterface;
28+
use function sys_get_temp_dir;
29+
30+
class DoctrineCommandsTest extends TestCase
31+
{
32+
/**
33+
* @dataProvider getCommands
34+
*/
35+
public function testCommandRegistered(string $name, string $instance) : void
36+
{
37+
$application = $this->getApplication();
38+
39+
self::assertInstanceOf($instance, $application->find($name));
40+
}
41+
42+
/**
43+
* @return string[][]
44+
*/
45+
public function getCommands() : array
46+
{
47+
return [
48+
['doctrine:migrations:diff', DiffCommand::class],
49+
['doctrine:migrations:dump-schema', DumpSchemaCommand::class],
50+
['doctrine:migrations:execute', ExecuteCommand::class],
51+
['doctrine:migrations:generate', GenerateCommand::class],
52+
['doctrine:migrations:latest', LatestCommand::class],
53+
['doctrine:migrations:list', ListCommand::class],
54+
['doctrine:migrations:migrate', MigrateCommand::class],
55+
['doctrine:migrations:rollup', RollupCommand::class],
56+
['doctrine:migrations:status', StatusCommand::class],
57+
['doctrine:migrations:sync-metadata-storage', SyncMetadataCommand::class],
58+
['doctrine:migrations:up-to-date', UpToDateCommand::class],
59+
['doctrine:migrations:version', VersionCommand::class],
60+
];
61+
}
62+
63+
/**
64+
* @return MockObject|KernelInterface
65+
*/
66+
private function getKernel(ContainerBuilder $container)
67+
{
68+
$kernel = $this
69+
->getMockBuilder(KernelInterface::class)
70+
->getMock();
71+
72+
$kernel
73+
->expects(self::any())
74+
->method('getContainer')
75+
->willReturn($container);
76+
77+
$kernel
78+
->expects(self::once())
79+
->method('getBundles')
80+
->willReturn([]);
81+
82+
return $kernel;
83+
}
84+
85+
private function getApplication() : Application
86+
{
87+
$container = new ContainerBuilder(new ParameterBag([
88+
'kernel.debug' => false,
89+
'kernel.bundles' => [],
90+
'kernel.cache_dir' => sys_get_temp_dir(),
91+
'kernel.environment' => 'test',
92+
'kernel.project_dir' => __DIR__ . '/../',
93+
]));
94+
95+
$kernel = $this->getKernel($container);
96+
$application = new Application($kernel);
97+
$container->set('application', $application);
98+
99+
$em = $this->createMock(EntityManager::class);
100+
$container->set('doctrine.orm.default_entity_manager', $em);
101+
102+
$container->addCompilerPass(new AddConsoleCommandPass());
103+
104+
$extension = new DoctrineMigrationsExtension();
105+
$extension->load([
106+
'doctrine_migrations' => [
107+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
108+
],
109+
], $container);
110+
111+
$container->compile();
112+
113+
return $application;
114+
}
115+
}

Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2626
use function assert;
2727
use function method_exists;
28+
use function print_r;
2829
use function sys_get_temp_dir;
2930

3031
class DoctrineMigrationsExtensionTest extends TestCase
@@ -91,6 +92,28 @@ public function testFullConfig() : void
9192
$this->assertConfigs($config);
9293
}
9394

95+
public function testNoConfig() : void
96+
{
97+
$this->expectException(InvalidConfigurationException::class);
98+
$this->expectExceptionMessage('The child node "migrations_paths" at path "doctrine_migrations" must be configured.');
99+
100+
$container = $this->getContainer();
101+
$extension = new DoctrineMigrationsExtension();
102+
103+
$conn = $this->createMock(Connection::class);
104+
$container->set('doctrine.dbal.default_connection', $conn);
105+
106+
$extension->load([], $container);
107+
108+
$container->getDefinition('doctrine.migrations.configuration')->setPublic(true);
109+
$container->compile();
110+
111+
$config = $container->get('doctrine.migrations.configuration');
112+
113+
print_r($config);
114+
}
115+
116+
94117
private function assertConfigs(?object $config) : void
95118
{
96119
self::assertInstanceOf(Configuration::class, $config);
@@ -122,6 +145,7 @@ public function testCustomSorter() : void
122145
$extension = new DoctrineMigrationsExtension();
123146

124147
$config = [
148+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
125149
'services' => [Comparator::class => 'my_sorter'],
126150
];
127151

@@ -151,7 +175,10 @@ public function testCustomConnection() : void
151175
$container = $this->getContainer();
152176
$extension = new DoctrineMigrationsExtension();
153177

154-
$config = ['connection' => 'custom'];
178+
$config = [
179+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
180+
'connection' => 'custom',
181+
];
155182

156183
$extension->load(['doctrine_migrations' => $config], $container);
157184

@@ -176,7 +203,11 @@ public function testPrefersEntityManagerOverConnection() : void
176203
$em = $this->createMock(EntityManager::class);
177204
$container->set('doctrine.orm.default_entity_manager', $em);
178205

179-
$extension->load(['doctrine_migrations' => []], $container);
206+
$extension->load([
207+
'doctrine_migrations' => [
208+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
209+
],
210+
], $container);
180211

181212
$container->getDefinition('doctrine.migrations.dependency_factory')->setPublic(true);
182213

@@ -193,7 +224,10 @@ public function testCustomEntityManager() : void
193224
$container = $this->getContainer();
194225
$extension = new DoctrineMigrationsExtension();
195226

196-
$config = ['em' => 'custom'];
227+
$config = [
228+
'em' => 'custom',
229+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
230+
];
197231

198232
$em = new Definition(CustomEntityManager::class);
199233
$container->setDefinition('doctrine.orm.custom_entity_manager', $em);
@@ -221,6 +255,7 @@ public function testCustomMetadataStorage() : void
221255
$extension = new DoctrineMigrationsExtension();
222256

223257
$config = [
258+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
224259
'services' => [MetadataStorage::class => 'mock_storage_service'],
225260
];
226261

@@ -249,6 +284,7 @@ public function testInvalidService() : void
249284
$extension = new DoctrineMigrationsExtension();
250285

251286
$config = [
287+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
252288
'services' => ['foo' => 'mock_storage_service'],
253289
];
254290

@@ -268,6 +304,7 @@ public function testCanNotSpecifyBothEmAndConnection() : void
268304
$extension = new DoctrineMigrationsExtension();
269305

270306
$config = [
307+
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
271308
'em' => 'custom',
272309
'connection' => 'custom',
273310
];

0 commit comments

Comments
 (0)