Skip to content

Commit

Permalink
Add test case that verifies execute twice exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Aug 24, 2021
1 parent 238c78e commit 4df30e7
Showing 1 changed file with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
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;
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand;
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
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 4df30e7

Please sign in to comment.