Skip to content

Commit 2c28845

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fixed obsolete getMock() usage [WebProfilerBundle] Display multiple HTTP headers in WDT
2 parents ce54f2a + 2186868 commit 2c28845

32 files changed

+97
-147
lines changed

DataCollector/RequestDataCollector.php

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
namespace Symfony\Component\HttpKernel\DataCollector;
1313

1414
use Symfony\Component\HttpFoundation\ParameterBag;
15-
use Symfony\Component\HttpFoundation\HeaderBag;
1615
use Symfony\Component\HttpFoundation\Request;
1716
use Symfony\Component\HttpFoundation\Response;
18-
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1917
use Symfony\Component\HttpKernel\KernelEvents;
2018
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
2119
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -40,12 +38,8 @@ public function __construct()
4038
public function collect(Request $request, Response $response, \Exception $exception = null)
4139
{
4240
$responseHeaders = $response->headers->all();
43-
$cookies = array();
4441
foreach ($response->headers->getCookies() as $cookie) {
45-
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
46-
}
47-
if (count($cookies) > 0) {
48-
$responseHeaders['Set-Cookie'] = $cookies;
42+
$responseHeaders['set-cookie'][] = (string) $cookie;
4943
}
5044

5145
// attributes are serialized and as they can be anything, they need to be converted to strings.
@@ -121,6 +115,18 @@ public function collect(Request $request, Response $response, \Exception $except
121115
$this->data['request_request']['_password'] = '******';
122116
}
123117

118+
foreach ($this->data as $key => $value) {
119+
if (!is_array($value)) {
120+
continue;
121+
}
122+
if ('request_headers' === $key || 'response_headers' === $key) {
123+
$value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
124+
}
125+
if ('request_server' !== $key && 'request_cookies' !== $key) {
126+
$this->data[$key] = $value;
127+
}
128+
}
129+
124130
if (isset($this->controllers[$request])) {
125131
$controller = $this->controllers[$request];
126132
if (is_array($controller)) {
@@ -183,7 +189,7 @@ public function getRequestQuery()
183189

184190
public function getRequestHeaders()
185191
{
186-
return new HeaderBag($this->data['request_headers']);
192+
return new ParameterBag($this->data['request_headers']);
187193
}
188194

189195
public function getRequestServer()
@@ -203,7 +209,7 @@ public function getRequestAttributes()
203209

204210
public function getResponseHeaders()
205211
{
206-
return new ResponseHeaderBag($this->data['response_headers']);
212+
return new ParameterBag($this->data['response_headers']);
207213
}
208214

209215
public function getSessionMetadata()
@@ -302,41 +308,4 @@ public function getName()
302308
{
303309
return 'request';
304310
}
305-
306-
private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
307-
{
308-
$cookie = sprintf('%s=%s', $name, urlencode($value));
309-
310-
if (0 !== $expires) {
311-
if (is_numeric($expires)) {
312-
$expires = (int) $expires;
313-
} elseif ($expires instanceof \DateTime) {
314-
$expires = $expires->getTimestamp();
315-
} else {
316-
$tmp = strtotime($expires);
317-
if (false === $tmp || -1 == $tmp) {
318-
throw new \InvalidArgumentException(sprintf('The "expires" cookie parameter is not valid (%s).', $expires));
319-
}
320-
$expires = $tmp;
321-
}
322-
323-
$cookie .= '; expires='.str_replace('+0000', '', \DateTime::createFromFormat('U', $expires, new \DateTimeZone('GMT'))->format('D, d-M-Y H:i:s T'));
324-
}
325-
326-
if ($domain) {
327-
$cookie .= '; domain='.$domain;
328-
}
329-
330-
$cookie .= '; path='.$path;
331-
332-
if ($secure) {
333-
$cookie .= '; secure';
334-
}
335-
336-
if ($httponly) {
337-
$cookie .= '; httponly';
338-
}
339-
340-
return $cookie;
341-
}
342311
}

Tests/Bundle/BundleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testGetContainerExtension()
3232
public function testRegisterCommands()
3333
{
3434
$cmd = new FooCommand();
35-
$app = $this->getMock('Symfony\Component\Console\Application');
35+
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
3636
$app->expects($this->once())->method('add')->with($this->equalTo($cmd));
3737

3838
$bundle = new ExtensionPresentBundle();
@@ -58,7 +58,7 @@ public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAs
5858
$container = new ContainerBuilder();
5959
$container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
6060

61-
$application = $this->getMock('Symfony\Component\Console\Application');
61+
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
6262
// add() is never called when the found command classes are already registered as services
6363
$application->expects($this->never())->method('add');
6464

Tests/CacheClearer/ChainCacheClearerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public function testInjectClearerUsingAdd()
5252

5353
protected function getMockClearer()
5454
{
55-
return $this->getMock('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface');
55+
return $this->getMockBuilder('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface')->getMock();
5656
}
5757
}

Tests/Config/FileLocatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FileLocatorTest extends \PHPUnit_Framework_TestCase
1717
{
1818
public function testLocate()
1919
{
20-
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
20+
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
2121
$kernel
2222
->expects($this->atLeastOnce())
2323
->method('locateResource')
@@ -35,7 +35,7 @@ public function testLocate()
3535

3636
public function testLocateWithGlobalResourcePath()
3737
{
38-
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
38+
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
3939
$kernel
4040
->expects($this->atLeastOnce())
4141
->method('locateResource')

Tests/Controller/ControllerResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
2121
{
2222
public function testGetControllerWithoutControllerParameter()
2323
{
24-
$logger = $this->getMock('Psr\Log\LoggerInterface');
24+
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
2525
$logger->expects($this->once())->method('warning')->with('Unable to look for the controller as the "_controller" parameter is missing.');
2626
$resolver = $this->createControllerResolver($logger);
2727

@@ -215,7 +215,7 @@ public function testGetVariadicArguments()
215215

216216
public function testCreateControllerCanReturnAnyCallable()
217217
{
218-
$mock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolver', array('createController'));
218+
$mock = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolver')->setMethods(array('createController'))->getMock();
219219
$mock->expects($this->once())->method('createController')->will($this->returnValue('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function'));
220220

221221
$request = Request::create('/');

Tests/DataCollector/LoggerDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
2020
*/
2121
public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
2222
{
23-
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\DebugLoggerInterface');
23+
$logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
2424
$logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
2525
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
2626

Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCollect()
3131
$attributes = $c->getRequestAttributes();
3232

3333
$this->assertSame('request', $c->getName());
34-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getRequestHeaders());
34+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestHeaders());
3535
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer());
3636
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies());
3737
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
@@ -45,7 +45,7 @@ public function testCollect()
4545
$this->assertRegExp('/Resource\(stream#\d+\)/', $attributes->get('resource'));
4646
$this->assertSame('Object(stdClass)', $attributes->get('object'));
4747

48-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders());
48+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
4949
$this->assertSame('OK', $c->getStatusText());
5050
$this->assertSame(200, $c->getStatusCode());
5151
$this->assertSame('application/json', $c->getContentType());
@@ -185,7 +185,7 @@ protected function createResponse()
185185
*/
186186
protected function injectController($collector, $controller, $request)
187187
{
188-
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
188+
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock();
189189
$httpKernel = new HttpKernel(new EventDispatcher(), $resolver);
190190
$event = new FilterControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST);
191191
$collector->onKernelController($event);

Tests/DataCollector/TimeDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testCollect()
4141
$c->collect($request, new Response());
4242
$this->assertEquals(0, $c->getStartTime());
4343

44-
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
44+
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
4545
$kernel->expects($this->once())->method('getStartTime')->will($this->returnValue(123456));
4646

4747
$c = new TimeDataCollector($kernel);

Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testListenerCanRemoveItselfWhenExecuted()
108108

109109
protected function getHttpKernel($dispatcher, $controller)
110110
{
111-
$resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');
111+
$resolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();
112112
$resolver->expects($this->once())->method('getController')->will($this->returnValue($controller));
113113
$resolver->expects($this->once())->method('getArguments')->will($this->returnValue(array()));
114114

Tests/DependencyInjection/ContainerAwareHttpKernelTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testHandle($type)
3434
return $expected;
3535
};
3636

37-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
37+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
3838
$this
3939
->expectsEnterScopeOnce($container)
4040
->expectsLeaveScopeOnce($container)
@@ -63,11 +63,11 @@ public function testVerifyRequestStackPushPopDuringHandle($type)
6363
return $expected;
6464
};
6565

66-
$stack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack', array('push', 'pop'));
66+
$stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(array('push', 'pop'))->getMock();
6767
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
6868
$stack->expects($this->at(1))->method('pop');
6969

70-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
70+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
7171
$dispatcher = new EventDispatcher();
7272
$resolver = $this->getResolverMockFor($controller, $request);
7373
$kernel = new ContainerAwareHttpKernel($dispatcher, $container, $resolver, $stack);
@@ -86,7 +86,7 @@ public function testHandleRestoresThePreviousRequestOnException($type)
8686
throw $expected;
8787
};
8888

89-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
89+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
9090
$this
9191
->expectsEnterScopeOnce($container)
9292
->expectsLeaveScopeOnce($container)
@@ -95,7 +95,7 @@ public function testHandleRestoresThePreviousRequestOnException($type)
9595
;
9696

9797
$dispatcher = new EventDispatcher();
98-
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
98+
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock();
9999
$resolver = $this->getResolverMockFor($controller, $request);
100100
$stack = new RequestStack();
101101
$kernel = new ContainerAwareHttpKernel($dispatcher, $container, $resolver, $stack);
@@ -120,7 +120,7 @@ public function getProviderTypes()
120120

121121
private function getResolverMockFor($controller, $request)
122122
{
123-
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
123+
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock();
124124
$resolver->expects($this->once())
125125
->method('getController')
126126
->with($request)

0 commit comments

Comments
 (0)