26
26
use Doctrine \Migrations \Tests \Helper ;
27
27
use Doctrine \Migrations \Tests \MigrationTestCase ;
28
28
use Doctrine \Migrations \Tools \Console \Command \MigrateCommand ;
29
+ use Doctrine \Migrations \Tools \Console \InvalidAllOrNothingConfiguration ;
29
30
use Doctrine \Migrations \Version \AlphabeticalComparator ;
30
31
use Doctrine \Migrations \Version \ExecutionResult ;
31
32
use Doctrine \Migrations \Version \MigrationFactory ;
@@ -343,11 +344,13 @@ public function testExecuteMigrateDown(): void
343
344
*
344
345
* @dataProvider allOrNothing
345
346
*/
346
- public function testExecuteMigrateAllOrNothing (bool $ default , array $ input , bool $ expected , bool $ expectDeprecation = true ): void
347
+ public function testExecuteMigrateAllOrNothing (bool | null $ default , array $ input , bool $ expected , bool $ expectDeprecation = true ): void
347
348
{
348
349
$ migrator = $ this ->createMock (DbalMigrator::class);
349
350
$ this ->dependencyFactory ->setService (Migrator::class, $ migrator );
350
- $ this ->configuration ->setAllOrNothing ($ default );
351
+ if ($ default !== null ) {
352
+ $ this ->configuration ->setAllOrNothing ($ default );
353
+ }
351
354
352
355
$ migrator ->expects (self ::once ())
353
356
->method ('migrate ' )
@@ -371,7 +374,7 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
371
374
self ::assertSame (0 , $ this ->migrateCommandTester ->getStatusCode ());
372
375
}
373
376
374
- /** @psalm-return Generator<array{0: bool, 1: array<string, bool|int|string|null>, 2: bool, 3?: bool}> */
377
+ /** @psalm-return Generator<array{0: bool|null , 1: array<string, bool|int|string|null>, 2: bool, 3?: bool}> */
375
378
public static function allOrNothing (): Generator
376
379
{
377
380
yield [false , ['--all-or-nothing ' => false ], false ];
@@ -381,14 +384,29 @@ public static function allOrNothing(): Generator
381
384
yield [false , ['--all-or-nothing ' => true ], true ];
382
385
yield [false , ['--all-or-nothing ' => 1 ], true ];
383
386
yield [false , ['--all-or-nothing ' => '1 ' ], true ];
384
- yield [false , ['--all-or-nothing ' => null ], false , false ];
387
+ yield [false , ['--all-or-nothing ' => null ], true , false ];
388
+ yield [true , ['--no-all-or-nothing ' => null ], false , false ];
385
389
386
390
yield [true , ['--all-or-nothing ' => false ], false ];
387
391
yield [true , ['--all-or-nothing ' => 0 ], false ];
388
392
yield [true , ['--all-or-nothing ' => '0 ' ], false ];
389
393
390
394
yield [true , [], true , false ];
391
395
yield [false , [], false , false ];
396
+ yield [null , [], false , false ];
397
+ }
398
+
399
+ public function testThrowsOnContradictoryAllOrNothingOptions (): void
400
+ {
401
+ $ this ->expectException (InvalidAllOrNothingConfiguration::class);
402
+
403
+ $ this ->migrateCommandTester ->execute (
404
+ [
405
+ '--all-or-nothing ' => null ,
406
+ '--no-all-or-nothing ' => null ,
407
+ ],
408
+ ['interactive ' => false ],
409
+ );
392
410
}
393
411
394
412
public function testExecuteMigrateCancelExecutedUnavailableMigrations (): void
0 commit comments