Skip to content

Commit

Permalink
Reach 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Apr 5, 2019
1 parent 1466389 commit f94152b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Unit/AbstractTerminableCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ protected function commandBody(InputInterface $input, OutputInterface $output):
{
$this->setSleepDuration(100);

$output->writeln('Testing getSleepDuration: ' . $this->getSleepDuration());

return 0;
}
};
Expand All @@ -38,6 +40,8 @@ protected function commandBody(InputInterface $input, OutputInterface $output):
$output = $this->prophesize(OutputInterface::class);
$output->writeln(Argument::containingString('Starting'), OutputInterface::VERBOSITY_VERBOSE)
->shouldBeCalledTimes(1);
$output->writeln('Testing getSleepDuration: 100')
->shouldBeCalledTimes(1);
$output->writeln('Slept 100 second(s)', OutputInterface::VERBOSITY_DEBUG)
->shouldBeCalledTimes(1);

Expand Down Expand Up @@ -107,6 +111,33 @@ protected function commandBody(InputInterface $input, OutputInterface $output):
$this->assertSame(143, $exitCode);
}

/**
* @dataProvider signalProvider
*/
public function testReceiveSignalBeforeCommandBody(int $signal): void
{
$stubCommand = new class() extends AbstractTerminableCommand {
protected function commandBody(InputInterface $input, OutputInterface $output): int
{
return 0;
}
};

$input = $this->prophesize(InputInterface::class);
$output = $this->prophesize(OutputInterface::class);
$output->writeln(Argument::containingString('Starting'), OutputInterface::VERBOSITY_VERBOSE)
->shouldBeCalledTimes(1)
->will(function () use ($stubCommand, $signal) {
$stubCommand->handleSignal($signal);
});
$output->writeln('Signal received, skipping execution', OutputInterface::VERBOSITY_NORMAL)
->shouldBeCalledTimes(1);

$exitCode = $stubCommand->run($input->reveal(), $output->reveal());

$this->assertSame(143, $exitCode);
}

public function signalProvider(): array
{
return [
Expand Down

0 comments on commit f94152b

Please sign in to comment.