Merge branch '2.2' into 2.3
* 2.2: Revert "[Console] ensure exit code between 0-254" fix many-to-many Propel1 ModelChoiceList [Console] ensure exit code between 0-254 [DomCrawler] Fixed a fatal error when setting a value in a malformed field name. [Console] fix status code when Exception::getCode returns something like 0.1 Fixed exit code for exceptions with error code 0 instantiate valid commands only Conflicts: src/Symfony/Component/Console/Application.php
This commit is contained in:
commit
2f915f72f6
@ -255,14 +255,14 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
*/
|
*/
|
||||||
public function getIndicesForChoices(array $models)
|
public function getIndicesForChoices(array $models)
|
||||||
{
|
{
|
||||||
|
$indices = array();
|
||||||
|
|
||||||
if (!$this->loaded) {
|
if (!$this->loaded) {
|
||||||
// Optimize performance for single-field identifiers. We already
|
// Optimize performance for single-field identifiers. We already
|
||||||
// know that the IDs are used as indices
|
// know that the IDs are used as indices
|
||||||
|
|
||||||
// Attention: This optimization does not check choices for existence
|
// Attention: This optimization does not check choices for existence
|
||||||
if ($this->identifierAsIndex) {
|
if ($this->identifierAsIndex) {
|
||||||
$indices = array();
|
|
||||||
|
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
if ($model instanceof $this->class) {
|
if ($model instanceof $this->class) {
|
||||||
// Make sure to convert to the right format
|
// Make sure to convert to the right format
|
||||||
@ -276,7 +276,30 @@ class ModelChoiceList extends ObjectChoiceList
|
|||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getIndicesForChoices($models);
|
/*
|
||||||
|
* Overwriting default implementation.
|
||||||
|
*
|
||||||
|
* The two objects may represent the same entry in the database,
|
||||||
|
* but if they originated from different queries, there are not the same object within the code.
|
||||||
|
*
|
||||||
|
* This happens when using m:n relations with either sides model as data_class of the form.
|
||||||
|
* The choicelist will retrieve the list of available related models with a different query, resulting in different objects.
|
||||||
|
*/
|
||||||
|
$choices = $this->fixChoices($models);
|
||||||
|
foreach ($this->getChoices() as $i => $choice) {
|
||||||
|
foreach ($choices as $j => $givenChoice) {
|
||||||
|
if ($this->getIdentifierValues($choice) === $this->getIdentifierValues($givenChoice)) {
|
||||||
|
$indices[] = $i;
|
||||||
|
unset($choices[$j]);
|
||||||
|
|
||||||
|
if (0 === count($choices)) {
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,4 +185,18 @@ class ModelChoiceListTest extends Propel1TestCase
|
|||||||
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
|
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
|
||||||
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
|
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDifferentEqualObjectsAreChoosen()
|
||||||
|
{
|
||||||
|
$item = new Item(1, 'Foo');
|
||||||
|
$choiceList = new ModelChoiceList(
|
||||||
|
self::ITEM_CLASS,
|
||||||
|
'value',
|
||||||
|
array($item)
|
||||||
|
);
|
||||||
|
|
||||||
|
$choosenItem = new Item(1, 'Foo');
|
||||||
|
|
||||||
|
$this->assertEquals(array(1), $choiceList->getIndicesForChoices(array($choosenItem)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,9 +129,16 @@ class Application
|
|||||||
} else {
|
} else {
|
||||||
$this->renderException($e, $output);
|
$this->renderException($e, $output);
|
||||||
}
|
}
|
||||||
$exitCode = $e->getCode();
|
|
||||||
|
|
||||||
$exitCode = $exitCode ? (is_numeric($exitCode) ? (int) $exitCode : 1) : 0;
|
$exitCode = $e->getCode();
|
||||||
|
if (is_numeric($exitCode)) {
|
||||||
|
$exitCode = (int) $exitCode;
|
||||||
|
if (0 === $exitCode) {
|
||||||
|
$exitCode = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$exitCode = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->autoExit) {
|
if ($this->autoExit) {
|
||||||
|
@ -573,6 +573,21 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
|
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRunReturnsExitCodeOneForExceptionCodeZero()
|
||||||
|
{
|
||||||
|
$exception = new \Exception('', 0);
|
||||||
|
|
||||||
|
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
|
||||||
|
$application->setAutoExit(false);
|
||||||
|
$application->expects($this->once())
|
||||||
|
->method('doRun')
|
||||||
|
->will($this->throwException($exception));
|
||||||
|
|
||||||
|
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
|
||||||
|
|
||||||
|
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \LogicException
|
* @expectedException \LogicException
|
||||||
* @dataProvider getAddingAlreadySetDefinitionElementData
|
* @dataProvider getAddingAlreadySetDefinitionElementData
|
||||||
|
@ -204,8 +204,12 @@ class FormFieldRegistry
|
|||||||
{
|
{
|
||||||
if (preg_match('/^(?P<base>[^[]+)(?P<extra>(\[.*)|$)/', $name, $m)) {
|
if (preg_match('/^(?P<base>[^[]+)(?P<extra>(\[.*)|$)/', $name, $m)) {
|
||||||
$segments = array($m['base']);
|
$segments = array($m['base']);
|
||||||
while (preg_match('/^\[(?P<segment>.*?)\](?P<extra>.*)$/', $m['extra'], $m)) {
|
while (!empty($m['extra'])) {
|
||||||
|
if (preg_match('/^\[(?P<segment>.*?)\](?P<extra>.*)$/', $m['extra'], $m)) {
|
||||||
$segments[] = $m['segment'];
|
$segments[] = $m['segment'];
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Malformed field path "%s"', $name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $segments;
|
return $segments;
|
||||||
|
@ -292,6 +292,18 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetValueOnMultiValuedFieldsWithMalformedName()
|
||||||
|
{
|
||||||
|
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="bar" /><input type="text" name="foo[baz]" value="baz" /><input type="submit" /></form>');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form['foo[bar'] = 'bar';
|
||||||
|
$this->fail('->offsetSet() throws an \InvalidArgumentException exception if the name is malformed.');
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
$this->assertTrue(true, '->offsetSet() throws an \InvalidArgumentException exception if the name is malformed.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testOffsetUnset()
|
public function testOffsetUnset()
|
||||||
{
|
{
|
||||||
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
|
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
|
||||||
|
@ -189,7 +189,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface
|
|||||||
$ns .= '\\'.strtr($relativePath, '/', '\\');
|
$ns .= '\\'.strtr($relativePath, '/', '\\');
|
||||||
}
|
}
|
||||||
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
|
$r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
|
||||||
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
|
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
|
||||||
$application->add($r->newInstance());
|
$application->add($r->newInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This command has a required parameter on the constructor and will be ignored by the default Bundle implementation.
|
||||||
|
*
|
||||||
|
* @see Symfony\Component\HttpKernel\Bundle\Bundle::registerCommands
|
||||||
|
*/
|
||||||
|
class BarCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct($example, $name = 'bar')
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user