Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 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('with-exit-status')) && 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 @@ -43,6 +43,7 @@ protected function configure()
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'),
new InputOption('with-exit-status', '', InputOption::VALUE_NONE, 'Exit with status 1 if there were any changes made, 0 otherwise'),
Comment thread
taylorotwell marked this conversation as resolved.
Outdated
]
);
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Feature/WithExitStatusTest.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',
'--with-exit-status' => 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'),
'--with-exit-status' => true,
'--test' => false,
]);

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