5
5
namespace Doctrine \Migrations \Tests \Tools \Console \Command ;
6
6
7
7
use Doctrine \Migrations \Configuration \Configuration ;
8
+ use Doctrine \Migrations \Configuration \Connection \ConnectionLoader ;
8
9
use Doctrine \Migrations \Configuration \Connection \ExistingConnection ;
10
+ use Doctrine \Migrations \Configuration \Migration \ConfigurationLoader ;
9
11
use Doctrine \Migrations \Configuration \Migration \ExistingConfiguration ;
10
12
use Doctrine \Migrations \DependencyFactory ;
11
13
use Doctrine \Migrations \Tests \MigrationTestCase ;
12
14
use Doctrine \Migrations \Tools \Console \Command \DoctrineCommand ;
13
15
use Symfony \Component \Console \Input \InputInterface ;
14
16
use Symfony \Component \Console \Output \OutputInterface ;
15
17
use Symfony \Component \Console \Tester \CommandTester ;
16
-
17
18
use function sys_get_temp_dir ;
18
19
19
20
class DoctrineCommandTest extends MigrationTestCase
@@ -29,8 +30,7 @@ public function testCommandFreezes(): void
29
30
->expects (self ::once ())
30
31
->method ('freeze ' );
31
32
32
- $ command = new class ($ dependencyFactory ) extends DoctrineCommand
33
- {
33
+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
34
34
protected function execute (InputInterface $ input , OutputInterface $ output ): int
35
35
{
36
36
return 0 ;
@@ -44,6 +44,39 @@ protected function execute(InputInterface $input, OutputInterface $output): int
44
44
);
45
45
}
46
46
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
+
47
80
public function testCustomConfiguration (): void
48
81
{
49
82
$ configuration = new Configuration ();
@@ -56,8 +89,7 @@ public function testCustomConfiguration(): void
56
89
new ExistingConnection ($ conn )
57
90
);
58
91
59
- $ command = new class ($ dependencyFactory ) extends DoctrineCommand
60
- {
92
+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
61
93
protected function execute (InputInterface $ input , OutputInterface $ output ): int
62
94
{
63
95
$ migrationDirectories = $ this ->getDependencyFactory ()->getConfiguration ()->getMigrationDirectories ();
@@ -69,16 +101,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
69
101
$ commandTester = new CommandTester ($ command );
70
102
71
103
$ commandTester ->execute (
72
- ['--configuration ' => __DIR__ . '/_files/config.yml ' ],
104
+ ['--configuration ' => __DIR__ . '/_files/config.yml ' ],
73
105
['interactive ' => false ]
74
106
);
75
107
}
76
108
77
109
public function testDependencyFactoryIsSetFirst (): void
78
110
{
79
111
$ dependencyFactory = $ this ->createMock (DependencyFactory::class);
80
- $ command = new class ($ dependencyFactory ) extends DoctrineCommand
81
- {
112
+ $ command = new class ($ dependencyFactory ) extends DoctrineCommand {
82
113
protected function configure (): void
83
114
{
84
115
$ this ->getDependencyFactory ();
0 commit comments