Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa committed Mar 3, 2022
1 parent 59d55f3 commit a31bad5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Command/AssessComplexityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$file = (string) $input->getArgument('file');
$contents = \file_get_contents($file);
$contents = \is_file($file)
? \file_get_contents($file)
: false;

if (false === $contents) {
$output->writeln('0');
Expand Down
13 changes: 12 additions & 1 deletion tests/Integration/Command/AssessComplexityCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function tearDown()
}

/** @test */
public function it_returns_the_cyclomatic_complexity()
public function it_returns_the_cyclomatic_complexity_greater_than_zero()
{
$exitCode = $this->commandTester->execute(['file' => __FILE__]);
$result = \rtrim($this->commandTester->getDisplay());
Expand All @@ -37,4 +37,15 @@ public function it_returns_the_cyclomatic_complexity()
$this->assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
$this->assertGreaterThan(0, (int) $result);
}

/** @test */
public function it_returns_zero_for_non_existing_file()
{
$exitCode = $this->commandTester->execute(['file' => 'nonexisting-file.php']);
$result = \rtrim($this->commandTester->getDisplay());

$this->assertEquals(0, $exitCode);
$this->assertTrue(\ctype_digit($result), 'The result of the command must be an integer');
$this->assertEquals(0, (int) $result);
}
}

0 comments on commit a31bad5

Please sign in to comment.