8000 Merge branch '3.1' into 3.2 · symfony/symfony@f4a6359 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4a6359

Browse files
committed
Merge branch '3.1' into 3.2
* 3.1: fixed @return when returning this or static override property constraints in child class removed unneeded comment [Console] improved code coverage of Command class [FrameworkBundle] Make TemplateController working without the Templating component Only count on arrays or countables to avoid warnings in PHP 7.2
2 parents 59dc976 + 4c453f6 commit f4a6359

File tree

87 files changed

+528
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+528
-389
lines changed

src/Symfony/Bridge/Twig/NodeVisitor/Scope.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(Scope $parent = null)
4242
/**
4343
* Opens a new child scope.
4444
*
45-
* @return Scope
45+
* @return self
4646
*/
4747
public function enter()
4848
{
@@ -52,7 +52,7 @@ public function enter()
5252
/**
5353
* Closes current scope and returns parent one.
5454
*
55-
* @return Scope|null
55+
* @return self|null
5656
*/
5757
public function leave()
5858
{
@@ -67,7 +67,7 @@ public function leave()
6767
* @param string $key
6868
* @param mixed $value
6969
*
70-
* @return Scope Current scope
70+
* @return $this
7171
*
7272
* @throws \LogicException
7373
*/

src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ class TemplateController implements ContainerAwareInterface
3636
*/
3737
public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
3838
{
39-
/** @var $response \Symfony\Component\HttpFoundation\Response */
40-
$response = $this->container->get('templating')->renderResponse($template);
39+
if ($this->container->has('templating')) {
40+
$response = $this->container->get('templating')->renderResponse($template);
41+
} elseif ($this->container->has('twig')) {
42+
$response = new Response($this->container->get('twig')->render($template));
43+
} else {
44+
throw new \LogicException('You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.');
45+
}
4146

4247
if ($maxAge) {
4348
$response->setMaxAge($maxAge);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
13+
14+
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
15+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
16+
use Symfony\Component\HttpFoundation\Response;
17+
18+
/**
19+
* @author Kévin Dunglas <dunglas@gmail.com>
20+
*/
21+
class TemplateControllerTest extends TestCase
22+
{
23+
public function testTwig()
24+
{
25+
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
26+
$twig->expects($this->once())->method('render')->willReturn('bar');
27+
28+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
29+
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
30+
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
31+
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
32+
33+
$controller = new TemplateController();
34+
$controller->setContainer($container);
35+
36+
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
37+
}
38+
39+
public function testTemplating()
40+
{
41+
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
42+
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
43+
44+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
45+
$container->expects($this->at(0))->method('has')->willReturn(true);
46+
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
47+
48+
$controller = new TemplateController();
49+
$controller->setContainer($container);
50+
51+
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
52+
}
53+
54+
/**
55+
* @expectedException \LogicException
56+
* @expectedExceptionMessage You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.
57+
*/
58+
public function testNoTwigNorTemplating()
59+
{
60+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
61+
$container->expects($this->at(0))->method('has')->willReturn(false);
62+
$container->expects($this->at(1))->method('has')->willReturn(false);
63+
64+
$controller = new TemplateController();
65+
$controller->setContainer($container);
66+
67+
$controller->templateAction('mytemplate')->getContent();
68+
}
69+
}

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __toString()
121121
* @param string $cookie A Set-Cookie header value
122122
* @param string $url The base URL
123123
*
124-
* @return Cookie A Cookie instance
124+
* @return static
125125
*
126126
* @throws \InvalidArgumentException
127127
*/

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function prototype($type)
8686
* If this function has been called and the node is not set during the finalization
8787
* phase, it's default value will be derived from its children default values.
8888
*
89-
* @return ArrayNodeDefinition
89+
* @return $this
9090
*/
9191
public function addDefaultsIfNotSet()
9292
{
@@ -102,7 +102,7 @@ public function addDefaultsIfNotSet()
102102
*
103103
* This method is applicable to prototype nodes only.
104104
*
105-
* @return ArrayNodeDefinition
105+
* @return $this
106106
*/
107107
public function addDefaultChildrenIfNoneSet($children = null)
108108
{
@@ -116,7 +116,7 @@ public function addDefaultChildrenIfNoneSet($children = null)
116116
*
117117
* This method is applicable to prototype nodes only.
118118
*
119-
* @return ArrayNodeDefinition
119+
* @return $this
120120
*/
121121
public function requiresAtLeastOneElement()
122122
{
@@ -130,7 +130,7 @@ public function requiresAtLeastOneElement()
130130
*
131131
* If used all keys have to be defined in the same configuration file.
132132
*
133-
* @return ArrayNodeDefinition
133+
* @return $this
134134
*/
135135
public function disallowNewKeysInSubsequentConfigs()
136136
{
@@ -145,7 +145,7 @@ public function disallowNewKeysInSubsequentConfigs()
145145
* @param string $singular The key to remap
146146
* @param string $plural The plural of the key for irregular plurals
147147
*
148-
* @return ArrayNodeDefinition
148+
* @return $this
149149
*/
150150
public function fixXmlConfig($singular, $plural = null)
151151
{
@@ -180,7 +180,7 @@ public function fixXmlConfig($singular, $plural = null)
180180
* @param string $name The name of the key
181181
* @param bool $removeKeyItem Whether or not the key item should be removed
182182
*
183-
* @return ArrayNodeDefinition
183+
* @return $this
184184
*/
185185
public function useAttributeAsKey($name, $removeKeyItem = true)
186186
{
@@ -195,7 +195,7 @@ public function useAttributeAsKey($name, $removeKeyItem = true)
195195
*
196196
* @param bool $allow
197197
*
198-
* @return ArrayNodeDefinition
198+
* @return $this
199199
*/
200200
public function canBeUnset($allow = true)
201201
{
@@ -217,7 +217,7 @@ public function canBeUnset($allow = true)
217217
* enableableArrayNode: {enabled: false, ...} # The config is disabled
218218
* enableableArrayNode: false # The config is disabled
219219
*
220-
* @return ArrayNodeDefinition
220+
* @return $this
221221
*/
222222
public function canBeEnabled()
223223
{
@@ -247,7 +247,7 @@ public function canBeEnabled()
247247
*
248248
* By default, the section is enabled.
249249
*
250-
* @return ArrayNodeDefinition
250+
* @return $this
251251
*/
252252
public function canBeDisabled()
253253
{
@@ -267,7 +267,7 @@ public function canBeDisabled()
267267
/**
268268
* Disables the deep merging of the node.
269269
*
270-
* @return ArrayNodeDefinition
270+
* @return $this
271271
*/
272272
public function performNoDeepMerging()
273273
{
@@ -287,7 +287,7 @@ public function performNoDeepMerging()
287287
*
288288
* @param bool $remove Whether to remove the extra keys
289289
*
290-
* @return ArrayNodeDefinition
290+
* @return $this
291291
*/
292292
public function ignoreExtraKeys($remove = true)
293293
{
@@ -302,7 +302,7 @@ public function ignoreExtraKeys($remove = true)
302302
*
303303
* @param bool $bool Whether to enable key normalization
304304
*
305-
* @return ArrayNodeDefinition
305+
* @return $this
306306
*/
307307
public function normalizeKeys($bool)
308308
{
@@ -324,7 +324,7 @@ public function normalizeKeys($bool)
324324
*
325325
* @param NodeDefinition $node A NodeDefinition instance
326326
*
327-
* @return ArrayNodeDefinition This node
327+
* @return $this
328328
*/
329329
public function append(NodeDefinition $node)
330330
{

src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EnumNodeDefinition extends ScalarNodeDefinition
2525
/**
2626
* @param array $values
2727
*
28-
* @return EnumNodeDefinition|$this
28+
* @return $this
2929
*/
3030
public function values(array $values)
3131
{

src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(NodeDefinition $node)
4040
*
4141
* @param \Closure $then
4242
*
43-
* @return ExprBuilder
43+
* @return $this
4444
*/
4545
public function always(\Closure $then = null)
4646
{
@@ -60,7 +60,7 @@ public function always(\Closure $then = null)
6060
*
6161
* @param \Closure $closure
6262
*
63-
* @return ExprBuilder
63+
* @return $this
6464
*/
6565
public function ifTrue(\Closure $closure = null)
6666
{
@@ -76,7 +76,7 @@ public function ifTrue(\Closure $closure = null)
7676
/**
7777
* Tests if the value is a string.
7878
*
79-
* @return ExprBuilder
79+
* @return $this
8080
*/
8181
public function ifString()
8282
{
@@ -88,7 +88,7 @@ public function ifString()
8888
/**
8989
* Tests if the value is null.
9090
*
91-
* @return ExprBuilder
91+
* @return $this
9292
*/
9393
public function ifNull()
9494
{
@@ -112,7 +112,7 @@ public function ifEmpty()
112112
/**
113113
* Tests if the value is an array.
114114
*
115-
* @return ExprBuilder
115+
* @return $this
116116
*/
117117
public function ifArray()
118118
{
@@ -126,7 +126,7 @@ public function ifArray()
126126
*
127127
* @param array $array
128128
*
129-
* @return ExprBuilder
129+
* @return $this
130130
*/
131131
public function ifInArray(array $array)
132132
{
@@ -140,7 +140,7 @@ public function ifInArray(array $array)
140140
*
141141
* @param array $array
142142
*
143-
* @return ExprBuilder
143+
* @return $this
144144
*/
145145
public function ifNotInArray(array $array)
146146
{
@@ -154,7 +154,7 @@ public function ifNotInArray(array $array)
154154
*
155155
* @param \Closure $closure
156156
*
157-
* @return ExprBuilder
157+
* @return $this
158158
*/
159159
public function then(\Closure $closure)
160160
{
@@ -166,7 +166,7 @@ public function then(\Closure $closure)
166166
/**
167167
* Sets a closure returning an empty array.
168168
*
169-
* @return ExprBuilder
169+
* @return $this
170170
*/
171171
public function thenEmptyArray()
172172
{
@@ -182,7 +182,7 @@ public function thenEmptyArray()
182182
*
183183
* @param string $message
184184
*
185-
* @return ExprBuilder
185+
* @return $this
186186
*
187187
* @throws \InvalidArgumentException
188188
*/
@@ -196,7 +196,7 @@ public function thenInvalid($message)
196196
/**
197197
* Sets a closure unsetting this key of the array at validation time.
198198
*
199-
* @return ExprBuilder
199+
* @return $this
200200
*
201201
* @throws UnsetKeyException
202202
*/

src/Symfony/Component/Config/Definition/Builder/MergeBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(NodeDefinition $node)
3737
*
3838
* @param bool $allow
3939
*
40-
* @return MergeBuilder
40+
* @return $this
4141
*/
4242
public function allowUnset($allow = true)
4343
{
@@ -51,7 +51,7 @@ public function allowUnset($allow = true)
5151
*
5252
* @param bool $deny Whether the overwriting is forbidden or not
5353
*
54-
* @return MergeBuilder
54+
* @return $this
5555
*/
5656
public function denyOverwrite($deny = true)
5757
{

src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct()
4242
*
4343
* @param ParentNodeDefinitionInterface $parent The parent node
4444
*
45-
* @return NodeBuilder This node builder
45+
* @return $this
4646
*/
4747
public function setParent(ParentNodeDefinitionInterface $parent = null)
4848
{
@@ -182,7 +182,7 @@ public function node($name, $type)
182182
*
183183
* @param NodeDefinition $node
184184
*
185-
* @return NodeBuilder This node builder
185+
* @return $this
186186
*/
187187
public function append(NodeDefinition $node)
188188
{
@@ -207,7 +207,7 @@ public function append(NodeDefinition $node)
207207
* @param string $type The name of the type
208208
* @param string $class The fully qualified name the node definition class
209209
*
210-
* @return NodeBuilder This node builder
210+
* @return $this
211211
*/
212212
public function setNodeClass($type, $class)
213213
{

0 commit comments

Comments
 (0)
0