Skip to content

Commit

Permalink
Automatically run console commands without asking for confirmation in…
Browse files Browse the repository at this point in the history
… non-interactive mode.
  • Loading branch information
butschster committed Jan 8, 2024
1 parent 09cac59 commit a048c3e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/Migrate/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function verifyEnvironment(string $message = 'Confirmation is required

$this->error($message);

if (!$this->askConfirmation()) {
if (!$this->askConfirmation() || !$this->isInteractive()) {
$this->comment('Cancelling operation...');

return false;
Expand Down
19 changes: 16 additions & 3 deletions tests/src/Console/Command/CycleOrm/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ protected function setUp(): void
public function testMigrate(): void
{
// Create migration
$this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [], self::USER_MIGRATION);
$this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [
'--no-interaction' => true,
], self::USER_MIGRATION);

$this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [], [
$this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [
'--no-interaction' => true,
], [
'Outstanding migrations found',
'Detecting schema changes...',
'Please run `migrate` first.',
]);

$this->assertConsoleCommandOutputContainsStrings('migrate', [
'was successfully executed.',
]);

$this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [
'--no-interaction' => true,
], [
'Detecting schema changes...',
'no database changes has been detected',
]);
}
Expand Down
8 changes: 5 additions & 3 deletions tests/src/Console/Command/CycleOrm/SyncCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ final class SyncCommandTest extends ConsoleTest
#[Env('SAFE_MIGRATIONS', 'false')]
public function testUnsafeSync(): void
{
$output = $this->runCommand('cycle:sync');
$output = $this->runCommand('cycle:sync', [
'--no-interaction' => true,
]);

$this->assertStringContainsString('This operation is not recommended for production environment.', $output);
$this->assertStringContainsString('Cancelling operation...', $output);
}
Expand Down Expand Up @@ -58,8 +61,7 @@ public function testSchemaDefaultsShouldBePassedToCompiler(): void
{
$config['schema']['defaults'][SchemaInterface::TYPECAST_HANDLER][] = 'foo';

$memory = new class implements MemoryInterface
{
$memory = new class implements MemoryInterface {
private mixed $data;

public function loadData(string $section): mixed
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Console/Command/Migrate/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ public function tesForceMigrate(): void
public function testUnsafeMigrate(): void
{
$db = $this->initMigrations();
$output = $this->runCommand('migrate');
$output = $this->runCommand('migrate', [
'--no-interaction' => true,
]);
$this->assertStringContainsString('Confirmation is required to run migrations!', $output);
$this->assertStringContainsString('Cancelling operation...', $output);
$this->assertCount(1, $db->getTables());
}

/**
* @return void
* @throws \Throwable
*/
public function initMigrations(): DatabaseInterface
Expand Down

0 comments on commit a048c3e

Please sign in to comment.