Merge branch '2.7' into 2.8

* 2.7:
  undefined offset fix (#19406)
  [EventDispatcher] Removed unused variable
This commit is contained in:
Fabien Potencier 2016-07-28 12:56:28 -04:00
commit 77b5fc4c4b
3 changed files with 37 additions and 11 deletions

View File

@ -108,11 +108,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));
}
/**
@ -124,13 +124,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;
}
@ -660,4 +654,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

@ -631,6 +631,25 @@ TABLE;
$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);

View File

@ -142,7 +142,7 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testLegacyDispatch()
{
$event = new Event();
$return = $this->dispatcher->dispatch(self::preFoo, $event);
$this->dispatcher->dispatch(self::preFoo, $event);
$this->assertEquals('pre.foo', $event->getName());
}