Skip to content

Commit c3855d3

Browse files
feat: Add a --with-exit-status flag (#270)
* feat: Add a --with-exit-status flag * feat: Add a --with-exit-status flag * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent a977fd8 commit c3855d3

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

app/Actions/ElaborateSummary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function execute($totalFiles, $changes)
5151
$this->summaryOutput->handle($summary, $totalFiles);
5252
}
5353

54-
$failure = ($summary->isDryRun() && count($changes) > 0)
54+
$failure = (($summary->isDryRun() || $this->input->getOption('repair')) && count($changes) > 0)
5555
|| count($this->errors->getInvalidErrors()) > 0
5656
|| count($this->errors->getExceptionErrors()) > 0
5757
|| count($this->errors->getLintErrors()) > 0;

app/Commands/DefaultCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected function configure()
4040
new InputOption('preset', '', InputOption::VALUE_REQUIRED, 'The preset that should be used'),
4141
new InputOption('test', '', InputOption::VALUE_NONE, 'Test for code style errors without fixing them'),
4242
new InputOption('bail', '', InputOption::VALUE_NONE, 'Test for code style errors without fixing them and stop on first error'),
43+
new InputOption('repair', '', InputOption::VALUE_NONE, 'Fix code style errors but exit with status 1 if there were any changes made'),
4344
new InputOption('dirty', '', InputOption::VALUE_NONE, 'Only fix files that have uncommitted changes'),
4445
new InputOption('format', '', InputOption::VALUE_REQUIRED, 'The output format that should be used'),
4546
new InputOption('cache-file', '', InputArgument::OPTIONAL, 'The path to the cache file'),

tests/Feature/RepairTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
beforeEach(function () {
4+
$this->contents = file_get_contents(base_path('tests/Fixtures/with-fixable-issues/file.php'));
5+
});
6+
7+
afterEach(function () {
8+
file_put_contents(base_path('tests/Fixtures/with-fixable-issues/file.php'), $this->contents);
9+
});
10+
11+
it('exits with status 1 with fixes', function () {
12+
[$statusCode, $output] = run('default', [
13+
'path' => base_path('tests/Fixtures/with-fixable-issues'),
14+
'--preset' => 'psr12',
15+
'--repair' => true,
16+
'--test' => false,
17+
]);
18+
19+
expect($statusCode)->toBe(1)
20+
->and($output)
21+
->toContain('FIXED');
22+
});
23+
24+
it('exits with status 0 without fixes', function () {
25+
[$statusCode, $output] = run('default', [
26+
'path' => base_path('tests/Fixtures/without-issues'),
27+
'--repair' => true,
28+
'--test' => false,
29+
]);
30+
31+
expect($statusCode)->toBe(0)
32+
->and($output)
33+
->toContain('PASS');
34+
});

0 commit comments

Comments
 (0)