Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically run console commands without asking for confirmation in non-interactive mode. #88

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading