Merge branch '2.7'

* 2.7:
  Add LegacyPdoSessionHandler class
  fix dependency on ExtensionInterface over implementation
  [Console] Remove $this in closure
  [FrameworkBundle] forward error reporting level to insulated Client
  [VarDumper] fix and test PdoCaster
  [Config] fix error handler restoration in test
This commit is contained in:
Fabien Potencier 2014-12-23 18:36:41 +01:00
commit e09e027fc3
7 changed files with 103 additions and 59 deletions

View File

@ -160,9 +160,13 @@ class Client extends BaseClient
$profilerCode = '$kernel->getContainer()->get(\'profiler\')->enable();';
}
$errorReporting = error_reporting();
$code = <<<EOF
<?php
error_reporting($errorReporting);
if ('$autoloader') {
require_once '$autoloader';
}

View File

@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
/**
* A console command for dumping available configuration reference.
@ -73,7 +73,7 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
return $extension;
}
public function validateConfiguration(Extension $extension, $configuration)
public function validateConfiguration(ExtensionInterface $extension, $configuration)
{
if (!$configuration) {
throw new \LogicException(sprintf('The extension with alias "%s" does not have its getConfiguration() method setup', $extension->getAlias()));

View File

@ -163,10 +163,17 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase
$file = __DIR__.'/../Fixtures/foo.xml';
try {
XmlUtils::loadFile($file);
$this->fail('An exception should have been raised');
} catch (\InvalidArgumentException $e) {
$this->assertEquals(sprintf('File %s does not contain valid XML, it is empty.', $file), $e->getMessage());
try {
XmlUtils::loadFile($file);
$this->fail('An exception should have been raised');
} catch (\InvalidArgumentException $e) {
$this->assertEquals(sprintf('File %s does not contain valid XML, it is empty.', $file), $e->getMessage());
}
} catch (\Exception $e) {
restore_error_handler();
error_reporting($errorReporting);
throw $e;
}
restore_error_handler();

View File

@ -117,8 +117,9 @@ class ChoiceQuestion extends Question
$choices = $this->choices;
$errorMessage = $this->errorMessage;
$multiselect = $this->multiselect;
$isAssoc = $this->isAssoc($choices);
return function ($selected) use ($choices, $errorMessage, $multiselect) {
return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
// Collapse all spaces.
$selectedChoices = str_replace(' ', '', $selected);
@ -134,8 +135,28 @@ class ChoiceQuestion extends Question
$multiselectChoices = array();
foreach ($selectedChoices as $value) {
$this->checkMultipleResults($choices, $value);
$result = $this->getResult($choices, $value);
$results = array();
foreach ($choices as $key => $choice) {
if ($choice === $value) {
$results[] = $key;
}
}
if (count($results) > 1) {
throw new \InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
}
$result = array_search($value, $choices);
if (!$isAssoc) {
if (!empty($result)) {
$result = $choices[$result];
} elseif (isset($choices[$value])) {
$result = $choices[$value];
}
} elseif (empty($result) && array_key_exists($value, $choices)) {
$result = $value;
}
if (empty($result)) {
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
@ -150,53 +171,4 @@ class ChoiceQuestion extends Question
return current($multiselectChoices);
};
}
/**
* Checks if there are multiple keys corresponding to the value supplied
* by the user.
*
* @param array $possibleChoices Possible value(s) that the user can supply
* @param string $value Value supplied by the user
*
* @return null
*/
private function checkMultipleResults(array $possibleChoices, $value)
{
$results = array();
foreach ($possibleChoices as $key => $choice) {
if ($choice === $value) {
$results[] = $key;
}
}
if (count($results) > 1) {
throw new \InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
}
}
/**
* Get the result according to what have been provided by the user and the
* possible choices.
*
* @param array $possibleChoices Possible value(s) that the user can supply
* @param string $value Value supplied by the user
*
* @retun string
*/
private function getResult(array $possibleChoices, $value)
{
$result = array_search($value, $possibleChoices);
if (!$this->isAssoc($possibleChoices)) {
if (!empty($result)) {
$result = $possibleChoices[$result];
} elseif (isset($possibleChoices[$value])) {
$result = $possibleChoices[$value];
}
} elseif (empty($result) && array_key_exists($value, $possibleChoices)) {
$result = $value;
}
return $result;
}
}

View File

@ -102,10 +102,13 @@ class Client extends BaseClient
$r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader');
$requirePath = str_replace("'", "\\'", $r->getFileName());
$symfonyPath = str_replace("'", "\\'", realpath(__DIR__.'/../../..'));
$errorReporting = error_reporting();
$code = <<<EOF
<?php
error_reporting($errorReporting);
require_once '$requirePath';
\$loader = new Symfony\Component\ClassLoader\ClassLoader();

View File

@ -71,7 +71,7 @@ class PdoCaster
try {
$a[$attr] = 'ERRMODE' === $attr ? $errmode : $c->getAttribute(constant("PDO::ATTR_{$attr}"));
if (isset($values[$a[$attr]])) {
if ($values && isset($values[$a[$attr]])) {
$a[$attr] = new ConstStub($values[$a[$attr]], $a[$attr]);
}
} catch (\Exception $m) {

View File

@ -0,0 +1,58 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\VarDumper\Tests\Caster;
use Symfony\Component\VarDumper\Caster\PdoCaster;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class PdoCasterTest extends \PHPUnit_Framework_TestCase
{
public function testCastPdo()
{
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('pdo_sqlite extension is required');
}
$pdo = new \PDO('sqlite::memory:');
$pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array($pdo)));
$cast = PdoCaster::castPdo($pdo, array(), new Stub(), false);
$attr = $cast["\0~\0attributes"];
$this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
$this->assertSame('NATURAL', $attr['CASE']->class);
$this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
$xCast = array(
"\0~\0inTransaction" => false,
"\0~\0attributes" => array(
'CASE' => $attr['CASE'],
'ERRMODE' => $attr['ERRMODE'],
'PERSISTENT' => false,
'DRIVER_NAME' => 'sqlite',
'ORACLE_NULLS' => $attr['ORACLE_NULLS'],
'CLIENT_VERSION' => $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION),
'SERVER_VERSION' => $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION),
'STATEMENT_CLASS' => array(
'PDOStatement',
array($pdo),
),
'DEFAULT_FETCH_MODE' => $attr['DEFAULT_FETCH_MODE'],
),
);
$this->assertSame($xCast, $cast);
}
}