55namespace Doctrine \Migrations \Tests \Tools \Console \Command ;
66
77use Doctrine \Migrations \Configuration \Configuration ;
8+ use Doctrine \Migrations \Configuration \Connection \ConnectionLoader ;
89use Doctrine \Migrations \Configuration \Connection \ExistingConnection ;
10+ use Doctrine \Migrations \Configuration \Migration \ConfigurationLoader ;
911use Doctrine \Migrations \Configuration \Migration \ExistingConfiguration ;
1012use Doctrine \Migrations \DependencyFactory ;
1113use Doctrine \Migrations \Tests \MigrationTestCase ;
1214use Doctrine \Migrations \Tools \Console \Command \DoctrineCommand ;
1315use Symfony \Component \Console \Input \InputInterface ;
1416use Symfony \Component \Console \Output \OutputInterface ;
1517use Symfony \Component \Console \Tester \CommandTester ;
16-
1718use function sys_get_temp_dir ;
1819
1920class DoctrineCommandTest extends MigrationTestCase
@@ -29,8 +30,7 @@ public function testCommandFreezes(): void
2930 ->expects (self ::once ())
3031 ->method ('freeze ' );
3132
32- $ command = new class ($ dependencyFactory ) extends DoctrineCommand
33- {
33+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
3434 protected function execute (InputInterface $ input , OutputInterface $ output ): int
3535 {
3636 return 0 ;
@@ -44,6 +44,39 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4444 );
4545 }
4646
47+ public function testCommandNotThrowingFrozenException ()
48+ {
49+ $ configurationLoader = $ this ->createMock (ConfigurationLoader::class);
50+ $ configurationLoader ->method ('getConfiguration ' )->willReturn (new Configuration ());
51+
52+ $ dependencyFactory = DependencyFactory::fromConnection (
53+ $ configurationLoader ,
54+ $ this ->createMock (ConnectionLoader::class)
55+ );
56+
57+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
58+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
59+ {
60+ return 0 ;
61+ }
62+ };
63+ $ commandTester = new CommandTester ($ command );
64+
65+ // execute once, this will freeze the dependencies.
66+ $ commandTester ->execute (
67+ ['--configuration ' => __DIR__ . '/_files/config.yml ' ],
68+ ['interactive ' => false ,]
69+ );
70+
71+ // execute one more time, this will throw exception.
72+ $ commandTester ->execute (
73+ ['--configuration ' => __DIR__ . '/_files/config.yml ' ],
74+ ['interactive ' => false ,]
75+ );
76+
77+ $ this ->expectNotToPerformAssertions ();
78+ }
79+
4780 public function testCustomConfiguration (): void
4881 {
4982 $ configuration = new Configuration ();
@@ -56,8 +89,7 @@ public function testCustomConfiguration(): void
5689 new ExistingConnection ($ conn )
5790 );
5891
59- $ command = new class ($ dependencyFactory ) extends DoctrineCommand
60- {
92+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
6193 protected function execute (InputInterface $ input , OutputInterface $ output ): int
6294 {
6395 $ migrationDirectories = $ this ->getDependencyFactory ()->getConfiguration ()->getMigrationDirectories ();
@@ -77,8 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
77109 public function testDependencyFactoryIsSetFirst (): void
78110 {
79111 $ dependencyFactory = $ this ->createMock (DependencyFactory::class);
80- $ command = new class ($ dependencyFactory ) extends DoctrineCommand
81- {
112+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
82113 protected function configure (): void
83114 {
84115 $ this ->getDependencyFactory ();
0 commit comments