Skip to content

Commit

Permalink
Fix type for commands. ManagerRegistry::getManager() accepts null (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jan 16, 2024
1 parent 2467b09 commit 4d8d32b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Command/DoctrineODMCommand.php
Expand Up @@ -21,7 +21,7 @@ public function __construct(private ManagerRegistry $registry)
parent::__construct();
}

public static function setApplicationDocumentManager(Application $application, string $dmName): void
public static function setApplicationDocumentManager(Application $application, ?string $dmName): void
{
$dm = $application->getKernel()->getContainer()->get('doctrine_mongodb')->getManager($dmName);
$helperSet = $application->getHelperSet();
Expand Down
31 changes: 31 additions & 0 deletions tests/Command/DoctrineODMCommandTest.php
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\MongoDBBundle\Tests\Command;

use Doctrine\Bundle\MongoDBBundle\Command\DoctrineODMCommand;
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class DoctrineODMCommandTest extends KernelTestCase
{
/** @dataProvider provideDmName */
public function testSetApplicationManager(?string $dmName): void
{
$kernel = new CommandTestKernel('test', false);
$kernel->boot();
$application = new Application($kernel);

DoctrineODMCommand::setApplicationDocumentManager($application, $dmName);

$this->assertInstanceOf(DocumentManagerHelper::class, $application->getHelperSet()->get('dm'));
}

public static function provideDmName(): iterable
{
yield ['command_test'];
yield [null];
}
}

0 comments on commit 4d8d32b

Please sign in to comment.