Skip to content

Commit

Permalink
Merge branch '2.3' into 2.4
Browse files Browse the repository at this point in the history
* 2.3:
  Update validators.eu.xlf
  fixed CS
  remove unused imports
  Unify null comparisons
  [EventDispatcher] don't count empty listeners
  [Process] Fix unit tests in sigchild environment
  [Process] fix signal handling in wait()
  [BrowserKit] refactor code and fix unquoted regex
  Fixed server HTTP_HOST port uri conversion
  Bring code into standard
  [Process] Add test to verify fix for issue #11421
  [Process] Fixes issue #11421
  [DependencyInjection] Pass a Scope instance instead of a scope name.

Conflicts:
	src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php
  • Loading branch information
fabpot committed Jul 28, 2014
2 parents 9b5f56c + 20bf24e commit 4413dac
Show file tree
Hide file tree
Showing 34 changed files with 215 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
Expand Up @@ -49,7 +49,7 @@ public function __construct(ContainerInterface $container)
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
{
if (isset($this->listeners[$eventName])) {
$eventArgs = $eventArgs === null ? EventArgs::getEmptyInstance() : $eventArgs;
$eventArgs = null === $eventArgs ? EventArgs::getEmptyInstance() : $eventArgs;

$initialized = isset($this->initialized[$eventName]);

Expand Down
Expand Up @@ -41,7 +41,7 @@ public function getConfigTreeBuilder()
->end()
->arrayNode('trusted_proxies')
->beforeNormalization()
->ifTrue(function ($v) { return !is_array($v) && !is_null($v); })
->ifTrue(function ($v) { return !is_array($v) && null !== $v; })
->then(function ($v) { return is_bool($v) ? array() : preg_split('/\s*,\s*/', $v); })
->end()
->prototype('scalar')
Expand Down
@@ -1,5 +1,5 @@
<select
<?php if ($required && $empty_value === null && $empty_value_in_choices === false && $multiple === false):
<?php if ($required && null === $empty_value && $empty_value_in_choices === false && $multiple === false):
$required = false;
endif; ?>
<?php echo $view['form']->block($form, 'widget_attributes', array(
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php
Expand Up @@ -69,14 +69,14 @@ protected static function getPhpUnitXmlDir()
}

$dir = static::getPhpUnitCliConfigArgument();
if ($dir === null &&
if (null === $dir &&
(is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
$dir = getcwd();
}

// Can't continue
if ($dir === null) {
if (null === $dir) {
throw new \RuntimeException('Unable to guess the Kernel directory.');
}

Expand Down
Expand Up @@ -96,7 +96,7 @@ public function testServicesAreOrderedAccordingToPriority()
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass',
'findAndSortTaggedServices'
);
$method->setAccessible(TRUE);
$method->setAccessible(true);

$actual = $method->invoke($serializerPass, 'tag', $container);

Expand Down
Expand Up @@ -370,7 +370,7 @@
this.getThreshold = function() {
var threshold = Sfjs.getPreference(_storagePrefix + 'threshold');
if (threshold === null) {
if (null === threshold) {
return _threshold;
}
Expand Down
Expand Up @@ -68,20 +68,20 @@
menu = document.getElementById('navigation'), savedState = Sfjs.getPreference('menu/displayState'),
displayState, elem, className;
if (savedState == null) {
if (null === savedState) {
savedState = 'block';
}
displayState = state || (savedState == 'block' ? 'none' : 'block');
displayState = state || ('block' === savedState ? 'none' : 'block');
if (typeof doSave === 'undefined') {
if ('undefined' === typeof doSave) {
doSave = true;
}
document.getElementById('searchBar').style.display = displayState;
document.getElementById('adminBar').style.display = displayState;
if (displayState == 'block') {
if ('block' === displayState) {
Sfjs.removeClass(menu, 'collapsed-menu');
Sfjs.removeClass(menu.parentNode.parentNode, 'collapsed-menu-parents');
Expand All @@ -107,7 +107,7 @@
}
window.setTimeout(function() {
if (document.getElementById('menu-profiler') == null) {
if (null === document.getElementById('menu-profiler')) {
return;
}
Expand All @@ -119,12 +119,12 @@
}
for (elem in menuItems) {
if (typeof(menuItems[elem].children) != 'undefined' &&
if (typeof(menuItems[elem].children) !== 'undefined' &&
menuItems[elem].children.length > 0) {
child = menuItems[elem].children[0]
if (child.getAttribute('title') == '' ||
child.getAttribute('title') == null) {
if ('' === child.getAttribute('title') ||
null === child.getAttribute('title')) {
value = child.text.replace(/^\s+/g, '').split('\n')[0].replace(/\s+$/g, '');
child.setAttribute('title', value);
}
Expand Down
20 changes: 13 additions & 7 deletions src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -299,7 +299,7 @@ public function request($method, $uri, array $parameters = array(), array $files
$uri = $this->getAbsoluteUri($uri);

if (isset($server['HTTP_HOST'])) {
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '${1}'.$server['HTTP_HOST'], $uri);
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
}

if (isset($server['HTTPS'])) {
Expand All @@ -312,12 +312,7 @@ public function request($method, $uri, array $parameters = array(), array $files
$server['HTTP_REFERER'] = $this->history->current()->getUri();
}

$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);

if ($port = parse_url($uri, PHP_URL_PORT)) {
$server['HTTP_HOST'] .= ':'.$port;
}

$server['HTTP_HOST'] = $this->extractHost($uri);
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);

$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
Expand Down Expand Up @@ -614,4 +609,15 @@ private function updateServerFromUri($server, $uri)

return $server;
}

private function extractHost($uri)
{
$host = parse_url($uri, PHP_URL_HOST);

if ($port = parse_url($uri, PHP_URL_PORT)) {
return $host.':'.$port;
}

return $host;
}
}
18 changes: 18 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -210,6 +210,24 @@ public function testRequestURIConversion()
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
}

public function testRequestURIConversionByServerHost()
{
$client = new TestClient();

$server = array('HTTP_HOST' => 'www.exampl+e.com:8000');
$parameters = array();
$files = array();

$client->request('GET', 'http://exampl+e.com', $parameters, $files, $server);
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');

$client->request('GET', 'http://exampl+e.com:8888', $parameters, $files, $server);
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to modify existing port');

$client->request('GET', 'http://exampl+e.com:8000', $parameters, $files, $server);
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST respects correct set port');
}

public function testRequestReferer()
{
$client = new TestClient();
Expand Down
Expand Up @@ -182,7 +182,7 @@ protected function finalizeTestBuilder($testBuilder, $config = null)
->end()
->end()
->buildTree()
->finalize($config === null ? array('key'=>'value') : $config)
->finalize(null === $config ? array('key'=>'value') : $config)
;
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Scope;

/**
* GraphvizDumper dumps a service container as a graphviz file.
Expand Down Expand Up @@ -193,8 +194,8 @@ private function cloneContainer()
$container->setDefinitions($this->container->getDefinitions());
$container->setAliases($this->container->getAliases());
$container->setResources($this->container->getResources());
foreach ($this->container->getScopes() as $scope) {
$container->addScope($scope);
foreach ($this->container->getScopes() as $scope => $parentScope) {
$container->addScope(new Scope($scope, $parentScope));
}
foreach ($this->container->getExtensions() as $extension) {
$container->registerExtension($extension);
Expand Down
Expand Up @@ -62,4 +62,11 @@ public function testDumpWithFrozenCustomClassContainer()
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
}

public function testDumpWithScopes()
{
$container = include self::$fixturesPath.'/containers/container18.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services18.dot')), $dumper->dump(), '->dump() dumps services');
}
}
@@ -0,0 +1,14 @@
<?php

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Scope;

$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->
register('foo', 'FooClass')->
setScope('request')
;
$container->compile();

return $container;
@@ -0,0 +1,8 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];

node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/EventDispatcher/EventDispatcher.php
Expand Up @@ -74,7 +74,7 @@ public function getListeners($eventName = null)
}
}

return $this->sorted;
return array_filter($this->sorted);
}

/**
Expand Down
Expand Up @@ -274,6 +274,28 @@ public function testWorkaroundForPhpBug62976()
$dispatcher->removeListener('bug.62976', function () {});
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
}

public function testHasListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertFalse($this->dispatcher->hasListeners());
}

public function testGetListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertSame(array(), $this->dispatcher->getListeners());
}

public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
{
$this->assertFalse($this->dispatcher->hasListeners('foo'));
$this->assertFalse($this->dispatcher->hasListeners());
}
}

class CallableClass
Expand Down
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\Finder\Shell\Shell;
use Symfony\Component\Finder\Expression\Expression;
use Symfony\Component\Finder\Shell\Command;
use Symfony\Component\Finder\Iterator\SortableIterator;
use Symfony\Component\Finder\Comparator\NumberComparator;
use Symfony\Component\Finder\Comparator\DateComparator;

Expand Down
Expand Up @@ -50,7 +50,7 @@ public function __construct($param)

public function isFile()
{
if ($this->type === null) {
if (null === $this->type) {
return preg_match('/file/', $this->getFilename());
};

Expand All @@ -59,7 +59,7 @@ public function isFile()

public function isDir()
{
if ($this->type === null) {
if (null === $this->type) {
return preg_match('/directory/', $this->getFilename());
}

Expand All @@ -68,7 +68,7 @@ public function isDir()

public function isReadable()
{
if ($this->mode === null) {
if (null === $this->mode) {
return preg_match('/r\+/', $this->getFilename());
}

Expand Down
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Locale\Locale;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class LocaleType extends AbstractType
Expand Down
Expand Up @@ -12,7 +12,7 @@
</trans-unit>
<trans-unit id="30">
<source>The CSRF token is invalid.</source>
<target>CSFR tokena ez da egokia.</target>
<target>CSRF tokena ez da egokia.</target>
</trans-unit>
</body>
</file>
Expand Down
Expand Up @@ -32,7 +32,7 @@ protected function tearDown()
$this->dateTimeWithoutSeconds = null;
}

public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE)
public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
{
if ($expected instanceof \DateTime && $actual instanceof \DateTime) {
$expected = $expected->format('c');
Expand Down
Expand Up @@ -126,7 +126,7 @@ public function provideParents()
public function testGetParent($violationPath, $parentPath)
{
$path = new ViolationPath($violationPath);
$parent = $parentPath === null ? null : new ViolationPath($parentPath);
$parent = null === $parentPath ? null : new ViolationPath($parentPath);

$this->assertEquals($parent, $path->getParent());
}
Expand Down
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Intl\ResourceBundle;

use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface;

/**
Expand Down
Expand Up @@ -11,7 +11,6 @@

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Icu\IcuData;
use Symfony\Component\Intl\Intl;

require_once __DIR__ . '/common.php';
require_once __DIR__ . '/autoload.php';
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Process/ExecutableFinder.php
Expand Up @@ -59,8 +59,7 @@ public function find($name, $default = null, array $extraDirs = array())
if (is_dir($path)) {
$dirs[] = $path;
} else {
$file = str_replace(dirname($path), '', $path);
if ($file == $name && is_executable($path)) {
if (basename($path) == $name && is_executable($path)) {
return $path;
}
}
Expand Down

0 comments on commit 4413dac

Please sign in to comment.