diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 7f2dd1b2380a8..1434562dfea69 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -115,11 +115,11 @@ public static function getStyleDefinition($name) self::$styles = self::initStyles(); } - if (!self::$styles[$name]) { - throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); + if (isset(self::$styles[$name])) { + return self::$styles[$name]; } - return self::$styles[$name]; + throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); } /** @@ -131,13 +131,7 @@ public static function getStyleDefinition($name) */ public function setStyle($name) { - if ($name instanceof TableStyle) { - $this->style = $name; - } elseif (isset(self::$styles[$name])) { - $this->style = self::$styles[$name]; - } else { - throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); - } + $this->style = $this->resolveStyle($name); return $this; } @@ -164,13 +158,7 @@ public function setColumnStyle($columnIndex, $name) { $columnIndex = intval($columnIndex); - if ($name instanceof TableStyle) { - $this->columnStyles[$columnIndex] = $name; - } elseif (isset(self::$styles[$name])) { - $this->columnStyles[$columnIndex] = self::$styles[$name]; - } else { - throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); - } + $this->columnStyles[$columnIndex] = $this->resolveStyle($name); return $this; } @@ -701,4 +689,17 @@ private static function initStyles() 'symfony-style-guide' => $styleGuide, ); } + + private function resolveStyle($name) + { + if ($name instanceof TableStyle) { + return $name; + } + + if (isset(self::$styles[$name])) { + return self::$styles[$name]; + } + + throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); + } } diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index d1991c50ec549..9eb34543772a8 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -694,6 +694,25 @@ public function testColumnWiths() $this->assertEquals($expected, $this->getOutputContent($output)); } + /** + * @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException + * @expectedExceptionMessage Style "absent" is not defined. + */ + public function testIsNotDefinedStyleException() + { + $table = new Table($this->getOutputStream()); + $table->setStyle('absent'); + } + + /** + * @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException + * @expectedExceptionMessage Style "absent" is not defined. + */ + public function testGetStyleDefinition() + { + Table::getStyleDefinition('absent'); + } + protected function getOutputStream() { return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, false); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy