Merge branch '2.7' into 2.8

* 2.7:
  [Console] Fix transient HHVM test
  [OptionsResolver] Fix catched exception along the dependency tree mistakenly detects cyclic dependencies
  fixed tests
  Fixing test locations
  [VarDumper] Fix dump comparison on large arrays
  [expression-language] Code Cleanup for GetAttrNode
This commit is contained in:
Nicolas Grekas 2015-09-25 11:20:50 +02:00
commit 2377994b66
9 changed files with 136 additions and 7 deletions

View File

@ -14,9 +14,20 @@ namespace Symfony\Component\Console\Tests\Helper;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Tests;
class ProgressBarTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
Tests\with_clock_mock(true);
}
protected function tearDown()
{
Tests\with_clock_mock(false);
}
public function testMultipleStart()
{
$bar = new ProgressBar($output = $this->getOutputStream());

View File

@ -78,7 +78,7 @@ class GetAttrNode extends Node
throw new \RuntimeException('Unable to get a property on a non-object.');
}
return call_user_func_array(array($obj, $this->nodes['attribute']->evaluate($functions, $values)), $this->nodes['arguments']->evaluate($functions, $values));
return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['value']), $this->nodes['arguments']->evaluate($functions, $values));
case self::ARRAY_CALL:
$array = $this->nodes['node']->evaluate($functions, $values);

View File

@ -854,8 +854,13 @@ class OptionsResolver implements Options, OptionsResolverInterface
// dependency
// BEGIN
$this->calling[$option] = true;
foreach ($this->lazy[$option] as $closure) {
$value = $closure($this, $value);
try {
foreach ($this->lazy[$option] as $closure) {
$value = $closure($this, $value);
}
} catch (\Exception $e) {
unset($this->calling[$option]);
throw $e;
}
unset($this->calling[$option]);
// END
@ -953,7 +958,12 @@ class OptionsResolver implements Options, OptionsResolverInterface
// dependency
// BEGIN
$this->calling[$option] = true;
$value = $normalizer($this, $value);
try {
$value = $normalizer($this, $value);
} catch (\Exception $e) {
unset($this->calling[$option]);
throw $e;
}
unset($this->calling[$option]);
// END
}

View File

@ -1103,6 +1103,56 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
$this->resolver->resolve();
}
public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver()
{
$throw = true;
$this->resolver->setDefaults(array('catcher' => null, 'thrower' => null));
$this->resolver->setNormalizer('catcher', function (Options $options) {
try {
return $options['thrower'];
} catch(\Exception $e) {
return false;
}
});
$this->resolver->setNormalizer('thrower', function (Options $options) use (&$throw) {
if ($throw) {
$throw = false;
throw new \UnexpectedValueException('throwing');
}
return true;
});
$this->resolver->resolve();
}
public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver()
{
$throw = true;
$this->resolver->setDefault('catcher', function (Options $options) {
try {
return $options['thrower'];
} catch(\Exception $e) {
return false;
}
});
$this->resolver->setDefault('thrower', function (Options $options) use (&$throw) {
if ($throw) {
$throw = false;
throw new \UnexpectedValueException('throwing');
}
return true;
});
$this->resolver->resolve();
}
public function testInvokeEachNormalizerOnlyOnce()
{
$calls = 0;

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Tests\Core\Authentication\Voter;
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
@ -78,7 +78,7 @@ class VoterFixture extends AbstractVoter
protected function getSupportedClasses()
{
return array(
'Symfony\Component\Security\Tests\Core\Authentication\Voter\ObjectFixture',
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
);
}

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Tests\Core;
namespace Symfony\Component\Security\Core\Tests;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Security;

View File

@ -33,6 +33,7 @@ trait VarDumperTestTrait
{
$h = fopen('php://memory', 'r+b');
$cloner = new VarCloner();
$cloner->setMaxItems(-1);
$dumper = new CliDumper($h);
$dumper->setColors(false);
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));

View File

@ -0,0 +1,41 @@
<?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\VarDumper\Tests\Test;
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
class VarDumperTestTraitTest extends VarDumperTestCase
{
use VarDumperTestTrait;
public function testItComparesLargeData()
{
$howMany = 700;
$data = array_fill_keys(range(0, $howMany), array('a', 'b', 'c', 'd'));
$expected = sprintf("array:%d [\n", $howMany + 1);
for ($i = 0; $i <= $howMany; ++$i) {
$expected .= <<<EODUMP
$i => array:4 [
0 => "a"
1 => "b"
2 => "c"
3 => "d"
]\n
EODUMP;
}
$expected .= "]\n";
$this->assertDumpEquals($expected, $data);
}
}

View File

@ -0,0 +1,16 @@
<?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.
*/
// Skipping trait tests for PHP < 5.4
if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
require 'VarDumpTestTraitRequire54.php';
}