Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82e3b17

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: improve exception message if symfony/security-csrf is missing fix: MockResponse total_time should not be simulated when provided
2 parents 2068652 + b3c4d63 commit 82e3b17

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true)
5959
public function renderCsrfToken(string $tokenId)
6060
{
6161
if (null === $this->csrfTokenManager) {
62-
throw new BadMethodCallException('CSRF tokens can only be generated if a CsrfTokenManagerInterface is injected in FormRenderer::__construct().');
62+
throw new BadMethodCallException('CSRF tokens can only be generated if a CsrfTokenManagerInterface is injected in FormRenderer::__construct(). Try running "composer require symfony/security-csrf".');
6363
}
6464

6565
return $this->csrfTokenManager->getToken($tokenId)->getValue();

src/Symfony/Component/HttpClient/Response/MockResponse.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ private static function writeRequest(self $response, array $options, ResponseInt
232232
$response->info['size_upload'] = 0.0;
233233
}
234234

235-
// simulate "total_time" if it is set
236-
if (isset($response->info['total_time'])) {
235+
// simulate "total_time" if it is not set
236+
if (!isset($response->info['total_time'])) {
237237
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
238238
}
239239

@@ -281,7 +281,7 @@ private static function readResponse(self $response, array $options, ResponseInt
281281
'http_code' => $response->info['http_code'],
282282
] + $info + $response->info;
283283

284-
if (isset($response->info['total_time'])) {
284+
if (!isset($response->info['total_time'])) {
285285
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
286286
}
287287

@@ -308,7 +308,7 @@ private static function readResponse(self $response, array $options, ResponseInt
308308
$offset = \strlen($body);
309309
}
310310

311-
if (isset($response->info['total_time'])) {
311+
if (!isset($response->info['total_time'])) {
312312
$response->info['total_time'] = microtime(true) - $response->info['start_time'];
313313
}
314314

src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
*/
1212
class MockResponseTest extends TestCase
1313
{
14+
public function testTotalTimeShouldBeSimulatedWhenNotProvided()
15+
{
16+
$response = new MockResponse('body');
17+
$response = MockResponse::fromRequest('GET', 'https://example.com/file.txt', [], $response);
18+
19+
$this->assertNotNull($response->getInfo('total_time'));
20+
$this->assertGreaterThan(0.0, $response->getInfo('total_time'));
21+
}
22+
23+
public function testTotalTimeShouldNotBeSimulatedWhenProvided()
24+
{
25+
$totalTime = 4.2;
26+
$response = new MockResponse('body', ['total_time' => $totalTime]);
27+
$response = MockResponse::fromRequest('GET', 'https://example.com/file.txt', [], $response);
28+
29+
$this->assertEquals($totalTime, $response->getInfo('total_time'));
30+
}
31+
1432
public function testToArray()
1533
{
1634
$data = ['color' => 'orange', 'size' => 42];

0 commit comments

Comments
 (0)