Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit 8517329

Browse files
author
guillermo.fisher
committed
Added messages for different verbosity levels.
1 parent 2d69659 commit 8517329

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/library/Command/PingCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,31 @@ public function getClient()
3737
return $this->client;
3838
}
3939

40+
/**
41+
* {@inheritdoc}
42+
*/
4043
protected function configure()
4144
{
4245
$this->setName('ping')
4346
->setDescription('Pings the HRPHP website');
4447
}
4548

49+
/**
50+
* {@inheritdoc}
51+
*/
4652
protected function execute(InputInterface $input, OutputInterface $output)
4753
{
4854
$output->writeln(sprintf('<info>%s command</info>', $this->getName()));
4955
$response = $this->getClient()->get(HRPHP_URL);
50-
/*
56+
5157
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
5258
$output->writeln(sprintf('Attempting to hit %s at %s...', HRPHP_URL, date('H:i:s A')));
5359
}
60+
5461
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
5562
$output->writeln(sprintf('Ping being sent from %s...', gethostname()));
5663
}
57-
*/
64+
5865
if ($response->getStatusCode() === 200) {
5966
$output->writeln(sprintf('%s is up!', HRPHP_URL));
6067
}

tests/library/Command/PingCommandTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use GuzzleHttp\Psr7\Response;
1515
use Hrphp\Cli\Command\PingCommand;
1616
use Symfony\Component\Console\Application;
17+
use Symfony\Component\Console\Output\OutputInterface;
1718
use Symfony\Component\Console\Tester\CommandTester;
1819

1920
class PingCommandTest extends \PHPUnit_Framework_TestCase
@@ -34,6 +35,26 @@ public function testPing()
3435
self::assertContains(sprintf('%s is up!', HRPHP_URL), $output);
3536
}
3637

38+
public function testVerbosePing()
39+
{
40+
$commandTester = $this->getCommandTester(
41+
'ping',
42+
[ 'verbosity' => OutputInterface::VERBOSITY_VERBOSE ]
43+
);
44+
$output = $commandTester->getDisplay();
45+
self::assertContains('Attempting to hit', $output);
46+
}
47+
48+
public function testVeryVerbosePing()
49+
{
50+
$commandTester = $this->getCommandTester(
51+
'ping',
52+
[ 'verbosity' => OutputInterface::VERBOSITY_VERY_VERBOSE ]
53+
);
54+
$output = $commandTester->getDisplay();
55+
self::assertContains('Ping being sent from', $output);
56+
}
57+
3758
protected function setUp()
3859
{
3960
$command = new PingCommand($this->getClient());
@@ -58,13 +79,14 @@ protected function getClient()
5879

5980
/**
6081
* @param string $commandName
82+
* @param array $options
6183
* @return CommandTester
6284
*/
63-
protected function getCommandTester($commandName)
85+
protected function getCommandTester($commandName, array $options = [])
6486
{
6587
$command = $this->getApplication()->find($commandName);
6688
$commandTester = new CommandTester($command);
67-
$commandTester->execute(array_merge(array('command' => $commandName)));
89+
$commandTester->execute(['command' => $commandName], $options);
6890
return $commandTester;
6991
}
7092

0 commit comments

Comments
 (0)