Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 648aacb

Browse filesBrowse files
committed
[FrameworkBundle] Allow to disable Kernel reboot
1 parent 043b8fe commit 648aacb
Copy full SHA for 648aacb

File tree

Expand file treeCollapse file tree

2 files changed

+87
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+87
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Client.php
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Client extends BaseClient
2929
{
3030
private $hasPerformedRequest = false;
3131
private $profiler = false;
32+
private $reboot = true;
3233

3334
/**
3435
* {@inheritdoc}
@@ -84,6 +85,26 @@ public function enableProfiler()
8485
}
8586
}
8687

88+
/**
89+
* By default, the Client reboots the Kernel for each request. This method
90+
* allows to keep the same kernel across requests.
91+
*/
92+
public function disableReboot()
93+
{
94+
$this->reboot = false;
95+
}
96+
97+
/**
98+
* Enable the kernel reboot behaviour.
99+
*
100+
* If the kernel reboot was previously disabled, you can re-enable it with
101+
* this method.
102+
*/
103+
public function enableReboot()
104+
{
105+
$this->reboot = true;
106+
}
107+
87108
/**
88109
* {@inheritdoc}
89110
*
@@ -95,7 +116,7 @@ protected function doRequest($request)
95116
{
96117
// avoid shutting down the Kernel if no request has been performed yet
97118
// WebTestCase::createClient() boots the Kernel but do not handle a request
98-
if ($this->hasPerformedRequest) {
119+
if ($this->hasPerformedRequest && $this->reboot) {
99120
$this->kernel->shutdown();
100121
} else {
101122
$this->hasPerformedRequest = true;
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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;
13+
14+
use Symfony\Bundle\FrameworkBundle\Client;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\WebTestCase;
16+
use Symfony\Component\HttpFoundation\Response;
17+
18+
class ClientTest extends WebTestCase
19+
{
20+
public function testRebootKernelBetweenRequests()
21+
{
22+
$mock = $this->getKernelMock();
23+
$mock->expects($this->once())->method('shutdown');
24+
25+
$client = new Client($mock);
26+
$client->request('GET', '/');
27+
$client->request('GET', '/');
28+
}
29+
30+
public function testDisabledRebootKernel()
31+
{
32+
$mock = $this->getKernelMock();
33+
$mock->expects($this->never())->method('shutdown');
34+
35+
$client = new Client($mock);
36+
$client->disableReboot();
37+
$client->request('GET', '/');
38+
$client->request('GET', '/');
39+
}
40+
41+
public function testEnableRebootKernel()
42+
{
43+
$mock = $this->getKernelMock();
44+
$mock->expects($this->once())->method('shutdown');
45+
46+
$client = new Client($mock);
47+
$client->disableReboot();
48+
$client->request('GET', '/');
49+
$client->request('GET', '/');
50+
$client->enableReboot();
51+
$client->request('GET', '/');
52+
}
53+
54+
private function getKernelMock()
55+
{
56+
$mock = $this->getMockBuilder($this->getKernelClass())
57+
->setMethods(array('shutdown', 'boot', 'handle'))
58+
->disableOriginalConstructor()
59+
->getMock();
60+
61+
$mock->expects($this->any())->method('handle')->willReturn(new Response('foo'));
62+
63+
return $mock;
64+
}
65+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.