-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Console] Improve code coverage #19328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. namespace is missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No namespaces were introduced for all |
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
// ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment | ||
return function (InputInterface $input, OutputInterface $output) { | ||
$output = new SymfonyStyle($input, $output); | ||
$output->section('Lorem ipsum dolor sit amet'); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Symfony\Component\Console\Exception\RuntimeException; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
// ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment | ||
return function (InputInterface $input, OutputInterface $output) { | ||
$output = new SymfonyStyle($input, $output); | ||
|
||
try { | ||
$output->progressFinish(); | ||
} catch (RuntimeException $e) { | ||
$output->writeln('OK'); | ||
|
||
return; | ||
} | ||
|
||
$output->writeln('KO'); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
Lorem ipsum dolor sit amet | ||
-------------------------- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OK |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0/10 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% | ||
4/10 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░] 40% | ||
10/10 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0/10 [>---------------------------] 0% | ||
4/10 [===========>----------------] 40% | ||
10/10 [============================] 100% | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Tests\Helper; | ||
|
||
use Symfony\Component\Console\Helper\DescriptorHelper; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DescriptorHelperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException | ||
* @expectedExceptionMessage Unsupported format "invalid". | ||
*/ | ||
public function testDescribeWithInvalidFormat() | ||
{ | ||
$descriptor = new DescriptorHelper(); | ||
$descriptor->describe($this->getMock(OutputInterface::class), null, array('format' => 'invalid')); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$descriptor = new DescriptorHelper(); | ||
|
||
$this->assertSame('descriptor', $descriptor->getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How it possible to assertSame There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the name will always be set, so the test is valid to make sure of that to prevent regression |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,21 @@ | |
|
||
class HelperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function formatMemoryProvider() | ||
{ | ||
return array( | ||
array(0, '0 B'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this kind of alignment allowed by the CS standards? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/1.11/README.rst) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know there are many implicit rules that aren't yet declared @SpacePossum, that's why I'm asking. The reasons I have in mind are the very same that moved us to unalign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @phansys I formatted the array this way to be consistent with what's already in this file (take a look at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure @geoffrey-brier, thanks for pointing and putting the sight on this. |
||
array(1, '1 B'), | ||
array(1000, '1000 B'), | ||
array(1024, '1 KiB'), | ||
array(1025, '1 KiB'), | ||
array(1048576, '1.0 MiB'), | ||
array(1048577, '1.0 MiB'), | ||
array(1073741824, '1.0 GiB'), | ||
array(1073741825, '1.0 GiB'), | ||
); | ||
} | ||
|
||
public function formatTimeProvider() | ||
{ | ||
return array( | ||
|
@@ -51,4 +66,15 @@ public function testFormatTime($secs, $expectedFormat) | |
{ | ||
$this->assertEquals($expectedFormat, Helper::formatTime($secs)); | ||
} | ||
|
||
/** | ||
* @dataProvider formatMemoryProvider | ||
* | ||
* @param int $bytes | ||
* @param string $expectedFormat | ||
*/ | ||
public function testFormatMemory($bytes, $expectedFormat) | ||
{ | ||
$this->assertEquals($expectedFormat, Helper::formatMemory($bytes)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use Symfony\Component\Console\Helper\SymfonyQuestionHelper; | ||
use Symfony\Component\Console\Output\StreamOutput; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
/** | ||
* @group tty | ||
|
@@ -22,7 +23,7 @@ public function testAskChoice() | |
|
||
$heroes = array('Superman', 'Batman', 'Spiderman'); | ||
|
||
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"); | ||
$inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\ny\n"); | ||
|
||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '2'); | ||
$question->setMaxAttempts(1); | ||
|
@@ -71,6 +72,34 @@ public function testAskChoice() | |
|
||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question)); | ||
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output); | ||
|
||
$question = new ConfirmationQuestion('Do you like superheroes ?'); | ||
$this->assertTrue($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question)); | ||
$this->assertOutputContains('Do you like superheroes ? (yes/no)', $output); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Console\Exception\LogicException | ||
* @expectedExceptionMessage A value is required. | ||
*/ | ||
public function testAskWithInvalidValidatorThrowsLogicException() | ||
{ | ||
$questionHelper = new SymfonyQuestionHelper(); | ||
|
||
$helperSet = new HelperSet(array(new FormatterHelper())); | ||
$questionHelper->setHelperSet($helperSet); | ||
|
||
$heroes = array('Superman', 'Batman', 'Spiderman'); | ||
|
||
$inputStream = $this->getInputStream("\n1\n"); | ||
|
||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '2'); | ||
$question->setMaxAttempts(1); | ||
$question->setValidator(function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use function. You can write direct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong. The validator is a callable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
return ''; | ||
}); | ||
|
||
$questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question); | ||
} | ||
|
||
protected function getInputStream($input) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Tests\Helper; | ||
|
||
use Symfony\Component\Console\Helper\TableCell; | ||
|
||
class TableCellTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException | ||
* @expectedExceptionMessage The TableCell does not support the following options: 'invalid'. | ||
*/ | ||
public function testConstructorWithInvalidOptions() | ||
{ | ||
new TableCell('', array('invalid' => 'invalid')); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are using
@return self
everywhere else. Not sure which one is the right one, but I didn't find any occurrence of@return $this
in Symfony codebase.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is because of my suggestion I'm afraid
#19328 (comment)
sorry if misleading the pr!