Skip to content

Commit 373d56f

Browse files
committed
Add test case that verifies execute twice exception.
1 parent 238c78e commit 373d56f

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

tests/Doctrine/Migrations/Tests/Tools/Console/Command/DoctrineCommandTest.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
namespace Doctrine\Migrations\Tests\Tools\Console\Command;
66

77
use Doctrine\Migrations\Configuration\Configuration;
8+
use Doctrine\Migrations\Configuration\Connection\ConnectionLoader;
89
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
10+
use Doctrine\Migrations\Configuration\Migration\ConfigurationLoader;
911
use Doctrine\Migrations\Configuration\Migration\ExistingConfiguration;
1012
use Doctrine\Migrations\DependencyFactory;
1113
use Doctrine\Migrations\Tests\MigrationTestCase;
1214
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand;
1315
use Symfony\Component\Console\Input\InputInterface;
1416
use Symfony\Component\Console\Output\OutputInterface;
1517
use Symfony\Component\Console\Tester\CommandTester;
16-
1718
use function sys_get_temp_dir;
1819

1920
class 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();
@@ -69,16 +101,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
69101
$commandTester = new CommandTester($command);
70102

71103
$commandTester->execute(
72-
['--configuration' => __DIR__ . '/_files/config.yml'],
104+
['--configuration' => __DIR__.'/_files/config.yml'],
73105
['interactive' => false]
74106
);
75107
}
76108

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

Comments
 (0)