8000 Merge branch '2.7' into 2.8 · symfony/symfony@4546377 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4546377

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [TwigBundle] fixed usage when Templating is not installed [Validator] Check cascasdedGroups for being countable [Filesystem] Check that the directory is writable after created it in dumpFile() [HttpFoundation] Improved set cookie header tests [Console] increased code coverage of Output classes
2 parents 5518f6a + 6bd7840 commit 4546377

File tree

10 files changed

+91
-22
lines changed

10 files changed

+91
-22
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function process(ContainerBuilder $container)
4545
if ($container->has('form.extension')) {
4646
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
4747
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
48-
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
48+
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
4949
}
5050

5151
if ($container->has('fragment.handler')) {
@@ -88,11 +88,13 @@ public function process(ContainerBuilder $container)
8888
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
8989
}
9090

91-
if (!$container->has('templating')) {
92-
$loader = $container->getDefinition('twig.loader.native_filesystem');
93-
$loader->addTag('twig.loader');
94-
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
91+
$twigLoader = $container->getDefinition('twig.loader.native_filesystem');
92+
if ($container->has('templating')) {
93+
$loader = $container->getDefinition('twig.loader.filesystem');
94+
$loader->setMethodCalls($twigLoader->getMethodCalls());
9595

96+
$twigLoader->clearTag('twig.loader');
97+
} else {
9698
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
9799
}
98100

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function load(array $configs, ContainerBuilder $container)
7878
$envConfiguratorDefinition->replaceArgument(4, $config['number_format']['decimal_point']);
7979
$envConfiguratorDefinition->replaceArgument(5, $config['number_format']['thousands_separator']);
8080

81-
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
81+
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.native_filesystem');
8282

8383
// register user-configured paths
8484
foreach ($config['paths'] as $path => $namespace) {

src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
<tag name="twig.loader"/>
1111
</service>
1212

13-
<service id="twig.loader" alias="twig.loader.filesystem" />
14-
1513
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
1614
<argument type="service" id="twig" />
1715
<argument type="service" id="templating.name_parser" />

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
6868
<argument type="collection" />
69+
<tag name="twig.loader"/>
6970
</service>
7071

7172
<service id="twig.loader.chain" class="%twig.loader.chain.class%" public="false"/>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function testTwigLoaderPaths($format)
187187
$this->loadFromFile($container, 'extra', $format);
188188
$this->compileContainer($container);
189189

190-
$def = $container->getDefinition('twig.loader.filesystem');
190+
$def = $container->getDefinition('twig.loader.native_filesystem');
191191
$paths = array();
192192
foreach ($def->getMethodCalls() as $call) {
193193
if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) {

src/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Tests\Output;
1313

14+
use Symfony\Component\Console\Formatter\OutputFormatter;
1415
use Symfony\Component\Console\Output\ConsoleOutput;
1516
use Symfony\Component\Console\Output\Output;
1617

@@ -22,4 +23,19 @@ public function testConstructor()
2223
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
2324
$this->assertSame($output->getFormatter(), $output->getErrorOutput()->getFormatter(), '__construct() takes a formatter or null as the third argument');
2425
}
26+
27+
public function testSetFormatter()
28+
{
29+
$output = new ConsoleOutput();
30+
$outputFormatter = new OutputFormatter();
31+
$output->setFormatter($outputFormatter);
32+
$this->assertSame($outputFormatter, $output->getFormatter());
33+
}
34+
35+
public function testSetVerbosity()
36+
{
37+
$output = new ConsoleOutput();
38+
$output->setVerbosity(Output::VERBOSITY_VERBOSE);
39+
$this->assertSame(Output::VERBOSITY_VERBOSE, $output->getVerbosity());
40+
}
2541
}

src/Symfony/Component/Console/Tests/Output/NullOutputTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Console\Tests\Output;
1313

14+
use Symfony\Component\Console\Formatter\OutputFormatter;
1415
use Symfony\Component\Console\Output\NullOutput;
16+
use Symfony\Component\Console\Output\Output;
1517
use Symfony\Component\Console\Output\OutputInterface;
1618

1719
class NullOutputTest extends \PHPUnit_Framework_TestCase
@@ -36,4 +38,50 @@ public function testVerbosity()
3638
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
3739
$this->assertSame(OutputInterface::VERBOSITY_QUIET, $output->getVerbosity(), '->getVerbosity() always returns VERBOSITY_QUIET for NullOutput');
3840
}
41+
42+
public function testSetFormatter()
43+
{
44+
$output = new NullOutput();
45+
$outputFormatter = new OutputFormatter();
46+
$output->setFormatter($outputFormatter);
47+
$this->assertNotSame($outputFormatter, $output->getFormatter());
48+
}
49+
50+
public function testSetVerbosity()
51+
{
52+
$output = new NullOutput();
53+
$output->setVerbosity(Output::VERBOSITY_NORMAL);
54+
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity());
55+
}
56+
57+
public function testSetDecorated()
58+
{
59+
$output = new NullOutput();
60+
$output->setDecorated(true);
61+
$this->assertFalse($output->isDecorated());
62+
}
63+
64+
public function testIsQuiet()
65+
{
66+
$output = new NullOutput();
67+
$this->assertTrue($output->isQuiet());
68+
}
69+
70+
public function testIsVerbose()
71+
{
72+
$output = new NullOutput();
73+
$this->assertFalse($output->isVerbose());
74+
}
75+
76+
public function testIsVeryVerbose()
77+
{
78+
$output = new NullOutput();
79+
$this->assertFalse($output->isVeryVerbose());
80+
}
81+
82+
public function testIsDebug()
83+
{
84+
$output = new NullOutput();
85+
$this->assertFalse($output->isDebug());
86+
}
3987
}

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,9 @@ public function dumpFile($filename, $content, $mode = 0666)
550550

551551
if (!is_dir($dir)) {
552552
$this->mkdir($dir);
553-
} elseif (!is_writable($dir)) {
553+
}
554+
555+
if (!is_writable($dir)) {
554556
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
555557
}
556558

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public function testToStringIncludesCookieHeaders()
116116
$bag = new ResponseHeaderBag(array());
117117
$bag->setCookie(new Cookie('foo', 'bar'));
118118

119-
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', explode("\r\n", $bag->__toString()));
119+
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
120120

121121
$bag->clearCookie('foo');
122122

123-
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; httponly#m', $bag->__toString());
123+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; httponly', $bag);
124124
}
125125

126126
public function testClearCookieSecureNotHttpOnly()
@@ -129,7 +129,7 @@ public function testClearCookieSecureNotHttpOnly()
129129

130130
$bag->clearCookie('foo', '/', null, true, false);
131131

132-
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; secure#m', $bag->__toString());
132+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; secure', $bag);
133133
}
134134

135135
public function testReplace()
@@ -165,11 +165,10 @@ public function testCookiesWithSameNames()
165165

166166
$this->assertCount(4, $bag->getCookies());
167167

168-
$headers = explode("\r\n", $bag->__toString());
169-
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
170-
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
171-
$this->assertContains('Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly', $headers);
172-
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', $headers);
168+
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
169+
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
170+
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
171+
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
173172

174173
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
175174
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));
@@ -223,7 +222,7 @@ public function testGetCookiesWithInvalidArgument()
223222
{
224223
$bag = new ResponseHeaderBag();
225224

226-
$cookies = $bag->getCookies('invalid_argument');
225+
$bag->getCookies('invalid_argument');
227226
}
228227

229228
/**
@@ -294,4 +293,9 @@ public function provideMakeDispositionFail()
294293
array('attachment', 'föö.html'),
295294
);
296295
}
296+
297+
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
298+
{
299+
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
300+
}
297301
}

src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,7 @@ private function validateGenericNode($value, $object, $cacheKey, MetadataInterfa
746746
// The $cascadedGroups property is set, if the "Default" group is
747747
// overridden by a group sequence
748748
// See validateClassNode()
749-
$cascadedGroups = count($cascadedGroups) > 0
750-
? $cascadedGroups
751-
: $groups;
749+
$cascadedGroups = null !== $cascadedGroups && count($cascadedGroups) > 0 ? $cascadedGroups : $groups;
752750

753751
if (is_array($value)) {
754752
// Arrays are always traversed, independent of the specified

0 commit comments

Comments
 (0)
0