diff --git a/src/Symfony/Component/Config/Definition/NumericNode.php b/src/Symfony/Component/Config/Definition/NumericNode.php index df45f2ebef..f062ae07cc 100644 --- a/src/Symfony/Component/Config/Definition/NumericNode.php +++ b/src/Symfony/Component/Config/Definition/NumericNode.php @@ -39,10 +39,10 @@ class NumericNode extends ScalarNode $errorMsg = null; if (isset($this->min) && $value < $this->min) { - $errorMsg = sprintf('The value %s is too small for path "%s". Should be greater than: %s', $value, $this->getPath(), $this->min); + $errorMsg = sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s', $value, $this->getPath(), $this->min); } if (isset($this->max) && $value > $this->max) { - $errorMsg = sprintf('The value %s is too big for path "%s". Should be less than: %s', $value, $this->getPath(), $this->max); + $errorMsg = sprintf('The value %s is too big for path "%s". Should be less than or equal to %s', $value, $this->getPath(), $this->max); } if (isset($errorMsg)) { $ex = new InvalidConfigurationException($errorMsg); diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php index 1cb08f90e9..cf0813ace0 100755 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php @@ -39,7 +39,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than: 5 + * @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than or equal to 5 */ public function testIntegerMinAssertion() { @@ -49,7 +49,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than: 3 + * @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than or equal to 3 */ public function testIntegerMaxAssertion() { @@ -66,7 +66,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than: 500 + * @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than or equal to 500 */ public function testFloatMinAssertion() { @@ -76,7 +76,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than: 0.3 + * @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than or equal to 0.3 */ public function testFloatMaxAssertion() { diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index 8b42b352a1..f24b504a40 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -167,7 +167,7 @@ class ProgressHelper extends Helper /** * Sets the redraw frequency. * - * @param int $freq The frequency in seconds + * @param int $freq The frequency in steps */ public function setRedrawFrequency($freq) { @@ -344,12 +344,12 @@ class ProgressHelper extends Helper $vars = array(); $percent = 0; if ($this->max > 0) { - $percent = (double) round($this->current / $this->max, 2); + $percent = (double) $this->current / $this->max; } if (isset($this->formatVars['bar'])) { $completeBars = 0; - $emptyBars = 0; + if ($this->max > 0) { $completeBars = floor($percent * $this->barWidth); } else { @@ -384,7 +384,7 @@ class ProgressHelper extends Helper } if (isset($this->formatVars['percent'])) { - $vars['percent'] = str_pad($percent * 100, $this->widths['percent'], ' ', STR_PAD_LEFT); + $vars['percent'] = str_pad(floor($percent * 100), $this->widths['percent'], ' ', STR_PAD_LEFT); } return $vars; diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php index abb8d0b681..9f8ced1e00 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php @@ -151,6 +151,18 @@ class ProgressHelperTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->generateOutput(' 3 [■■■>------------------------]'), stream_get_contents($output->getStream())); } + public function testPercentNotHundredBeforeComplete() + { + $progress = new ProgressHelper(); + $progress->start($output = $this->getOutputStream(), 200); + $progress->display(); + $progress->advance(199); + $progress->advance(); + + rewind($output->getStream()); + $this->assertEquals($this->generateOutput(' 0/200 [>---------------------------] 0%').$this->generateOutput(' 199/200 [===========================>] 99%').$this->generateOutput(' 200/200 [============================] 100%'), stream_get_contents($output->getStream())); + } + protected function getOutputStream() { return new StreamOutput(fopen('php://memory', 'r+', false)); diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 7284be3985..e5ccab0009 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -89,7 +89,7 @@ class JsonResponse extends Response public function setData($data = array()) { // Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML. - $this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_NUMERIC_CHECK); + $this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT ); return $this->update(); } diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index 4f237c2215..882bc2b0f2 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -130,7 +130,11 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer private function templateExists($template) { if ($this->templating instanceof EngineInterface) { - return $this->templating->exists($template); + try { + return $this->templating->exists($template); + } catch (\InvalidArgumentException $e) { + return false; + } } $loader = $this->templating->getLoader(); diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index 9725a5cd64..2c8d58f956 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -60,7 +60,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer $attributes = $reference->attributes; $reference->attributes = array(); $uri = $this->generateFragmentUri($uri, $request); - $reference->attributes = $attributes; + $reference->attributes = array_merge($attributes, $reference->attributes); } $subRequest = $this->createSubRequest($uri, $request); diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php index 53baf5ab51..af17e10464 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -50,7 +50,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase $this->assertEquals('', $strategy->render('/foo', Request::create('/'))->getContent()); } - public function testRenderWhithDefault() + public function testRenderWithDefault() { // only default $strategy = new HIncludeFragmentRenderer(); @@ -79,4 +79,17 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase $strategy = new HIncludeFragmentRenderer(); $this->assertEquals('default', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent()); } + + public function testRenderWithDefaultText() + { + $engine = $this->getMock('Symfony\\Component\\Templating\\EngineInterface'); + $engine->expects($this->once()) + ->method('exists') + ->with('default') + ->will($this->throwException(new \InvalidArgumentException())); + + // only default + $strategy = new HIncludeFragmentRenderer($engine); + $this->assertEquals('default', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent()); + } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index a6cfba211a..f405dae09c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -51,7 +51,7 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase $object = new \stdClass(); $subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller'); - $subRequest->attributes->replace(array('object' => $object)); + $subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller')); $subRequest->headers->set('x-forwarded-for', array('127.0.0.1')); $subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1'); diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index 562ba1011d..4e71e99c4e 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -164,7 +164,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface /** * Whether this request requires authentication. * - * The default implementation only processed requests to a specific path, + * The default implementation only processes requests to a specific path, * but a subclass could change this to only authenticate requests where a * certain parameters is present. * diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 680b50349c..4905e71ac9 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -304,14 +304,16 @@ class Parser $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine); - while ($this->moveToNextLine()) { + // We are in string block (ie. after a line ending with "|") + $removeComments = !preg_match('~(.*)\|[\s]*$~', $this->currentLine); + while ($this->moveToNextLine()) { if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) { $this->moveToPreviousLine(); break; } - if ($this->isCurrentLineEmpty()) { + if ($removeComments && $this->isCurrentLineEmpty() || $this->isCurrentLineBlank()) { if ($this->isCurrentLineBlank()) { $data[] = substr($this->currentLine, $newIndent); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index a8d28b9131..a74bd3ee87 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -522,6 +522,63 @@ EOF; $this->assertEquals(array('hash' => null), Yaml::parse($input)); } + + public function testStringBlockWithComments() + { + $this->assertEquals(array('content' => << +

title

+ + +footer # comment3 +EOT + ), Yaml::parse(<< +

title

+ + + footer # comment3 +EOF + )); + } + + public function testNestedStringBlockWithComments() + { + $this->assertEquals(array(array('content' => << +

title

+ + +footer # comment3 +EOT + )), Yaml::parse(<< +

title

+ + + footer # comment3 +EOF + )); + } } class B