Merge branch '2.3' into 2.7

* 2.3:
  Finnish translation fix
  [CssSelector] Optimize regexs matching simple selectors
  Fix the phpdoc in the CssSelector TranslatorInterface
  [Console] Add clock mock to fix transient test on HHVM
  [EventDispatcher] skip one lazy loading call
  [EventDispatcher] fix memory leak in a getListeners
This commit is contained in:
Nicolas Grekas 2015-09-22 15:49:29 +02:00
commit b6604f3e6f
14 changed files with 103 additions and 81 deletions

View File

@ -0,0 +1,41 @@
<?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\Console\Helper;
use Symfony\Component\Console\Tests;
function time()
{
return Tests\time();
}
namespace Symfony\Component\Console\Tests;
function with_clock_mock($enable = null)
{
static $enabled;
if (null === $enable) {
return $enabled;
}
$enabled = $enable;
}
function time()
{
if (!with_clock_mock()) {
return \time();
}
return $_SERVER['REQUEST_TIME'];
}

View File

@ -13,12 +13,25 @@ namespace Symfony\Component\Console\Tests\Helper;
use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Tests;
require_once __DIR__.'/../ClockMock.php';
/**
* @group legacy
*/
class LegacyProgressHelperTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
Tests\with_clock_mock(true);
}
protected function tearDown()
{
Tests\with_clock_mock(false);
}
public function testAdvance()
{
$progress = new ProgressHelper();

View File

@ -33,15 +33,14 @@ class ClassParser implements ParserInterface
{
// Matches an optional namespace, optional element, and required class
// $source = 'test|input.ab6bd_field';
// $matches = array (size=5)
// 0 => string 'test:input.ab6bd_field' (length=22)
// 1 => string 'test:' (length=5)
// 2 => string 'test' (length=4)
// 3 => string 'input' (length=5)
// 4 => string 'ab6bd_field' (length=11)
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?\.([\w-]+)$/i', trim($source), $matches)) {
// $matches = array (size=4)
// 0 => string 'test|input.ab6bd_field' (length=22)
// 1 => string 'test' (length=4)
// 2 => string 'input' (length=5)
// 3 => string 'ab6bd_field' (length=11)
if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+\.([\w-]++)$/i', trim($source), $matches)) {
return array(
new SelectorNode(new ClassNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])),
new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])),
);
}

View File

@ -32,13 +32,12 @@ class ElementParser implements ParserInterface
{
// Matches an optional namespace, required element or `*`
// $source = 'testns|testel';
// $matches = array (size=4)
// 0 => string 'testns:testel' (length=13)
// 1 => string 'testns:' (length=7)
// 2 => string 'testns' (length=6)
// 3 => string 'testel' (length=6)
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)$/i', trim($source), $matches)) {
return array(new SelectorNode(new ElementNode($matches[2] ?: null, $matches[3])));
// $matches = array (size=3)
// 0 => string 'testns|testel' (length=13)
// 1 => string 'testns' (length=6)
// 2 => string 'testel' (length=6)
if (preg_match('/^(?:([a-z]++)\|)?([\w-]++|\*)$/i', trim($source), $matches)) {
return array(new SelectorNode(new ElementNode($matches[1] ?: null, $matches[2])));
}
return array();

View File

@ -33,15 +33,14 @@ class HashParser implements ParserInterface
{
// Matches an optional namespace, optional element, and required id
// $source = 'test|input#ab6bd_field';
// $matches = array (size=5)
// 0 => string 'test:input#ab6bd_field' (length=22)
// 1 => string 'test:' (length=5)
// 2 => string 'test' (length=4)
// 3 => string 'input' (length=5)
// 4 => string 'ab6bd_field' (length=11)
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?#([\w-]+)$/i', trim($source), $matches)) {
// $matches = array (size=4)
// 0 => string 'test|input#ab6bd_field' (length=22)
// 1 => string 'test' (length=4)
// 2 => string 'input' (length=5)
// 3 => string 'ab6bd_field' (length=11)
if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+#([\w-]++)$/i', trim($source), $matches)) {
return array(
new SelectorNode(new HashNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])),
new SelectorNode(new HashNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])),
);
}

View File

@ -29,7 +29,7 @@ interface TranslatorInterface
* @param string $cssExpr
* @param string $prefix
*
* @return XPathExpr
* @return string
*/
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::');
@ -39,7 +39,7 @@ interface TranslatorInterface
* @param SelectorNode $selector
* @param string $prefix
*
* @return XPathExpr
* @return string
*/
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::');
}

View File

@ -100,7 +100,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
}
/**
* @see EventDispatcherInterface::hasListeners()
* {@inheritdoc}
*/
public function hasListeners($eventName = null)
{
@ -116,7 +116,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
}
/**
* @see EventDispatcherInterface::getListeners()
* {@inheritdoc}
*/
public function getListeners($eventName = null)
{
@ -152,21 +152,6 @@ class ContainerAwareEventDispatcher extends EventDispatcher
}
}
/**
* {@inheritdoc}
*
* Lazily loads listeners for this event from the dependency injection
* container.
*
* @throws \InvalidArgumentException if the service is not defined
*/
public function dispatch($eventName, Event $event = null)
{
$this->lazyLoad($eventName);
return parent::dispatch($eventName, $event);
}
public function getContainer()
{
return $this->container;

View File

@ -33,9 +33,7 @@ class EventDispatcher implements EventDispatcherInterface
private $sorted = array();
/**
* @see EventDispatcherInterface::dispatch()
*
* @api
* {@inheritdoc}
*/
public function dispatch($eventName, Event $event = null)
{
@ -46,21 +44,23 @@ class EventDispatcher implements EventDispatcherInterface
$event->setDispatcher($this);
$event->setName($eventName);
if (!isset($this->listeners[$eventName])) {
return $event;
if ($listeners = $this->getListeners($eventName)) {
$this->doDispatch($listeners, $eventName, $event);
}
$this->doDispatch($this->getListeners($eventName), $eventName, $event);
return $event;
}
/**
* @see EventDispatcherInterface::getListeners()
* {@inheritdoc}
*/
public function getListeners($eventName = null)
{
if (null !== $eventName) {
if (!isset($this->listeners[$eventName])) {
return array();
}
if (!isset($this->sorted[$eventName])) {
$this->sortListeners($eventName);
}
@ -78,7 +78,7 @@ class EventDispatcher implements EventDispatcherInterface
}
/**
* @see EventDispatcherInterface::hasListeners()
* {@inheritdoc}
*/
public function hasListeners($eventName = null)
{
@ -86,9 +86,7 @@ class EventDispatcher implements EventDispatcherInterface
}
/**
* @see EventDispatcherInterface::addListener()
*
* @api
* {@inheritdoc}
*/
public function addListener($eventName, $listener, $priority = 0)
{
@ -97,7 +95,7 @@ class EventDispatcher implements EventDispatcherInterface
}
/**
* @see EventDispatcherInterface::removeListener()
* {@inheritdoc}
*/
public function removeListener($eventName, $listener)
{
@ -113,9 +111,7 @@ class EventDispatcher implements EventDispatcherInterface
}
/**
* @see EventDispatcherInterface::addSubscriber()
*
* @api
* {@inheritdoc}
*/
public function addSubscriber(EventSubscriberInterface $subscriber)
{
@ -133,7 +129,7 @@ class EventDispatcher implements EventDispatcherInterface
}
/**
* @see EventDispatcherInterface::removeSubscriber()
* {@inheritdoc}
*/
public function removeSubscriber(EventSubscriberInterface $subscriber)
{
@ -177,9 +173,7 @@ class EventDispatcher implements EventDispatcherInterface
{
$this->sorted[$eventName] = array();
if (isset($this->listeners[$eventName])) {
krsort($this->listeners[$eventName]);
$this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
}
krsort($this->listeners[$eventName]);
$this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
}
}

View File

@ -12,7 +12,7 @@
</trans-unit>
<trans-unit id="30">
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
<target>CSRF tarkiste on virheellinen. Olen hyvä ja yritä lähettää lomake uudestaan.</target>
<target>CSRF tarkiste on virheellinen. Ole hyvä ja yritä lähettää lomake uudestaan.</target>
</trans-unit>
</body>
</file>

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\HttpFoundation;
function time($asFloat = false)
function time()
{
return Tests\time();
}

View File

@ -23,16 +23,14 @@ require_once __DIR__.'/ClockMock.php';
*/
class CookieTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function invalidNames()

View File

@ -18,16 +18,14 @@ require_once __DIR__.'/ClockMock.php';
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
/**

View File

@ -24,16 +24,14 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
{
const DELTA = 37;
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function testGetOrigin()

View File

@ -24,16 +24,14 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
{
const DELTA = 20;
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function testStart()