Merge branch '2.8' into 3.0

* 2.8:
  fixed CS
  [BrowserKit] Corrected HTTP_HOST logic #15398
  Fixed HTTP Digest auth not being passed user checker
  resolve aliases in factories
  resolve aliases in factory services
  Remove invalid CSS white-space value
  Fix FileSystem tests on Windows
  [Form] ArrayChoiceList can now deal with a null in choices
This commit is contained in:
Christian Flothmann 2016-01-27 12:34:55 +01:00
commit f204104c3b
11 changed files with 104 additions and 40 deletions

View File

@ -7,7 +7,6 @@
padding: 5px 4px;
list-style-type: decimal;
margin-left: 20px;
white-space: break-word;
}
.sf-reset #logs .traces li.error {
font-style: normal;

View File

@ -29,6 +29,7 @@ class HttpDigestFactory implements SecurityFactoryInterface
$container
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao'))
->replaceArgument(0, new Reference($userProvider))
->replaceArgument(1, new Reference('security.user_checker.'.$id))
->replaceArgument(2, $id)
;

View File

@ -14,7 +14,6 @@
padding: 5px 0;
list-style-type: decimal;
margin: 0 0 0 1em;
white-space: break-word;
}
.sf-reset .traces li.selected {
background: rgba(255, 255, 153, 0.5);

View File

@ -123,7 +123,6 @@ abstract class Client
public function setServerParameters(array $server)
{
$this->server = array_merge(array(
'HTTP_HOST' => 'localhost',
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
), $server);
}
@ -286,21 +285,20 @@ abstract class Client
$uri = $this->getAbsoluteUri($uri);
if (!empty($server['HTTP_HOST'])) {
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
}
$server = array_merge($this->server, $server);
if (isset($server['HTTPS'])) {
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
}
$server = array_merge($this->server, $server);
if (!$this->history->isEmpty()) {
$server['HTTP_REFERER'] = $this->history->current()->getUri();
}
$server['HTTP_HOST'] = $this->extractHost($uri);
if (empty($server['HTTP_HOST'])) {
$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);

View File

@ -93,12 +93,14 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
}
public function testGetRequestWithIpAsHost()
public function testGetRequestWithIpAsHttpHost()
{
$client = new TestClient();
$client->request('GET', 'https://example.com/foo', array(), array(), array('HTTP_HOST' => '127.0.0.1'));
$this->assertEquals('https://127.0.0.1/foo', $client->getRequest()->getUri());
$this->assertEquals('https://example.com/foo', $client->getRequest()->getUri());
$headers = $client->getRequest()->getServer();
$this->assertEquals('127.0.0.1', $headers['HTTP_HOST']);
}
public function testGetResponse()
@ -212,24 +214,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('http://www.example.com/http', $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();
@ -588,7 +572,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testGetServerParameter()
{
$client = new TestClient();
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertEquals('testvalue', $client->getServerParameter('testkey', 'testvalue'));
}
@ -597,7 +581,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$client = new TestClient();
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$client->setServerParameter('HTTP_HOST', 'testhost');
@ -611,7 +595,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$client = new TestClient();
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$client->request('GET', 'https://www.example.com/https/www.example.com', array(), array(), array(
@ -621,10 +605,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
'NEW_SERVER_KEY' => 'new-server-key-value',
));
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertEquals('http://testhost/https/www.example.com', $client->getRequest()->getUri());
$this->assertEquals('http://www.example.com/https/www.example.com', $client->getRequest()->getUri());
$server = $client->getRequest()->getServer();

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -42,6 +43,11 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface
$definition->setArguments($this->processArguments($definition->getArguments()));
$definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
$definition->setProperties($this->processArguments($definition->getProperties()));
$definition->setFactory($this->processFactory($definition->getFactory()));
if (null !== $factoryService = $definition->getFactoryService(false)) {
$definition->setFactoryService($this->processFactoryService($factoryService));
}
}
foreach ($container->getAliases() as $id => $alias) {
@ -76,6 +82,30 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface
return $arguments;
}
private function processFactoryService($factoryService)
{
if (null === $factoryService) {
return;
}
return $this->getDefinitionId($factoryService);
}
private function processFactory($factory)
{
if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
return $factory;
}
$defId = $this->getDefinitionId($id = (string) $factory[0]);
if ($defId !== $id) {
$factory[0] = new Reference($defId, $factory[0]->getInvalidBehavior(), $factory[0]->isStrict(false));
}
return $factory;
}
/**
* Resolves an alias into a definition id.
*

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -59,6 +61,45 @@ class ResolveReferencesToAliasesPassTest extends \PHPUnit_Framework_TestCase
$this->process($container);
}
public function testResolveFactory()
{
$container = new ContainerBuilder();
$container->register('factory', 'Factory');
$container->setAlias('factory_alias', new Alias('factory'));
$foo = new Definition();
$foo->setFactory(array(new Reference('factory_alias'), 'createFoo'));
$container->setDefinition('foo', $foo);
$bar = new Definition();
$bar->setFactory(array('Factory', 'createFoo'));
$container->setDefinition('bar', $bar);
$this->process($container);
$resolvedFooFactory = $container->getDefinition('foo')->getFactory();
$resolvedBarFactory = $container->getDefinition('bar')->getFactory();
$this->assertSame('factory', (string) $resolvedFooFactory[0]);
$this->assertSame('Factory', (string) $resolvedBarFactory[0]);
}
/**
* @group legacy
*/
public function testResolveFactoryService()
{
$container = new ContainerBuilder();
$container->register('factory', 'Factory');
$container->setAlias('factory_alias', new Alias('factory'));
$foo = new Definition();
$foo->setFactoryService('factory_alias');
$foo->setFactoryMethod('createFoo');
$container->setDefinition('foo', $foo);
$this->process($container);
$this->assertSame('factory', $foo->getFactoryService());
}
protected function process(ContainerBuilder $container)
{
$pass = new ResolveReferencesToAliasesPass();

View File

@ -893,7 +893,7 @@ class FilesystemTest extends FilesystemTestCase
public function testMirrorCopiesLinkedDirectoryContents()
{
$this->markAsSkippedIfSymlinkIsMissing();
$this->markAsSkippedIfSymlinkIsMissing(true);
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
@ -913,7 +913,7 @@ class FilesystemTest extends FilesystemTestCase
public function testMirrorCopiesRelativeLinkedContents()
{
$this->markAsSkippedIfSymlinkIsMissing();
$this->markAsSkippedIfSymlinkIsMissing(true);
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
$oldPath = getcwd();
@ -1121,8 +1121,8 @@ class FilesystemTest extends FilesystemTestCase
{
$this->markAsSkippedIfChmodIsMissing();
$sourceFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_source_file';
$targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file';
$sourceFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'copy_source_file';
$targetFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'copy_target_file';
file_put_contents($sourceFilePath, 'SOURCE FILE');
chmod($sourceFilePath, 0745);

View File

@ -92,7 +92,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('Unable to retrieve file group name');
}
protected function markAsSkippedIfSymlinkIsMissing()
protected function markAsSkippedIfSymlinkIsMissing($relative = false)
{
if (!function_exists('symlink')) {
$this->markTestSkipped('Function symlink is required.');
@ -101,6 +101,11 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) {
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
}
// https://bugs.php.net/bug.php?id=69473
if ($relative && '\\' === DIRECTORY_SEPARATOR && 1 === PHP_ZTS) {
$this->markTestSkipped('symlink does not support relative paths on thread safe Windows PHP versions');
}
}
protected function markAsSkippedIfChmodIsMissing()

View File

@ -135,7 +135,7 @@ class ArrayChoiceList implements ChoiceListInterface
$choices = array();
foreach ($values as $i => $givenValue) {
if (isset($this->choices[$givenValue])) {
if (array_key_exists($givenValue, $this->choices)) {
$choices[$i] = $this->choices[$givenValue];
}
}

View File

@ -122,4 +122,11 @@ class ArrayChoiceListTest extends AbstractChoiceListTest
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
}
public function testGetChoicesForValuesWithContainingNull()
{
$choiceList = new ArrayChoiceList(array('Null' => null));
$this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0')));
}
}