Skip to content

Commit

Permalink
feat: Add a --with-exit-status flag (#270)
Browse files Browse the repository at this point in the history
* feat: Add a --with-exit-status flag

* feat: Add a --with-exit-status flag

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
dshafik and taylorotwell committed Apr 26, 2024
1 parent a977fd8 commit c3855d3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Actions/ElaborateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function execute($totalFiles, $changes)
$this->summaryOutput->handle($summary, $totalFiles);
}

$failure = ($summary->isDryRun() && count($changes) > 0)
$failure = (($summary->isDryRun() || $this->input->getOption('repair')) && count($changes) > 0)
|| count($this->errors->getInvalidErrors()) > 0
|| count($this->errors->getExceptionErrors()) > 0
|| count($this->errors->getLintErrors()) > 0;
Expand Down
1 change: 1 addition & 0 deletions app/Commands/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function configure()
new InputOption('preset', '', InputOption::VALUE_REQUIRED, 'The preset that should be used'),
new InputOption('test', '', InputOption::VALUE_NONE, 'Test for code style errors without fixing them'),
new InputOption('bail', '', InputOption::VALUE_NONE, 'Test for code style errors without fixing them and stop on first error'),
new InputOption('repair', '', InputOption::VALUE_NONE, 'Fix code style errors but exit with status 1 if there were any changes made'),
new InputOption('dirty', '', InputOption::VALUE_NONE, 'Only fix files that have uncommitted changes'),
new InputOption('format', '', InputOption::VALUE_REQUIRED, 'The output format that should be used'),
new InputOption('cache-file', '', InputArgument::OPTIONAL, 'The path to the cache file'),
Expand Down
34 changes: 34 additions & 0 deletions tests/Feature/RepairTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

beforeEach(function () {
$this->contents = file_get_contents(base_path('tests/Fixtures/with-fixable-issues/file.php'));
});

afterEach(function () {
file_put_contents(base_path('tests/Fixtures/with-fixable-issues/file.php'), $this->contents);
});

it('exits with status 1 with fixes', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/with-fixable-issues'),
'--preset' => 'psr12',
'--repair' => true,
'--test' => false,
]);

expect($statusCode)->toBe(1)
->and($output)
->toContain('FIXED');
});

it('exits with status 0 without fixes', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/without-issues'),
'--repair' => true,
'--test' => false,
]);

expect($statusCode)->toBe(0)
->and($output)
->toContain('PASS');
});

0 comments on commit c3855d3

Please sign in to comment.