Skip to content

Commit 5d76dd6

Browse files
Add method_exists to avoid fatal error
Related error: ``` [Symfony\Component\Debug\Exception\UndefinedMethodException] Attempted to call an undefined method named "getCustomTemplate" of class "Doctrine\DBAL\Migrations\Configuration\Configuration". ``` This commit can be reverted when https://github.com/doctrine/migrations v1.6 is released.
1 parent 850c81e commit 5d76dd6

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Command/DoctrineCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function configureMigrations(ContainerInterface $container, Config
6767
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
6868
}
6969

70-
if (!$configuration->getCustomTemplate()) {
70+
if (method_exists($configuration, 'getCustomTemplate') && !$configuration->getCustomTemplate()) {
7171
$configuration->setCustomTemplate($container->getParameter('doctrine_migrations.custom_template'));
7272
}
7373

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection;
4+
5+
use Doctrine\Bundle\MigrationsBundle\Command\DoctrineCommand;
6+
use Doctrine\DBAL\Migrations\Configuration\Configuration;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
9+
10+
class DoctrineCommandTest extends \PHPUnit\Framework\TestCase
11+
{
12+
public function testConfigureMigrations()
13+
{
14+
$configurationMock = $this->getMockBuilder('Doctrine\DBAL\Migrations\Configuration\Configuration')
15+
->disableOriginalConstructor()
16+
->getMock();
17+
18+
$configurationMock->method('getMigrations')
19+
->willReturn(array());
20+
21+
DoctrineCommand::configureMigrations($this->getContainer(), $configurationMock);
22+
}
23+
24+
private function getContainer()
25+
{
26+
return new ContainerBuilder(new ParameterBag(array(
27+
'doctrine_migrations.dir_name' => __DIR__.'/../../',
28+
'doctrine_migrations.namespace' => 'test',
29+
'doctrine_migrations.name' => 'test',
30+
'doctrine_migrations.table_name' => 'test',
31+
'doctrine_migrations.organize_migrations' => Configuration::VERSIONS_ORGANIZATION_BY_YEAR,
32+
)));
33+
}
34+
}

0 commit comments

Comments
 (0)