From 7720f5c70bc079dac3d86612da98157fbbbc7727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Egyed?= <1ed@mailbox.hu> Date: Mon, 28 Sep 2015 22:51:14 +0200 Subject: [PATCH 1/3] [Console] Fix tests for SymfonyStyle --- .../Style/SymfonyStyle/command/command_0.php | 4 ++-- .../Style/SymfonyStyle/command/command_1.php | 4 ++-- .../Style/SymfonyStyle/command/command_2.php | 4 ++-- .../Style/SymfonyStyle/command/command_3.php | 4 ++-- .../Style/SymfonyStyle/command/command_4.php | 4 ++-- .../Style/SymfonyStyle/command/command_5.php | 4 ++-- .../Style/SymfonyStyle/command/command_6.php | 4 ++-- .../Style/SymfonyStyle/command/command_7.php | 4 ++-- .../Console/Tests/Style/SymfonyStyleTest.php | 18 +++++++++++++++++- 9 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php index 8fe7c07712..996fafb989 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_0.php @@ -2,10 +2,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has single blank line at start when using block element return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->caution('Lorem ipsum dolor sit amet'); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php index e5c700d60e..6634cd5690 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_1.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has single blank line between titles and blocks return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->title('Title'); $output->warning('Lorem ipsum dolor sit amet'); $output->title('Title'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php index 791b626f24..6004e3d6c2 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_2.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has single blank line between blocks return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->warning('Warning'); $output->caution('Caution'); $output->error('Error'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php index 99253a6c08..c7a08f138d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_3.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has single blank line between two titles return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->title('First title'); $output->title('Second title'); }; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php index 0c5d3fb26c..afea70c7aa 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_4.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has single blank line after any text and a title return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->write('Lorem ipsum dolor sit amet'); $output->title('First title'); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php index 4543ad8cd6..ac666ec0ee 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_5.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has proper line ending before outputing a text block like with SymfonyStyle::listing() or SymfonyStyle::text() return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->writeln('Lorem ipsum dolor sit amet'); $output->listing(array( diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php index 8031ec9c30..f1d7990544 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_6.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure has proper blank line after text block when using a block like with SymfonyStyle::success return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->listing(array( 'Lorem ipsum dolor sit amet', diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php index 203eb5b12e..cbfea734b4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_7.php @@ -2,11 +2,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength; //Ensure questions do not output anything when input is non-interactive return function (InputInterface $input, OutputInterface $output) { - $output = new SymfonyStyle($input, $output); + $output = new SymfonyStyleWithForcedLineLength($input, $output); $output->title('Title'); $output->askHidden('Hidden question'); $output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1'); diff --git a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php index 7aa6a3f54c..6bf64129f4 100644 --- a/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php +++ b/src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php @@ -62,7 +62,7 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase $maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3; $this->command->setCode(function (InputInterface $input, OutputInterface $output) use ($word) { - $sfStyle = new SymfonyStyle($input, $output); + $sfStyle = new SymfonyStyleWithForcedLineLength($input, $output); $sfStyle->block($word, 'CUSTOM', 'fg=white;bg=blue', ' § ', false); }); @@ -71,3 +71,19 @@ class SymfonyStyleTest extends PHPUnit_Framework_TestCase $this->assertSame($expectedCount, substr_count($this->tester->getDisplay(true), ' § ')); } } + +/** + * Use this class in tests to force the line length + * and ensure a consistent output for expectations. + */ +class SymfonyStyleWithForcedLineLength extends SymfonyStyle +{ + public function __construct(InputInterface $input, OutputInterface $output) + { + parent::__construct($input, $output); + + $ref = new \ReflectionProperty(get_parent_class($this), 'lineLength'); + $ref->setAccessible(true); + $ref->setValue($this, 120); + } +} From f15d179fbd447b50d646aad2ba18885730058ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aar=C3=B3n=20Nieves=20Fern=C3=A1ndez?= Date: Tue, 29 Sep 2015 18:57:23 +0200 Subject: [PATCH 2/3] The 'config' variable is already used as an array expression less... --- src/Symfony/Component/Routing/Loader/YamlFileLoader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index 32c3bde18d..c069385da3 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -58,7 +58,7 @@ class YamlFileLoader extends FileLoader } try { - $config = $this->yamlParser->parse(file_get_contents($path)); + $parsedConfig = $this->yamlParser->parse(file_get_contents($path)); } catch (ParseException $e) { throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e); } @@ -67,16 +67,16 @@ class YamlFileLoader extends FileLoader $collection->addResource(new FileResource($path)); // empty file - if (null === $config) { + if (null === $parsedConfig) { return $collection; } // not an array - if (!is_array($config)) { + if (!is_array($parsedConfig)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path)); } - foreach ($config as $name => $config) { + foreach ($parsedConfig as $name => $config) { if (isset($config['pattern'])) { if (isset($config['path'])) { throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path)); From d94dd1679a2410d59b7bea4c847544a55c92bcc6 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 1 Oct 2015 16:53:49 +0200 Subject: [PATCH 3/3] [TwigBundle] fix useless and failing test --- .../Controller/ExceptionControllerTest.php | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php deleted file mode 100644 index 20646f74aa..0000000000 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Controller; - -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Bundle\TwigBundle\Controller\ExceptionController; -use Symfony\Component\HttpFoundation\Request; - -class ExceptionControllerTest extends TestCase -{ - public function testOnlyClearOwnOutputBuffers() - { - $flatten = $this->getMock('Symfony\Component\Debug\Exception\FlattenException'); - $flatten - ->expects($this->once()) - ->method('getStatusCode') - ->will($this->returnValue(404)); - $twig = $this->getMockBuilder('\Twig_Environment') - ->disableOriginalConstructor() - ->getMock(); - $twig - ->expects($this->any()) - ->method('render') - ->will($this->returnValue($this->getMock('Symfony\Component\HttpFoundation\Response'))); - $twig - ->expects($this->any()) - ->method('getLoader') - ->will($this->returnValue($this->getMock('\Twig_LoaderInterface'))); - $request = Request::create('/'); - $request->headers->set('X-Php-Ob-Level', 1); - - $controller = new ExceptionController($twig, false); - $controller->showAction($request, $flatten); - } -}