Merge branch '2.8' into 3.3

* 2.8:
  [travis] update to trusty
  Fix ArrayInput::toString() for VALUE_IS_ARRAY options/args
  [ExpressionLanguage] throws an exception on calling uncallable method
This commit is contained in:
Nicolas Grekas 2017-09-06 18:40:18 +02:00
commit 87b3b1a685
7 changed files with 41 additions and 13 deletions

View File

@ -1,6 +1,6 @@
language: php language: php
dist: precise dist: trusty
sudo: false sudo: false
git: git:
@ -20,10 +20,8 @@ env:
matrix: matrix:
include: include:
# Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
- php: hhvm-3.18 - php: hhvm-3.18
sudo: required sudo: required
dist: trusty
group: edge group: edge
- php: 5.5 - php: 5.5
- php: 5.6 - php: 5.6
@ -104,7 +102,6 @@ before_install:
echo opcache.enable_cli = 1 >> $INI echo opcache.enable_cli = 1 >> $INI
echo hhvm.jit = 0 >> $INI echo hhvm.jit = 0 >> $INI
echo apc.enable_cli = 1 >> $INI echo apc.enable_cli = 1 >> $INI
echo extension = ldap.so >> $INI
echo extension = redis.so >> $INI echo extension = redis.so >> $INI
echo extension = memcached.so >> $INI echo extension = memcached.so >> $INI
[[ $PHP = 5.* ]] && echo extension = memcache.so >> $INI [[ $PHP = 5.* ]] && echo extension = memcache.so >> $INI

View File

@ -112,9 +112,15 @@ class ArrayInput extends Input
$params = array(); $params = array();
foreach ($this->parameters as $param => $val) { foreach ($this->parameters as $param => $val) {
if ($param && '-' === $param[0]) { if ($param && '-' === $param[0]) {
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : ''); if (is_array($val)) {
foreach ($val as $v) {
$params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
}
} else {
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
}
} else { } else {
$params[] = $this->escapeToken($val); $params[] = is_array($val) ? array_map(array($this, 'escapeToken'), $val) : $this->escapeToken($val);
} }
} }

View File

@ -167,5 +167,8 @@ class ArrayInputTest extends TestCase
{ {
$input = new ArrayInput(array('-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C")); $input = new ArrayInput(array('-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"));
$this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input); $this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
$input = new ArrayInput(array('-b' => array('bval_1', 'bval_2'), '--f' => array('fval_1', 'fval_2')));
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
} }
} }

View File

@ -82,8 +82,11 @@ class GetAttrNode extends Node
if (!is_object($obj)) { if (!is_object($obj)) {
throw new \RuntimeException('Unable to get a property on a non-object.'); throw new \RuntimeException('Unable to get a property on a non-object.');
} }
if (!is_callable($toCall = array($obj, $this->nodes['attribute']->attributes['value']))) {
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], get_class($obj)));
}
return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['value']), $this->nodes['arguments']->evaluate($functions, $values)); return call_user_func_array($toCall, $this->nodes['arguments']->evaluate($functions, $values));
case self::ARRAY_CALL: case self::ARRAY_CALL:
$array = $this->nodes['node']->evaluate($functions, $values); $array = $this->nodes['node']->evaluate($functions, $values);

View File

@ -242,6 +242,16 @@ class ExpressionLanguageTest extends TestCase
$registerCallback($el); $registerCallback($el);
} }
/**
* @expectedException \RuntimeException
* @expectedExceptionMessageRegExp /Unable to call method "\w+" of object "\w+"./
*/
public function testCallBadCallable()
{
$el = new ExpressionLanguage();
$el->evaluate('foo.myfunction()', array('foo' => new \stdClass()));
}
/** /**
* @dataProvider getRegisterCallbacks * @dataProvider getRegisterCallbacks
* @expectedException \LogicException * @expectedException \LogicException

View File

@ -146,12 +146,17 @@ class JsonResponse extends Response
$data = json_encode($data, $this->encodingOptions); $data = json_encode($data, $this->encodingOptions);
} else { } else {
try { try {
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable if (!interface_exists('JsonSerializable', false)) {
// objects in a new exception that needs to be removed. set_error_handler(function () { return false; });
// Fortunately, PHP 5.5 and up do not trigger any warning anymore. $data = @json_encode($data, $this->encodingOptions);
$data = json_encode($data, $this->encodingOptions); restore_error_handler();
} else {
$data = json_encode($data, $this->encodingOptions);
}
} catch (\Exception $e) { } catch (\Exception $e) {
if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) { if (!interface_exists('JsonSerializable', false)) {
restore_error_handler();
} elseif ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
throw $e->getPrevious() ?: $e; throw $e->getPrevious() ?: $e;
} }
throw $e; throw $e;

View File

@ -228,6 +228,10 @@ class JsonResponseTest extends TestCase
*/ */
public function testSetContentJsonSerializeError() public function testSetContentJsonSerializeError()
{ {
if (!interface_exists('JsonSerializable', false)) {
$this->markTestSkipped('JsonSerializable is required.');
}
$serializable = new JsonSerializableObject(); $serializable = new JsonSerializableObject();
JsonResponse::create($serializable); JsonResponse::create($serializable);
@ -242,7 +246,7 @@ class JsonResponseTest extends TestCase
} }
} }
if (interface_exists('JsonSerializable')) { if (interface_exists('JsonSerializable', false)) {
class JsonSerializableObject implements \JsonSerializable class JsonSerializableObject implements \JsonSerializable
{ {
public function jsonSerialize() public function jsonSerialize()