From 166e1750bcdabb3b674543c20b2f397790833a6d Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 13 Aug 2015 19:30:11 +0800 Subject: [PATCH 1/6] [expression-language] Code Cleanup for GetAttrNode Use ``$this->nodes['attribute']->attributes['value']`` to replace ``$this->nodes['attribute']->evaluate($functions, $values)`` for method call and property call. | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a --- src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php index c7f9c41113..b3f98bf565 100644 --- a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php +++ b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php @@ -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); From 6a6e7f394726046d3071eee309aba956c2419f9b Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 22 Sep 2015 15:04:33 +0200 Subject: [PATCH 2/6] [VarDumper] Fix dump comparison on large arrays --- .../VarDumper/Test/VarDumperTestTrait.php | 1 + .../Tests/Test/VarDumpTestTraitRequire54.php | 41 +++++++++++++++++++ .../Tests/Test/VarDumpTestTraitTest.php | 16 ++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitRequire54.php create mode 100644 src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitTest.php diff --git a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php index 0d1489ab44..2d19a148d0 100644 --- a/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php +++ b/src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php @@ -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)); diff --git a/src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitRequire54.php b/src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitRequire54.php new file mode 100644 index 0000000000..240cc926aa --- /dev/null +++ b/src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitRequire54.php @@ -0,0 +1,41 @@ + + * + * 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 .= << array:4 [ + 0 => "a" + 1 => "b" + 2 => "c" + 3 => "d" + ]\n +EODUMP; + } + $expected .= "]\n"; + + $this->assertDumpEquals($expected, $data); + } +} diff --git a/src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitTest.php b/src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitTest.php new file mode 100644 index 0000000000..21ef14d9ff --- /dev/null +++ b/src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitTest.php @@ -0,0 +1,16 @@ + + * + * 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'; +} + From 16e09d3eaafa53e7187030fd5761fc27c25ff90e Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 23 Sep 2015 21:45:13 -0400 Subject: [PATCH 3/6] Fixing test locations --- .../Tests/Authorization}/Voter/AbstractVoterTest.php | 2 +- .../Core => Core/Tests}/LegacySecurityContextInterfaceTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Symfony/Component/Security/{Tests/Core/Authentication => Core/Tests/Authorization}/Voter/AbstractVoterTest.php (97%) rename src/Symfony/Component/Security/{Tests/Core => Core/Tests}/LegacySecurityContextInterfaceTest.php (94%) diff --git a/src/Symfony/Component/Security/Tests/Core/Authentication/Voter/AbstractVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php similarity index 97% rename from src/Symfony/Component/Security/Tests/Core/Authentication/Voter/AbstractVoterTest.php rename to src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php index af7b82f35d..5e2b35eca7 100644 --- a/src/Symfony/Component/Security/Tests/Core/Authentication/Voter/AbstractVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -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\Authorization\Voter\AbstractVoter; diff --git a/src/Symfony/Component/Security/Tests/Core/LegacySecurityContextInterfaceTest.php b/src/Symfony/Component/Security/Core/Tests/LegacySecurityContextInterfaceTest.php similarity index 94% rename from src/Symfony/Component/Security/Tests/Core/LegacySecurityContextInterfaceTest.php rename to src/Symfony/Component/Security/Core/Tests/LegacySecurityContextInterfaceTest.php index 5225eb52d6..a45ecf956d 100644 --- a/src/Symfony/Component/Security/Tests/Core/LegacySecurityContextInterfaceTest.php +++ b/src/Symfony/Component/Security/Core/Tests/LegacySecurityContextInterfaceTest.php @@ -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; From 7d674c21355251427d996e5c48f24f03693f9888 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 25 Sep 2015 08:52:54 +0200 Subject: [PATCH 4/6] fixed tests --- .../Core/Tests/Authorization/Voter/AbstractVoterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php index 5e2b35eca7..1341093189 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -66,7 +66,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', ); } From 9a188c521572121997ad8a55498e4f13c22b77fd Mon Sep 17 00:00:00 2001 From: Mathieu Lemoine Date: Wed, 23 Sep 2015 15:41:05 -0400 Subject: [PATCH 5/6] [OptionsResolver] Fix catched exception along the dependency tree mistakenly detects cyclic dependencies --- .../OptionsResolver/OptionsResolver.php | 16 ++++-- .../Tests/OptionsResolver2Dot6Test.php | 50 +++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/OptionsResolver.php b/src/Symfony/Component/OptionsResolver/OptionsResolver.php index e42d7bbfd1..e0578af717 100644 --- a/src/Symfony/Component/OptionsResolver/OptionsResolver.php +++ b/src/Symfony/Component/OptionsResolver/OptionsResolver.php @@ -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 } diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 0c2dce1af4..367ee3fecd 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -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; From 945ec0e40caa1fc7427e2b7d0bb4b4d7fafddd91 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 25 Sep 2015 10:32:23 +0200 Subject: [PATCH 6/6] [Console] Fix transient HHVM test --- .../Console/Tests/Helper/ProgressBarTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index 51962f3d16..e37853e40c 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -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());