diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DoctrineCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DoctrineCommandTest.php index da7c9f766e..fff9de9bcd 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DoctrineCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DoctrineCommandTest.php @@ -5,7 +5,9 @@ namespace Doctrine\Migrations\Tests\Tools\Console\Command; use Doctrine\Migrations\Configuration\Configuration; +use Doctrine\Migrations\Configuration\Connection\ConnectionLoader; use Doctrine\Migrations\Configuration\Connection\ExistingConnection; +use Doctrine\Migrations\Configuration\Migration\ConfigurationLoader; use Doctrine\Migrations\Configuration\Migration\ExistingConfiguration; use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Tests\MigrationTestCase; @@ -13,7 +15,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; - use function sys_get_temp_dir; class DoctrineCommandTest extends MigrationTestCase @@ -29,8 +30,7 @@ public function testCommandFreezes(): void ->expects(self::once()) ->method('freeze'); - $command = new class ($dependencyFactory) extends DoctrineCommand - { + $command = new class ($dependencyFactory) extends DoctrineCommand { protected function execute(InputInterface $input, OutputInterface $output): int { return 0; @@ -44,6 +44,39 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + public function testCommandNotThrowingFrozenException() + { + $configurationLoader = $this->createMock(ConfigurationLoader::class); + $configurationLoader->method('getConfiguration')->willReturn(new Configuration()); + + $dependencyFactory = DependencyFactory::fromConnection( + $configurationLoader, + $this->createMock(ConnectionLoader::class) + ); + + $command = new class ($dependencyFactory) extends DoctrineCommand { + protected function execute(InputInterface $input, OutputInterface $output): int + { + return 0; + } + }; + $commandTester = new CommandTester($command); + + // execute once, this will freeze the dependencies. + $commandTester->execute( + ['--configuration' => __DIR__.'/_files/config.yml'], + ['interactive' => false,] + ); + + // execute one more time, this will throw exception. + $commandTester->execute( + ['--configuration' => __DIR__.'/_files/config.yml'], + ['interactive' => false,] + ); + + $this->expectNotToPerformAssertions(); + } + public function testCustomConfiguration(): void { $configuration = new Configuration(); @@ -56,8 +89,7 @@ public function testCustomConfiguration(): void new ExistingConnection($conn) ); - $command = new class ($dependencyFactory) extends DoctrineCommand - { + $command = new class ($dependencyFactory) extends DoctrineCommand { protected function execute(InputInterface $input, OutputInterface $output): int { $migrationDirectories = $this->getDependencyFactory()->getConfiguration()->getMigrationDirectories(); @@ -69,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $commandTester = new CommandTester($command); $commandTester->execute( - ['--configuration' => __DIR__ . '/_files/config.yml'], + ['--configuration' => __DIR__.'/_files/config.yml'], ['interactive' => false] ); } @@ -77,8 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int public function testDependencyFactoryIsSetFirst(): void { $dependencyFactory = $this->createMock(DependencyFactory::class); - $command = new class ($dependencyFactory) extends DoctrineCommand - { + $command = new class ($dependencyFactory) extends DoctrineCommand { protected function configure(): void { $this->getDependencyFactory();