Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
* 3.0:
  The exception should be thrown if an object doesn't implement Traversable AND doesn't implement Countable, not when it doesn't implement Traversable but DOES implement Countable
  [Form] fix violation mapper tests
  [HttpKernel] Prevent a fatal error when DebugHandlersListener is used with a kernel with no terminateWithException() method
  don't rely on deprecated YAML parser feature
  • Loading branch information
fabpot committed Feb 17, 2016
2 parents 6e0d085 + 0923bc8 commit 1f80683
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Question/Question.php
Expand Up @@ -143,7 +143,7 @@ public function setAutocompleterValues($values)
}

if (null !== $values && !is_array($values)) {
if (!$values instanceof \Traversable || $values instanceof \Countable) {
if (!$values instanceof \Traversable || !$values instanceof \Countable) {
throw new InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
}
}
Expand Down
Expand Up @@ -28,14 +28,14 @@ public function testDump()
{
$dumper = new YamlDumper($container = new ContainerBuilder());

$this->assertEqualYamlStructure(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
$this->assertEqualYamlStructure(file_get_contents(self::$fixturesPath.'/yaml/services1.yml'), $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
}

public function testAddParameters()
{
$container = include self::$fixturesPath.'/containers/container8.php';
$dumper = new YamlDumper($container);
$this->assertEqualYamlStructure(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
$this->assertEqualYamlStructure(file_get_contents(self::$fixturesPath.'/yaml/services8.yml'), $dumper->dump(), '->dump() dumps parameters');
}

public function testAddService()
Expand Down
Expand Up @@ -1552,12 +1552,14 @@ public function testBacktrackIfSeveralSubFormsWithSamePropertyPath()
$parent->add($child2);
$child2->add($grandChild);

$parent->submit(array());

$this->mapper->mapViolation($violation, $parent);

// The error occurred on the child of the second form with the same path
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
$this->assertCount(0, $child1->getErrors(), $child1->getName().' should not have an error, but has one');
$this->assertCount(0, $child2->getErrors(), $child2->getName().' should not have an error, but has one');
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChild->getName().' should have an error, but has none');
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChild->getName().' should have an error, but has none');
}
}
Expand Up @@ -93,7 +93,9 @@ public function configure(Event $event = null)
}
if (!$this->exceptionHandler) {
if ($event instanceof KernelEvent) {
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
if (method_exists($event->getKernel(), 'terminateWithException')) {
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
}
} elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
$output = $event->getOutput();
if ($output instanceof ConsoleOutputInterface) {
Expand Down
Expand Up @@ -21,7 +21,10 @@
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -62,6 +65,31 @@ public function testConfigure()
$this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
}

public function testConfigureForHttpKernelWithNoTerminateWithException()
{
$listener = new DebugHandlersListener(null);
$eHandler = new ErrorHandler();
$event = new KernelEvent(
$this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
Request::create('/'),
HttpKernelInterface::MASTER_REQUEST
);

$exception = null;
$h = set_exception_handler(array($eHandler, 'handleException'));
try {
$listener->configure($event);
} catch (\Exception $exception) {
}
restore_exception_handler();

if (null !== $exception) {
throw $exception;
}

$this->assertNull($h);
}

public function testConsoleEvent()
{
$dispatcher = new EventDispatcher();
Expand Down

0 comments on commit 1f80683

Please sign in to comment.