8000 Merge branch '3.0' · symfony/symfony@a976840 · GitHub
[go: up one dir, main page]

Skip to content

Commit a976840

Browse files
committed
Merge branch '3.0'
* 3.0: fixed previous merge [2.7] Fixed flatten exception recursion with errors Embedded identifier support Also transform inline mappings to objects Change the ExtensionInterface load method definition to bo identical to the documentation. add and correct armenian translations [Config] Fix array sort on normalization in edge case [Security] Run tests on all PHP versions [DomCrawler] Revert previous restriction, allow selection of every DOMNode object [Serializer] Make metadata interfaces internal [Yaml] fix indented line handling in folded blocks improve BrowserKit test coverage p1
2 parents 03c4276 + a9fe244 commit a976840

File tree

21 files changed

+523
-106
lines changed
  • DomCrawler
  • Security/Core/Tests/Encoder
  • Serializer/Mapping
  • Validator/Resources/translations
  • Yaml
  • 21 files changed

    +523
    -106
    lines changed

    src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -58,6 +58,7 @@ public function getEntitiesByIds($identifier, array $values)
    5858
    $qb = clone $this->queryBuilder;
    5959
    $alias = current($qb->getRootAliases());
    6060
    $parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;
    61+
    $parameter = str_replace('.', '_', $parameter);
    6162
    $where = $qb->expr()->in($alias.'.'.$identifier, ':'.$parameter);
    6263

    6364
    // Guess type
    Lines changed: 28 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,28 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    namespace Symfony\Bridge\Doctrine\Tests\Fixtures\Embeddable;
    13+
    14+
    use Doctrine\ORM\Mapping as ORM;
    15+
    16+
    /**
    17+
    * @ORM\Embeddable
    18+
    */
    19+
    class Identifier
    20+
    {
    21+
    /**
    22+
    * @var int
    23+
    *
    24+
    * @ORM\Id
    25+
    * @ORM\Column(type="integer")
    26+
    */
    27+
    protected $value;
    28+
    }
    Lines changed: 27 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,27 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
    13+
    14+
    use Doctrine\ORM\Mapping as ORM;
    15+
    16+
    /**
    17+
    * @ORM\Entity
    18+
    */
    19+
    class EmbeddedIdentifierEntity
    20+
    {
    21+
    /**
    22+
    * @var Embeddable\Identifier
    23+
    *
    24+
    * @ORM\Embedded(class="Symfony\Bridge\Doctrine\Tests\Fixtures\Embeddable\Identifier")
    25+
    */
    26+
    protected $id;
    27+
    }

    src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php

    Lines changed: 35 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,6 +14,7 @@
    1414
    use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
    1515
    use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
    1616
    use Doctrine\DBAL\Connection;
    17+
    use Doctrine\ORM\Version;
    1718

    1819
    class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase
    1920
    {
    @@ -84,4 +85,38 @@ public function testFilterNonIntegerValues()
    8485
    $loader = new ORMQueryBuilderLoader($qb);
    8586
    $loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo'));
    8687
    }
    88+
    89+
    public function testEmbeddedIdentifierName()
    90+
    {
    91+
    if (Version::compare('2.5.0') > 0) {
    92+
    $this->markTestSkipped('Applicable only for Doctrine >= 2.5.0');
    93+
    94+
    return;
    95+
    }
    96+
    97+
    $em = DoctrineTestHelper::createTestEntityManager();
    98+
    99+
    $query = $this->getMockBuilder('QueryMock')
    100+
    ->setMethods(array('setParameter', 'getResult', 'getSql', '_doExecute'))
    101+
    ->getMock();
    102+
    103+
    $query->expects($this->once())
    104+
    ->method('setParameter')
    105+
    ->with('ORMQueryBuilderLoader_getEntitiesByIds_id_value', array(1, 2, 3), Connection::PARAM_INT_ARRAY)
    106+
    ->willReturn($query);
    107+
    108+
    $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
    109+
    ->setConstructorArgs(array($em))
    110+
    ->setMethods(array('getQuery'))
    111+
    ->getMock();
    112+
    $qb->expects($this->once())
    113+
    ->method('getQuery')
    114+
    ->willReturn($query);
    115+
    116+
    $qb->select('e')
    117+
    ->from('Symfony\Bridge\Doctrine\Tests\Fixtures\EmbeddedIdentifierEntity', 'e');
    118+
    119+
    $loader = new ORMQueryBuilderLoader($qb);
    120+
    $loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
    121+
    }
    87122
    }

    src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FirewallEntryPointBundle/DependencyInjection/FirewallEntryPointExtension.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,7 @@
    1818

    1919
    class FirewallEntryPointExtension extends Extension
    2020
    {
    21-
    public function load(array $config, ContainerBuilder $container)
    21+
    public function load(array $configs, ContainerBuilder $container)
    2222
    {
    2323
    $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
    2424
    $loader->load('services.xml');

    src/Symfony/Component/BrowserKit/Tests/ClientTest.php

    Lines changed: 20 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -640,4 +640,24 @@ public function testSetServerParameterInRequest()
    640640
    $this->assertArrayHasKey('HTTPS', $server);
    641641
    $this->assertFalse($server['HTTPS']);
    642642
    }
    643+
    644+
    public function testInternalRequest()
    645+
    {
    646+
    $client = new TestClient();
    647+
    648+
    $client->request('GET', 'https://www.example.com/https/www.example.com', array(), array(), array(
    649+
    'HTTP_HOST' => 'testhost',
    650+
    'HTTP_USER_AGENT' => 'testua',
    651+
    'HTTPS' => false,
    652+
    'NEW_SERVER_KEY' => 'new-server-key-value',
    653+
    ));
    654+
    655+
    $this->assertInstanceOf('Symfony\Component\BrowserKit\Request', $client->getInternalRequest());
    656+
    }
    657+
    658+
    public function testInternalRequestNull()
    659+
    {
    660+
    $client = new TestClient();
    661+
    $this->assertNull($client->getInternalRequest());
    662+
    }
    643663
    }

    src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php

    Lines changed: 18 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -174,6 +174,16 @@ public function testCookieExpireWithNullPaths()
    174174
    $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
    175175
    }
    176176

    177+
    public function testCookieExpireWithDomain()
    178+
    {
    179+
    $cookieJar = new CookieJar();
    180+
    $cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/foo', 'http://example2.com/'));
    181+
    $cookieJar->expire('foo', '/foo', 'http://example2.com/');
    182+
    183+
    $this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
    184+
    $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example2.com/')));
    185+
    }
    186+
    177187
    public function testCookieWithSameNameButDifferentPaths()
    178188
    {
    179189
    $cookieJar = new CookieJar();
    @@ -207,6 +217,14 @@ public function testCookieGetWithSubdomain()
    207217
    $this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'test.example.com'));
    208218
    }
    209219

    220+
    public function testCookieGetWithWrongSubdomain()
    221+
    {
    222+
    $cookieJar = new CookieJar();
    223+
    $cookieJar->set($cookie1 = new Cookie('foo1', 'bar', null, '/', 'test.example.com'));
    224+
    225+
    $this->assertNull($cookieJar->get('foo1', '/', 'foo.example.com'));
    226+
    }
    227+
    210228
    public function testCookieGetWithSubdirectory()
    211229
    {
    212230
    $cookieJar = new CookieJar();

    src/Symfony/Component/BrowserKit/Tests/CookieTest.php

    Lines changed: 9 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -176,4 +176,13 @@ public function testIsExpired()
    176176
    $cookie = new Cookie('foo', 'bar', 0);
    177177
    $this->assertFalse($cookie->isExpired());
    178178
    }
    179+
    180+
    /**
    181+
    * @expectedException UnexpectedValueException
    182+
    * @expectedExceptionMessage The cookie expiration time "string" is not valid.
    183+
    */
    184+
    public function testConstructException()
    185+
    {
    186+
    $cookie = new Cookie('foo', 'bar', 'string');
    187+
    }
    179188
    }

    src/Symfony/Component/Config/Definition/ArrayNode.php

    Lines changed: 6 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -56,14 +56,17 @@ protected function preNormalize($value)
    5656
    return $value;
    5757
    }
    5858

    59+
    $normalized = array();
    60+
    5961
    foreach ($value as $k => $v) {
    6062
    if (false !== strpos< 10000 /span>($k, '-') && false === strpos($k, '_') && !array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
    61-
    $value[$normalizedKey] = $v;
    62-
    unset($value[$k]);
    63+
    $normalized[$normalizedKey] = $v;
    64+
    } else {
    65+
    $normalized[$k] = $v;
    6366
    }
    6467
    }
    6568

    66-
    return $value;
    69+
    return $normalized;
    6770
    }
    6871

    6972
    /**

    src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -86,6 +86,10 @@ public function getPreNormalizationTests()
    8686
    array('foo-bar_moo' => 'foo'),
    8787
    array('foo-bar_moo' => 'foo'),
    8888
    ),
    89+
    array(
    90+
    array('anything-with-dash-and-no-underscore' => 'first', 'no_dash' => 'second'),
    91+
    array('anything_with_dash_and_no_underscore' => 'first', 'no_dash' => 'second'),
    92+
    ),
    8993
    array(
    9094
    array('foo-bar' => null, 'foo_bar' => 'foo'),
    9195
    array('foo-bar' => null, 'foo_bar' => 'foo'),

    src/Symfony/Component/Debug/Exception/FlattenException.php

    Lines changed: 7 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -53,8 +53,13 @@ public static function create(\Exception $exception, $statusCode = null, array $
    5353
    $e->setClass(get_class($exception));
    5454
    $e->setFile($exception->getFile());
    5555
    $e->setLine($exception->getLine());
    56-
    if ($exception->getPrevious()) {
    57-
    $e->setPrevious(static::create($exception->getPrevious()));
    56+
    57+
    $previous = $exception->getPrevious();
    58+
    59+
    if ($previous instanceof \Exception) {
    60+
    $e->setPrevious(static::create($previous));
    61+
    } elseif ($previous instanceof \Throwable) {
    62+
    $e->setPrevious(static::create(new FatalThrowableError($previous)));
    5863
    }
    5964

    6065
    return $e;

    src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

    Lines changed: 14 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -131,6 +131,20 @@ public function testPrevious(\Exception $exception, $statusCode)
    131131
    $this->assertSame(array($flattened2), $flattened->getAllPrevious());
    132132
    }
    133133

    134+
    /**
    135+
    * @requires PHP 7.0
    136+
    */
    137+
    public function testPreviousError()
    138+
    {
    139+
    $exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
    140+
    141+
    $flattened = FlattenException::create($exception)->getPrevious();
    142+
    143+
    $this->assertEquals($flattened->getMessage(), 'Parse error: Oh noes!', 'The message is copied from the original exception.');
    144+
    $this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
    145+
    $this->assertEquals($flattened->getClass(), 'Symfony\Component\Debug\Exception\FatalThrowableError', 'The class is set to the class of the original exception');
    146+
    }
    147+
    134148
    /**
    135149
    * @dataProvider flattenDataProvider
    136150
    */

    src/Symfony/Component/DependencyInjection/Extension/ExtensionInterface.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -23,12 +23,12 @@ interface ExtensionInterface
    2323
    /**
    2424
    * Loads a specific configuration.
    2525
    *
    26-
    * @param array $config An array of configuration values
    26+
    * @param array $configs An array of configuration values
    2727
    * @param ContainerBuilder $container A ContainerBuilder instance
    2828
    *
    2929
    * @throws \InvalidArgumentException When provided tag is not defined in this extension
    3030
    */
    31-
    public function load(array $config, ContainerBuilder $container);
    31+
    public function load(array $configs, ContainerBuilder $container);
    3232

    3333
    /**
    3434
    * Returns the namespace to be used for this extension (XML namespace).

    src/Symfony/Component/DomCrawler/Crawler.php

    Lines changed: 21 additions & 14 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,7 +14,7 @@
    1414
    use Symfony\Component\CssSelector\CssSelectorConverter;
    1515

    1616
    /**
    17-
    * Crawler eases navigation of a list of \DOMElement objects.
    17+
    * Crawler eases navigation of a list of \DOMNode objects.
    1818
    *
    1919
    * @author Fabien Potencier <fabien@symfony.com>
    2020
    */
    @@ -295,10 +295,6 @@ public function addNode(\DOMNode $node)
    295295
    $node = $node->documentElement;
    296296
    }
    297297

    298-
    if (!$node instanceof \DOMElement) {
    299-
    throw new \InvalidArgumentException(sprintf('Nodes set in a Crawler must be DOMElement or DOMDocument instances, "%s" given.', get_class($node)));
    300-
    }
    301-
    302298
    if (null !== $this->document && $this->document !== $node->ownerDocument) {
    303299
    throw new \InvalidArgumentException('Attaching DOM nodes from multiple documents in the same crawler is forbidden.');
    304300
    }
    @@ -696,7 +692,7 @@ public function selectButton($value)
    696692
    *
    697693
    * @return Link A Link instance
    698694
    *
    699-
    * @throws \InvalidArgumentException If the current node list is empty
    695+
    * @throws \InvalidArgumentException If the current node list is empty or the selected node is not instance of DOMElement
    700696
    */
    701697
    public function link($method = 'get')
    702698
    {
    @@ -706,18 +702,28 @@ public function link($method = 'get')
    706702

    707703
    $node = $this->getNode(0);
    708704

    705+
    if (!$node instanceof \DOMElement) {
    706+
    throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_class($node)));
    707+
    }
    708+
    709709
    return new Link($node, $this->baseHref, $method);
    710710
    }
    711711

    712712
    /**
    713713
    * Returns an array of Link objects for the nodes in the list.
    714714
    *
    715715
    * @return Link[] An array of Link instances
    716+
    *
    717+
    * @throws \InvalidArgumentException If the current node list contains non-DOMElement instances
    716718
    */
    717719
    public function links()
    718720
    {
    719721
    $links = array();
    720722
    foreach ($this->nodes as $node) {
    723+
    if (!$node instanceof \DOMElement) {
    724+
    throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_class($node)));
    725+
    }
    726+
    721727
    $links[] = new Link($node, $this->baseHref, 'get');
    722728
    }
    723729

    @@ -732,15 +738,21 @@ public function links()
    732738
    *
    733739
    * @return Form A Form instance
    734740
    *
    735-
    * @throws \InvalidArgumentException If the current node list is empty
    741+
    * @throws \InvalidArgumentException If the current node list is empty or the selected node is not instance of DOMElement
    736742
    */
    737743
    public function form(array $values = null, $method = null)
    738744
    {
    739745
    if (!$this->nodes) {
    740746
    throw new \InvalidArgumentException('The current node list is empty.');
    741747
    }
    742748

    743-
    $form = new Form($this->getNode(0), $this->uri, $method, $this->baseHref);
    749+
    $node = $this->getNode(0);
    750+
    751+
    if (!$node instanceof \DOMElement) {
    752+
    throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_class($node)));
    753+
    }
    754+
    755+
    $form = new Form($node, $this->uri, $method, $this->baseHref);
    744756

    745757
    if (null !== $values) {
    746758
    $form->setValues($values);
    @@ -832,12 +844,7 @@ private function filterRelativeXPath($xpath)
    832844

    833845
    foreach ($this->nodes as $node) {
    834846
    $domxpath = $this->createDOMXPath($node->ownerDocument, $prefixes);
    835-
    836-
    foreach ($domxpath->query($xpath, $node) as $subNode) {
    837-
    if ($subNode->nodeType === 1) {
    838-
    $crawler->add($subNode);
    839-
    }
    840-
    }
    847+
    $crawler->add($domxpath->query($xpath, $node));
    841848
    }
    842849

    843850
    return $crawler;

    0 commit comments

    Comments
     (0)
    0