Skip to content

Commit 0f2b435

Browse files
[Console] Improve code coverage
1 parent 194dcf3 commit 0f2b435

24 files changed

+450
-4
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,13 @@ public function all($namespace = null)
594594
* @param array $names An array of names
595595
*
596596
* @return array An array of abbreviations
597+
*
598+
* @deprecated since version 3.2, to be removed in 4.0.
597599
*/
598600
public static function getAbbreviations($names)
599601
{
602+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
603+
600604
$abbrevs = array();
601605
foreach ($names as $name) {
602606
for ($len = strlen($name); $len > 0; --$len) {

src/Symfony/Component/Console/Command/Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ public function getSynopsis($short = false)
572572
* Add a command usage example.
573573
*
574574
* @param string $usage The usage, it'll be prefixed with the command name
575+
*
576+
* @return Command
575577
*/
576578
public function addUsage($usage)
577579
{

src/Symfony/Component/Console/Helper/TableStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TableStyle
4242
public function setPaddingChar($paddingChar)
4343
{
4444
if (!$paddingChar) {
45-
throw new LogicException('The padding char must not be empty');
45+
throw new LogicException('The padding char must not be empty.');
4646
}
4747

4848
$this->paddingChar = $paddingChar;

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Console\Tests\Command;
1313

1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1516
use Symfony\Component\Console\Helper\FormatterHelper;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\Console\Input\InputDefinition;
@@ -156,6 +157,28 @@ public function testGetSetAliases()
156157
$this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases');
157158
}
158159

160+
/**
161+
* @expectedException InvalidArgumentException
162+
* @expectedExceptionMessage $aliases must be an array or an instance of \Traversable
163+
*/
164+
public function testSetAliasesThrowsInvalidArgumentException()
165+
{
166+
$command = new \TestCommand();
167+
168+
$command->setAliases('foo');
169+
}
170+
171+
public function testAddUsage()
172+
{
173+
$command = new \TestCommand();
174+
175+
$command
176+
->addUsage('foo')
177+
->addUsage('bar');
178+
179+
$this->assertSame(array('namespace:name foo', 'namespace:name bar'), $command->getUsages());
180+
}
181+
159182
public function testGetSynopsis()
160183
{
161184
$command = new \TestCommand();

src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public function testDescribeInputDefinition(InputDefinition $definition, $expect
3838
$this->assertDescription($expectedDescription, $definition);
3939
}
4040

41+
/**
42+
* @expectedException Symfony\Component\Console\Exception\InvalidArgumentException
43+
* @expectedExceptionMessage Object of type "stdClass" is not describable.
44+
*/
45+
public function testDescribeCommandInvalidObjects()
46+
{
47+
$this->assertDescription(null, new \stdClass());
48+
}
49+
4150
/** @dataProvider getDescribeCommandTestData */
4251
public function testDescribeCommand(Command $command, $expectedDescription)
4352
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Style\SymfonyStyle;
6+
7+
// ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output = new SymfonyStyle($input, $output);
10+
$output->section('Lorem ipsum dolor sit amet');
11+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Exception\RuntimeException;
4+
use Symfony\Component\Console\Input\InputInterface;
5+
use Symfony\Component\Console\Output\OutputInterface;
6+
use Symfony\Component\Console\Style\SymfonyStyle;
7+
8+
// ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment
9+
return function (InputInterface $input, OutputInterface $output) {
10+
$output = new SymfonyStyle($input, $output);
11+
12+
try {
13+
$output->progressFinish();
14+
} catch (RuntimeException $e) {
15+
$output->writeln('OK');
16+
17+
return;
18+
}
19+
20+
$output->writeln('KO');
21+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Lorem ipsum dolor sit amet
3+
--------------------------
4+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0/10 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
2+
4/10 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░] 40%
3+
10/10 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
4+

0 commit comments

Comments
 (0)