Merge branch '2.3' into 2.4
* 2.3: Fixed failed config schema loads due to libxml_disable_entity_loader usage. enabled PHP 5.6 for tests [Process] Fix ExecutableFinder with open basedir Refactored the CssSelector to remove the circular object graph Fix mocks to support >=5.5.14 and >=5.4.30 [ClassLoader] fixed PHP warning on PHP 5.3 [Components][Serializer] optional constructor arguments can be omitted during the denormalization process [DomCrawler] properly handle buttons with single and double quotes inside the name attribute Conflicts: src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php
This commit is contained in:
commit
5b2e34f765
@ -10,7 +10,6 @@ php:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: 5.6
|
|
||||||
- php: hhvm-nightly
|
- php: hhvm-nightly
|
||||||
|
|
||||||
services: mongodb
|
services: mongodb
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\ClassLoader;
|
namespace Symfony\Component\ClassLoader;
|
||||||
|
|
||||||
|
if (!defined('T_TRAIT')) {
|
||||||
|
define('T_TRAIT', 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassMapGenerator
|
* ClassMapGenerator
|
||||||
*
|
*
|
||||||
@ -84,7 +88,6 @@ class ClassMapGenerator
|
|||||||
{
|
{
|
||||||
$contents = file_get_contents($path);
|
$contents = file_get_contents($path);
|
||||||
$tokens = token_get_all($contents);
|
$tokens = token_get_all($contents);
|
||||||
$T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;
|
|
||||||
|
|
||||||
$classes = array();
|
$classes = array();
|
||||||
|
|
||||||
@ -111,7 +114,7 @@ class ClassMapGenerator
|
|||||||
break;
|
break;
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_INTERFACE:
|
case T_INTERFACE:
|
||||||
case $T_TRAIT:
|
case T_TRAIT:
|
||||||
// Find the classname
|
// Find the classname
|
||||||
while (($t = $tokens[++$i]) && is_array($t)) {
|
while (($t = $tokens[++$i]) && is_array($t)) {
|
||||||
if (T_STRING === $t[0]) {
|
if (T_STRING === $t[0]) {
|
||||||
|
@ -80,7 +80,8 @@ class XmlUtils
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
} elseif (!is_array($schemaOrCallable) && is_file((string) $schemaOrCallable)) {
|
} elseif (!is_array($schemaOrCallable) && is_file((string) $schemaOrCallable)) {
|
||||||
$valid = @$dom->schemaValidate($schemaOrCallable);
|
$schemaSource = file_get_contents((string) $schemaOrCallable);
|
||||||
|
$valid = @$dom->schemaValidateSource($schemaSource);
|
||||||
} else {
|
} else {
|
||||||
libxml_use_internal_errors($internalErrors);
|
libxml_use_internal_errors($internalErrors);
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ interface ExtensionInterface
|
|||||||
/**
|
/**
|
||||||
* Returns node translators.
|
* Returns node translators.
|
||||||
*
|
*
|
||||||
|
* These callables will receive the node as first argument and the translator as second argument.
|
||||||
|
*
|
||||||
* @return callable[]
|
* @return callable[]
|
||||||
*/
|
*/
|
||||||
public function getNodeTranslators();
|
public function getNodeTranslators();
|
||||||
|
@ -29,11 +29,6 @@ class NodeExtension extends AbstractExtension
|
|||||||
const ATTRIBUTE_NAME_IN_LOWER_CASE = 2;
|
const ATTRIBUTE_NAME_IN_LOWER_CASE = 2;
|
||||||
const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4;
|
const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Translator
|
|
||||||
*/
|
|
||||||
private $translator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
@ -42,12 +37,10 @@ class NodeExtension extends AbstractExtension
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param Translator $translator
|
* @param int $flags
|
||||||
* @param int $flags
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Translator $translator, $flags = 0)
|
public function __construct($flags = 0)
|
||||||
{
|
{
|
||||||
$this->translator = $translator;
|
|
||||||
$this->flags = $flags;
|
$this->flags = $flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,33 +93,36 @@ class NodeExtension extends AbstractExtension
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\SelectorNode $node
|
* @param Node\SelectorNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateSelector(Node\SelectorNode $node)
|
public function translateSelector(Node\SelectorNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
return $this->translator->nodeToXPath($node->getTree());
|
return $translator->nodeToXPath($node->getTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\CombinedSelectorNode $node
|
* @param Node\CombinedSelectorNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateCombinedSelector(Node\CombinedSelectorNode $node)
|
public function translateCombinedSelector(Node\CombinedSelectorNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
return $this->translator->addCombination($node->getCombinator(), $node->getSelector(), $node->getSubSelector());
|
return $translator->addCombination($node->getCombinator(), $node->getSelector(), $node->getSubSelector());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\NegationNode $node
|
* @param Node\NegationNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateNegation(Node\NegationNode $node)
|
public function translateNegation(Node\NegationNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
$xpath = $this->translator->nodeToXPath($node->getSelector());
|
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||||
$subXpath = $this->translator->nodeToXPath($node->getSubSelector());
|
$subXpath = $translator->nodeToXPath($node->getSubSelector());
|
||||||
$subXpath->addNameTest();
|
$subXpath->addNameTest();
|
||||||
|
|
||||||
if ($subXpath->getCondition()) {
|
if ($subXpath->getCondition()) {
|
||||||
@ -138,34 +134,37 @@ class NodeExtension extends AbstractExtension
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\FunctionNode $node
|
* @param Node\FunctionNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateFunction(Node\FunctionNode $node)
|
public function translateFunction(Node\FunctionNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
$xpath = $this->translator->nodeToXPath($node->getSelector());
|
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||||
|
|
||||||
return $this->translator->addFunction($xpath, $node);
|
return $translator->addFunction($xpath, $node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\PseudoNode $node
|
* @param Node\PseudoNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translatePseudo(Node\PseudoNode $node)
|
public function translatePseudo(Node\PseudoNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
$xpath = $this->translator->nodeToXPath($node->getSelector());
|
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||||
|
|
||||||
return $this->translator->addPseudoClass($xpath, $node->getIdentifier());
|
return $translator->addPseudoClass($xpath, $node->getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\AttributeNode $node
|
* @param Node\AttributeNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateAttribute(Node\AttributeNode $node)
|
public function translateAttribute(Node\AttributeNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
$name = $node->getAttribute();
|
$name = $node->getAttribute();
|
||||||
$safe = $this->isSafeName($name);
|
$safe = $this->isSafeName($name);
|
||||||
@ -181,37 +180,39 @@ class NodeExtension extends AbstractExtension
|
|||||||
|
|
||||||
$attribute = $safe ? '@'.$name : sprintf('attribute::*[name() = %s]', Translator::getXpathLiteral($name));
|
$attribute = $safe ? '@'.$name : sprintf('attribute::*[name() = %s]', Translator::getXpathLiteral($name));
|
||||||
$value = $node->getValue();
|
$value = $node->getValue();
|
||||||
$xpath = $this->translator->nodeToXPath($node->getSelector());
|
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||||
|
|
||||||
if ($this->hasFlag(self::ATTRIBUTE_VALUE_IN_LOWER_CASE)) {
|
if ($this->hasFlag(self::ATTRIBUTE_VALUE_IN_LOWER_CASE)) {
|
||||||
$value = strtolower($value);
|
$value = strtolower($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->translator->addAttributeMatching($xpath, $node->getOperator(), $attribute, $value);
|
return $translator->addAttributeMatching($xpath, $node->getOperator(), $attribute, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\ClassNode $node
|
* @param Node\ClassNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateClass(Node\ClassNode $node)
|
public function translateClass(Node\ClassNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
$xpath = $this->translator->nodeToXPath($node->getSelector());
|
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||||
|
|
||||||
return $this->translator->addAttributeMatching($xpath, '~=', '@class', $node->getName());
|
return $translator->addAttributeMatching($xpath, '~=', '@class', $node->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Node\HashNode $node
|
* @param Node\HashNode $node
|
||||||
|
* @param Translator $translator
|
||||||
*
|
*
|
||||||
* @return XPathExpr
|
* @return XPathExpr
|
||||||
*/
|
*/
|
||||||
public function translateHash(Node\HashNode $node)
|
public function translateHash(Node\HashNode $node, Translator $translator)
|
||||||
{
|
{
|
||||||
$xpath = $this->translator->nodeToXPath($node->getSelector());
|
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||||
|
|
||||||
return $this->translator->addAttributeMatching($xpath, '=', '@id', $node->getId());
|
return $translator->addAttributeMatching($xpath, '=', '@id', $node->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,7 @@ class Translator implements TranslatorInterface
|
|||||||
$this->mainParser = $parser ?: new Parser();
|
$this->mainParser = $parser ?: new Parser();
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->registerExtension(new Extension\NodeExtension($this))
|
->registerExtension(new Extension\NodeExtension())
|
||||||
->registerExtension(new Extension\CombinationExtension())
|
->registerExtension(new Extension\CombinationExtension())
|
||||||
->registerExtension(new Extension\FunctionExtension())
|
->registerExtension(new Extension\FunctionExtension())
|
||||||
->registerExtension(new Extension\PseudoClassExtension())
|
->registerExtension(new Extension\PseudoClassExtension())
|
||||||
@ -207,7 +207,7 @@ class Translator implements TranslatorInterface
|
|||||||
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
|
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return call_user_func($this->nodeTranslators[$node->getNodeName()], $node);
|
return call_user_func($this->nodeTranslators[$node->getNodeName()], $node, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -676,8 +676,8 @@ class Crawler extends \SplObjectStorage
|
|||||||
{
|
{
|
||||||
$translate = 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")';
|
$translate = 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")';
|
||||||
$xpath = sprintf('descendant-or-self::input[((contains(%s, "submit") or contains(%s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %s)) ', $translate, $translate, static::xpathLiteral(' '.$value.' ')).
|
$xpath = sprintf('descendant-or-self::input[((contains(%s, "submit") or contains(%s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %s)) ', $translate, $translate, static::xpathLiteral(' '.$value.' ')).
|
||||||
sprintf('or (contains(%s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %s)) or @id="%s" or @name="%s"] ', $translate, static::xpathLiteral(' '.$value.' '), $value, $value).
|
sprintf('or (contains(%s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %s)) or @id=%s or @name=%s] ', $translate, static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value), static::xpathLiteral($value)).
|
||||||
sprintf('| descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %s) or @id="%s" or @name="%s"]', static::xpathLiteral(' '.$value.' '), $value, $value);
|
sprintf('| descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %s) or @id=%s or @name=%s]', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value), static::xpathLiteral($value));
|
||||||
|
|
||||||
return $this->filterRelativeXPath($xpath);
|
return $this->filterRelativeXPath($xpath);
|
||||||
}
|
}
|
||||||
|
@ -569,6 +569,48 @@ EOF
|
|||||||
$this->assertEquals(1, $crawler->selectButton('FooBarName')->count(), '->selectButton() selects buttons with form attribute too');
|
$this->assertEquals(1, $crawler->selectButton('FooBarName')->count(), '->selectButton() selects buttons with form attribute too');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSelectButtonWithSingleQuotesInNameAttribute()
|
||||||
|
{
|
||||||
|
$html = <<<HTML
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<div id="action">
|
||||||
|
<a href="/index.php?r=site/login">Login</a>
|
||||||
|
</div>
|
||||||
|
<form id="login-form" action="/index.php?r=site/login" method="post">
|
||||||
|
<button type="submit" name="Click 'Here'">Submit</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML;
|
||||||
|
|
||||||
|
$crawler = new Crawler($html);
|
||||||
|
|
||||||
|
$this->assertCount(1, $crawler->selectButton('Click \'Here\''));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSelectButtonWithDoubleQuotesInNameAttribute()
|
||||||
|
{
|
||||||
|
$html = <<<HTML
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<div id="action">
|
||||||
|
<a href="/index.php?r=site/login">Login</a>
|
||||||
|
</div>
|
||||||
|
<form id="login-form" action="/index.php?r=site/login" method="post">
|
||||||
|
<button type="submit" name='Click "Here"'>Submit</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML;
|
||||||
|
|
||||||
|
$crawler = new Crawler($html);
|
||||||
|
|
||||||
|
$this->assertCount(1, $crawler->selectButton('Click "Here"'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testLink()
|
public function testLink()
|
||||||
{
|
{
|
||||||
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
|
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Tests\Extension\HttpFoundation;
|
|||||||
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
|
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
|
||||||
use Symfony\Component\Form\Tests\AbstractRequestHandlerTest;
|
use Symfony\Component\Form\Tests\AbstractRequestHandlerTest;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
@ -47,8 +48,6 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest
|
|||||||
|
|
||||||
protected function getMockFile()
|
protected function getMockFile()
|
||||||
{
|
{
|
||||||
return $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
|
return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo');
|
||||||
->setConstructorArgs(array(__DIR__.'/../../Fixtures/foo', 'foo'))
|
|
||||||
->getMock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
<?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\HttpFoundation\Resources\stubs;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\File\File as OrigFile;
|
||||||
|
|
||||||
|
class FakeFile extends OrigFile
|
||||||
|
{
|
||||||
|
private $realpath;
|
||||||
|
|
||||||
|
public function __construct($realpath, $path)
|
||||||
|
{
|
||||||
|
$this->realpath = $realpath;
|
||||||
|
parent::__construct($path, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isReadable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRealpath()
|
||||||
|
{
|
||||||
|
return $this->realpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSize()
|
||||||
|
{
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMTime()
|
||||||
|
{
|
||||||
|
return time();
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ namespace Symfony\Component\HttpFoundation\Tests;
|
|||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||||
|
use Symfony\Component\HttpFoundation\Resources\stubs\FakeFile;
|
||||||
|
|
||||||
class BinaryFileResponseTest extends ResponseTestCase
|
class BinaryFileResponseTest extends ResponseTestCase
|
||||||
{
|
{
|
||||||
@ -179,18 +180,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
$request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect');
|
$request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect');
|
||||||
$request->headers->set('X-Accel-Mapping', $mapping);
|
$request->headers->set('X-Accel-Mapping', $mapping);
|
||||||
|
|
||||||
$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
$file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test');
|
||||||
->setConstructorArgs(array(__DIR__.'/File/Fixtures/test'))
|
|
||||||
->getMock();
|
|
||||||
$file->expects($this->any())
|
|
||||||
->method('getRealPath')
|
|
||||||
->will($this->returnValue($realpath));
|
|
||||||
$file->expects($this->any())
|
|
||||||
->method('isReadable')
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$file->expects($this->any())
|
|
||||||
->method('getMTime')
|
|
||||||
->will($this->returnValue(time()));
|
|
||||||
|
|
||||||
BinaryFileResponse::trustXSendFileTypeHeader();
|
BinaryFileResponse::trustXSendFileTypeHeader();
|
||||||
$response = new BinaryFileResponse($file);
|
$response = new BinaryFileResponse($file);
|
||||||
|
@ -53,7 +53,7 @@ class ExecutableFinder
|
|||||||
public function find($name, $default = null, array $extraDirs = array())
|
public function find($name, $default = null, array $extraDirs = array())
|
||||||
{
|
{
|
||||||
if (ini_get('open_basedir')) {
|
if (ini_get('open_basedir')) {
|
||||||
$searchPath = explode(PATH_SEPARATOR, getenv('open_basedir'));
|
$searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
|
||||||
$dirs = array();
|
$dirs = array();
|
||||||
foreach ($searchPath as $path) {
|
foreach ($searchPath as $path) {
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
|
112
src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
Normal file
112
src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?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\Process\Tests;
|
||||||
|
|
||||||
|
use Symfony\Component\Process\ExecutableFinder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Chris Smith <chris@cs278.org>
|
||||||
|
*/
|
||||||
|
class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private $path;
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
if ($this->path) {
|
||||||
|
// Restore path if it was changed.
|
||||||
|
putenv('PATH='.$this->path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setPath($path)
|
||||||
|
{
|
||||||
|
$this->path = getenv('PATH');
|
||||||
|
putenv('PATH='.$path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFind()
|
||||||
|
{
|
||||||
|
if (!defined('PHP_BINARY')) {
|
||||||
|
$this->markTestSkipped('Requires the PHP_BINARY constant');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini_get('open_basedir')) {
|
||||||
|
$this->markTestSkipped('Cannot test when open_basedir is set');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setPath(dirname(PHP_BINARY));
|
||||||
|
|
||||||
|
$finder = new ExecutableFinder;
|
||||||
|
$result = $finder->find(basename(PHP_BINARY));
|
||||||
|
|
||||||
|
$this->assertEquals($result, PHP_BINARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindWithDefault()
|
||||||
|
{
|
||||||
|
if (ini_get('open_basedir')) {
|
||||||
|
$this->markTestSkipped('Cannot test when open_basedir is set');
|
||||||
|
}
|
||||||
|
|
||||||
|
$expected = 'defaultValue';
|
||||||
|
|
||||||
|
$this->setPath('');
|
||||||
|
|
||||||
|
$finder = new ExecutableFinder;
|
||||||
|
$result = $finder->find('foo', $expected);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindWithExtraDirs()
|
||||||
|
{
|
||||||
|
if (!defined('PHP_BINARY')) {
|
||||||
|
$this->markTestSkipped('Requires the PHP_BINARY constant');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini_get('open_basedir')) {
|
||||||
|
$this->markTestSkipped('Cannot test when open_basedir is set');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setPath('');
|
||||||
|
|
||||||
|
$extraDirs = array(dirname(PHP_BINARY));
|
||||||
|
|
||||||
|
$finder = new ExecutableFinder;
|
||||||
|
$result = $finder->find(basename(PHP_BINARY), null, $extraDirs);
|
||||||
|
|
||||||
|
$this->assertEquals(PHP_BINARY, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindWithOpenBaseDir()
|
||||||
|
{
|
||||||
|
if (!defined('PHP_BINARY')) {
|
||||||
|
$this->markTestSkipped('Requires the PHP_BINARY constant');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
$this->markTestSkipped('Cannot run test on windows');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini_get('open_basedir')) {
|
||||||
|
$this->markTestSkipped('Cannot test when open_basedir is set');
|
||||||
|
}
|
||||||
|
|
||||||
|
ini_set('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/');
|
||||||
|
|
||||||
|
$finder = new ExecutableFinder;
|
||||||
|
$result = $finder->find(basename(PHP_BINARY));
|
||||||
|
|
||||||
|
$this->assertEquals(PHP_BINARY, $result);
|
||||||
|
}
|
||||||
|
}
|
@ -131,7 +131,9 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer implements Normal
|
|||||||
$params[] = $data[$paramName];
|
$params[] = $data[$paramName];
|
||||||
// don't run set for a parameter passed to the constructor
|
// don't run set for a parameter passed to the constructor
|
||||||
unset($data[$paramName]);
|
unset($data[$paramName]);
|
||||||
} elseif (!$constructorParameter->isOptional()) {
|
} elseif ($constructorParameter->isOptional()) {
|
||||||
|
$params[] = $constructorParameter->getDefaultValue();
|
||||||
|
} else {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
'Cannot create an instance of '.$class.
|
'Cannot create an instance of '.$class.
|
||||||
' from serialized data because its constructor requires '.
|
' from serialized data because its constructor requires '.
|
||||||
|
@ -105,6 +105,16 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('bar', $obj->getBar());
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
||||||
|
{
|
||||||
|
$obj = $this->normalizer->denormalize(
|
||||||
|
array('foo' => 'test', 'baz' => array(1, 2, 3)),
|
||||||
|
__NAMESPACE__.'\GetConstructorOptionalArgsDummy', 'any');
|
||||||
|
$this->assertEquals('test', $obj->getFoo());
|
||||||
|
$this->assertEquals(array(), $obj->getBar());
|
||||||
|
$this->assertEquals(array(1, 2, 3), $obj->getBaz());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideCallbacks
|
* @dataProvider provideCallbacks
|
||||||
*/
|
*/
|
||||||
@ -313,3 +323,37 @@ class GetConstructorDummy
|
|||||||
abstract class SerializerNormalizer implements SerializerInterface, NormalizerInterface
|
abstract class SerializerNormalizer implements SerializerInterface, NormalizerInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GetConstructorOptionalArgsDummy
|
||||||
|
{
|
||||||
|
protected $foo;
|
||||||
|
private $bar;
|
||||||
|
private $baz;
|
||||||
|
|
||||||
|
public function __construct($foo, $bar = array(), $baz = array())
|
||||||
|
{
|
||||||
|
$this->foo = $foo;
|
||||||
|
$this->bar = $bar;
|
||||||
|
$this->baz = $baz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFoo()
|
||||||
|
{
|
||||||
|
return $this->foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBar()
|
||||||
|
{
|
||||||
|
return $this->bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBaz()
|
||||||
|
{
|
||||||
|
return $this->baz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function otherMethod()
|
||||||
|
{
|
||||||
|
throw new \RuntimeException("Dummy::otherMethod() should not be called");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user