|
18 | 18 | use Doctrine\Migrations\Version\Version; |
19 | 19 | use PHPUnit\Framework\MockObject\MockObject; |
20 | 20 | use PHPUnit\Framework\TestCase; |
| 21 | +use Symfony\Component\Console\Helper\HelperSet; |
| 22 | +use Symfony\Component\Console\Helper\QuestionHelper; |
21 | 23 | use Symfony\Component\Console\Tester\CommandTester; |
22 | 24 |
|
23 | 25 | use function array_map; |
24 | 26 | use function explode; |
| 27 | +use function sprintf; |
25 | 28 | use function sys_get_temp_dir; |
26 | 29 | use function trim; |
27 | 30 |
|
@@ -139,6 +142,44 @@ public function testExecutedUnavailableMigrationsCancel(): void |
139 | 142 | self::assertSame(3, $statusCode); |
140 | 143 | } |
141 | 144 |
|
| 145 | + /** @return array<string, array{int|null, string}> */ |
| 146 | + public static function getSelectedNamespace(): array |
| 147 | + { |
| 148 | + return [ |
| 149 | + 'no' => [null, 'FooNs'], |
| 150 | + 'first' => [0, 'FooNs'], |
| 151 | + 'two' => [1, 'FooNs2'], |
| 152 | + ]; |
| 153 | + } |
| 154 | + |
| 155 | + /** @dataProvider getSelectedNamespace */ |
| 156 | + public function testExecuteWithMultipleDirectories(int|null $input, string $namespace): void |
| 157 | + { |
| 158 | + $this->migrationStatusCalculator |
| 159 | + ->method('getNewMigrations') |
| 160 | + ->willReturn(new AvailableMigrationsList([])); |
| 161 | + |
| 162 | + $this->migrationStatusCalculator |
| 163 | + ->method('getExecutedUnavailableMigrations') |
| 164 | + ->willReturn(new ExecutedMigrationsList([])); |
| 165 | + |
| 166 | + $this->configuration->addMigrationsDirectory('FooNs2', sys_get_temp_dir()); |
| 167 | + |
| 168 | + $this->diffCommand->setHelperSet(new HelperSet(['question' => new QuestionHelper()])); |
| 169 | + |
| 170 | + $this->migrationDiffGenerator->expects(self::once())->method('generate'); |
| 171 | + |
| 172 | + $this->diffCommandTester->setInputs([$input]); |
| 173 | + $this->diffCommandTester->execute([]); |
| 174 | + |
| 175 | + $output = $this->diffCommandTester->getDisplay(true); |
| 176 | + |
| 177 | + self::assertStringContainsString('Please choose a namespace (defaults to the first one)', $output); |
| 178 | + self::assertStringContainsString('[0] FooNs', $output); |
| 179 | + self::assertStringContainsString('[1] FooNs2', $output); |
| 180 | + self::assertStringContainsString(sprintf('You have selected the "%s" namespace', $namespace), $output); |
| 181 | + } |
| 182 | + |
142 | 183 | protected function setUp(): void |
143 | 184 | { |
144 | 185 | $this->migrationDiffGenerator = $this->createMock(DiffGenerator::class); |
|
0 commit comments