Skip to content
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ Gitlab format:
php vendor/bin/phpfci inspect coverage.xml reports/gitlab.errors.json --report=gitlab
```

## Command line arguments

| Option | Values | Description |
|---------------------------|------------------------|-------------------------------------------------------|
| `argument 1` | `inspect`, `baseline` | the command to execute. |
| `argument 2` | `coverage.xml` | the phpunit clover coverage input file. |
| `argument 3` | `phpfci.xml` | the output file to write to. |
| `--report=<report-style>` | `gitlab`, `checkstyle` | the output format. If absent will default to console. |
| `--config=<path-to-file>` | `phpfci.xml` | the path to the config file. |
| `--exit-code-on-failure` | - | Set exit code to `1` when there are failures. |

## About us

At 123inkt (Part of Digital Revolution B.V.), every day more than 30 developers are working on improving our internal ERP and our several shops. Do you want to join us? [We are looking for developers](https://www.123inkt.nl/page/werken_ict.html).
8 changes: 7 additions & 1 deletion src/Command/InspectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected function configure(): void
->addArgument('output', InputOption::VALUE_REQUIRED, 'Path to write inspections report file to')
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to configuration file. Optional')
->addOption('baseDir', '', InputOption::VALUE_REQUIRED, 'Base directory from where to determine the relative config paths')
->addOption('report', '', InputOption::VALUE_REQUIRED, 'output format, either checkstyle or gitlab', 'checkstyle');
->addOption('report', '', InputOption::VALUE_REQUIRED, 'output format, either checkstyle or gitlab', 'checkstyle')
->addOption('exit-code-on-failure', '', InputOption::VALUE_NONE, 'If failures, exit with failure exit code');
}

/**
Expand Down Expand Up @@ -78,6 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new InvalidArgumentException('Invalid report argument: ' . $input->getOption('report'));
}

// raise exit code on failure
if (count($failures) > 0 && $input->getOption('exit-code-on-failure') !== false) {
return Command::FAILURE;
}

return Command::SUCCESS;
}
}
1 change: 0 additions & 1 deletion src/Renderer/CheckStyleRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use DigitalRevolution\CodeCoverageInspection\Model\Config\InspectionConfig;
use DigitalRevolution\CodeCoverageInspection\Model\Metric\Failure;
use RuntimeException;
use XMLWriter;

class CheckStyleRenderer
Expand Down
18 changes: 13 additions & 5 deletions tests/Functional/Command/InspectCommand/InspectCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

class InspectCommandTest extends TestCase
{
/** @var vfsStreamDirectory */
private $fileSystem;
private vfsStreamDirectory $fileSystem;

protected function setUp(): void
{
Expand All @@ -26,9 +25,10 @@ protected function setUp(): void

/**
* @coversNothing
* @dataProvider dataProvider
* @throws Exception
*/
public function testInspectCommand(): void
public function testInspectCommand(array $flags, int $exitStatus): void
{
// prepare data files
$configPath = __DIR__ . '/Data/phpfci.xml';
Expand All @@ -39,11 +39,11 @@ public function testInspectCommand(): void

// prepare command
$command = new InspectCommand();
$input = new ArgvInput(['phpfci', '--config', $configPath, '--baseDir', $baseDir, $coveragePath, $output]);
$input = new ArgvInput(array_merge(['phpfci', '--config', $configPath, '--baseDir', $baseDir, $coveragePath, $output], $flags));
$output = new ConsoleOutput();

// run test case
static::assertSame(Command::SUCCESS, $command->run($input, $output));
static::assertSame($exitStatus, $command->run($input, $output));
static::assertTrue($this->fileSystem->hasChild('checkstyle.xml'));

// check output
Expand All @@ -53,4 +53,12 @@ public function testInspectCommand(): void

static::assertSame($expected, $result);
}

public function dataProvider(): array
{
return [
'standard exit code' => [[], Command::SUCCESS],
'exit code on failure' => [['--exit-code-on-failure'], Command::FAILURE]
];
}
}