-
-
Notifications
You must be signed in to change notification settings - Fork 388
/
DoctrineCommandTest.php
90 lines (74 loc) · 2.92 KB
/
DoctrineCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace Doctrine\Migrations\Tests\Tools\Console\Command;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
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
{
public function testCommandFreezes(): void
{
$dependencyFactory = $this->getMockBuilder(DependencyFactory::class)
->disableOriginalConstructor()
->onlyMethods(['freeze'])
->getMock();
$dependencyFactory
->expects(self::once())
->method('freeze');
$command = new class ($dependencyFactory) extends DoctrineCommand
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
return 0;
}
};
$commandTester = new CommandTester($command);
$commandTester->execute(
[],
['interactive' => false]
);
}
public function testCustomConfiguration(): void
{
$configuration = new Configuration();
$configuration->addMigrationsDirectory('DoctrineMigrations', sys_get_temp_dir());
$conn = $this->getSqliteConnection();
$dependencyFactory = DependencyFactory::fromConnection(
new ExistingConfiguration($configuration),
new ExistingConnection($conn)
);
$command = new class ($dependencyFactory) extends DoctrineCommand
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$migrationDirectories = $this->getDependencyFactory()->getConfiguration()->getMigrationDirectories();
DoctrineCommandTest::assertSame(['DoctrineMigrationsTest' => 'bar'], $migrationDirectories);
return 0;
}
};
$commandTester = new CommandTester($command);
$commandTester->execute(
['--configuration' => __DIR__ . '/_files/config.yml'],
['interactive' => false]
);
}
public function testDependencyFactoryIsSetFirst(): void
{
$dependencyFactory = $this->createMock(DependencyFactory::class);
$command = new class ($dependencyFactory) extends DoctrineCommand
{
protected function configure(): void
{
$this->getDependencyFactory();
}
};
self::assertFalse($command->getDefinition()->hasOption('db-configuration'));
}
}