Skip to content

Commit b122d36

Browse files
[Console] Improve code coverage
1 parent 0fc2b62 commit b122d36

25 files changed

+462
-4
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ public function all($namespace = null)
594594
*/
595595
public static function getAbbreviations($names)
596596
{
597+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
598+
597599
$abbrevs = array();
598600
foreach ($names as $name) {
599601
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/ApplicationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static function setUpBeforeClass()
4343
require_once self::$fixturesPath.'/Foo3Command.php';
4444
require_once self::$fixturesPath.'/Foo4Command.php';
4545
require_once self::$fixturesPath.'/Foo5Command.php';
46+
require_once self::$fixturesPath.'/DisabledCommand.php';
4647
require_once self::$fixturesPath.'/FoobarCommand.php';
4748
require_once self::$fixturesPath.'/BarBucCommand.php';
4849
require_once self::$fixturesPath.'/FooSubnamespaced1Command.php';
@@ -1115,6 +1116,13 @@ public function testCanCheckIfTerminalIsInteractive()
11151116
$inputStream = $tester->getInput()->getStream();
11161117
$this->assertEquals($tester->getInput()->isInteractive(), @posix_isatty($inputStream));
11171118
}
1119+
1120+
public function testAddApplicationReturnsNullWhenCommandIsNotEnabled()
1121+
{
1122+
$application = new CustomDefaultCommandApplication();
1123+
1124+
$this->assertNull($application->add(new \DisabledCommand()));
1125+
}
11181126
}
11191127

11201128
class CustomApplication extends Application

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
use Symfony\Component\Console\Command\Command;
5+
6+
class DisabledCommand extends Command
7+
{
8+
protected function configure()
9+
{
10+
$this->setName('disabled');
11+
}
12+
13+
public function isEnabled()
14+
{
15+
return false;
16+
}
17+
}
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
11+
$output->progressStart(10);
12+
$output->progressAdvance(4);
13+
$output->progressFinish();
14+
};
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+
};

0 commit comments

Comments
 (0)