bug #19470 undefined offset fix (#19406) (ReenExe)

This PR was squashed before being merged into the 2.7 branch (closes #19470).

Discussion
----------

undefined offset fix (#19406)

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

9813888 undefined offset fix (#19406)
This commit is contained in:
Fabien Potencier 2016-07-28 12:53:57 -04:00
commit 382ad65372
2 changed files with 36 additions and 10 deletions

View File

@ -101,11 +101,11 @@ class Table
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));
}
/**
@ -117,13 +117,7 @@ class Table
*/
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;
}
@ -611,4 +605,17 @@ class Table
'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));
}
}

View File

@ -577,6 +577,25 @@ TABLE;
$this->assertEquals($table, $table->addRow(new TableSeparator()), 'fluent interface on addRow() with a single TableSeparator() works');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Style "absent" is not defined.
*/
public function testIsNotDefinedStyleException()
{
$table = new Table($this->getOutputStream());
$table->setStyle('absent');
}
/**
* @expectedException \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);