Skip to content

Commit

Permalink
Merge branch '2.4' into 2.5
Browse files Browse the repository at this point in the history
* 2.4:
  Update validators.eu.xlf
  fixed CS
  remove unused imports
  [Routing] simplify the XML schema file
  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
  [MonologBridge] fixed Console handler priorities
  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/Bundle/FrameworkBundle/Test/WebTestCase.php
	src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php
	src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php
  • Loading branch information
fabpot committed Jul 28, 2014
2 parents e8b53e9 + 4413dac commit 7e175ef
Show file tree
Hide file tree
Showing 35 changed files with 261 additions and 53 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
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Expand Up @@ -139,8 +139,8 @@ public function onTerminate(ConsoleTerminateEvent $event)
public static function getSubscribedEvents()
{
return array(
ConsoleEvents::COMMAND => 'onCommand',
ConsoleEvents::TERMINATE => 'onTerminate'
ConsoleEvents::COMMAND => array('onCommand', 255),
ConsoleEvents::TERMINATE => array('onTerminate', -255),
);
}

Expand Down
44 changes: 44 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php
Expand Up @@ -13,7 +13,13 @@

use Monolog\Logger;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Console\Command\Command;

/**
* Tests the ConsoleHandler and also the ConsoleFormatter.
Expand Down Expand Up @@ -156,4 +162,42 @@ public function testWritingAndFormatting()

$this->assertTrue($handler->handle($errorRecord), 'The handler finished handling the log as bubble is false.');
}

public function testLogsFromListeners()
{
$output = new BufferedOutput();
$output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);

$handler = new ConsoleHandler(null, false);

$logger = new Logger('app');
$logger->pushHandler($handler);

$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::COMMAND, function () use ($logger) {
$logger->addInfo('Before command message.');
});
$dispatcher->addListener(ConsoleEvents::TERMINATE, function () use ($logger) {
$logger->addInfo('Before terminate message.');
});

$dispatcher->addSubscriber($handler);

$dispatcher->addListener(ConsoleEvents::COMMAND, function () use ($logger) {
$logger->addInfo('After command message.');
});
$dispatcher->addListener(ConsoleEvents::TERMINATE, function () use ($logger) {
$logger->addInfo('After terminate message.');
});

$event = new ConsoleCommandEvent(new Command('foo'), $this->getMock('Symfony\Component\Console\Input\InputInterface'), $output);
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
$this->assertContains('Before command message.', $out = $output->fetch());
$this->assertContains('After command message.', $out);

$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMock('Symfony\Component\Console\Input\InputInterface'), $output, 0);
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$this->assertContains('Before terminate message.', $out = $output->fetch());
$this->assertContains('After terminate message.', $out);
}
}
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
10 changes: 5 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
Expand Up @@ -45,14 +45,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 @@ -90,7 +90,7 @@ private static function getPhpUnitCliConfigArgument()
}

/**
* Attempts to guess the Kernel location.
* Attempts to guess the kernel location.
*
* When the Kernel is located, the file is required.
*
Expand All @@ -117,7 +117,7 @@ protected static function getKernelClass()
$finder->name('*Kernel.php')->depth(0)->in($dir);
$results = iterator_to_array($finder);
if (!count($results)) {
throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to http://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the KernelTestCase::createKernel() method.');
throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to http://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the WebTestCase::createKernel() method.');
}

$file = current($results);
Expand All @@ -141,7 +141,7 @@ protected static function bootKernel(array $options = array())
static::$kernel->boot();
}

/**
/**
* Creates a Kernel.
*
* Available options:
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 @@ -297,7 +297,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 @@ -310,12 +310,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 @@ -610,4 +605,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 @@ -18,6 +18,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 @@ -200,8 +201,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 @@ -70,4 +70,11 @@ public function testDumpWithUnresolvedParameter()

$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.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

0 comments on commit 7e175ef

Please sign in to comment.