From 4d8d32b726e7af21a562a2b6a227f0496c7d39d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 16 Jan 2024 12:03:11 +0100 Subject: [PATCH] Fix type for commands. ManagerRegistry::getManager() accepts null (#837) --- src/Command/DoctrineODMCommand.php | 2 +- tests/Command/DoctrineODMCommandTest.php | 31 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/Command/DoctrineODMCommandTest.php diff --git a/src/Command/DoctrineODMCommand.php b/src/Command/DoctrineODMCommand.php index 178224cf..1efe3f08 100644 --- a/src/Command/DoctrineODMCommand.php +++ b/src/Command/DoctrineODMCommand.php @@ -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(); diff --git a/tests/Command/DoctrineODMCommandTest.php b/tests/Command/DoctrineODMCommandTest.php new file mode 100644 index 00000000..f58c43de --- /dev/null +++ b/tests/Command/DoctrineODMCommandTest.php @@ -0,0 +1,31 @@ +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]; + } +}