8000 Merge branch '5.4' into 6.0 · symfony/symfony@2560fec · GitHub
[go: up one dir, main page]

Skip to content

Commit 2560fec

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [HttpClient] Fix handling thrown \Exception in \Generator in MockResponse [DebugBundle] Add missing README [Lock] Fix missing argument in PostgreSqlStore::putOffExpiration with DBAL connection Bump Symfony version to 5.4.2 Update VERSION for 5.4.1 Update CHANGELOG for 5.4.1 [String] Fix requiring wcswitch table several times
2 parents e3202d1 + f532ec7 commit 2560fec

File tree

5 files changed

+87
-24
lines changed

5 files changed

+87
-24
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DebugBundle
2+
===========
3+
4+
DebugBundle provides a tight integration of the Symfony VarDumper component and
5+
the ServerLogCommand from MonologBridge into the Symfony full-stack framework.
6+
7+
Resources
8+
---------
9+
10+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
11+
* [Report issues](https://github.com/symfony/symfony/issues) and
12+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
13+
in the [main Symfony repository](https://github.com/symfony/symfony)

src/Symfony/Bundle/DebugBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "symfony/debug-bundle",
33
"type": "symfony-bundle",
4-
"description": "Provides a tight integration of the Symfony Debug component into the Symfony full-stack framework",
4+
"description": "Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfony full-stack framework",
55
"keywords": [],
66
"homepage": "https://symfony.com",
77
"license": "MIT",

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MockResponse implements ResponseInterface, StreamableInterface
4141
/**
4242
* @param string|string[]|iterable $body The response body as a string or an iterable of strings,
4343
* yielding an empty string simulates an idle timeout,
44-
* exceptions are turned to TransportException
44+
* throwing an exception yields an ErrorChunk
4545
*
4646
* @see ResponseInterface::getInfo() for possible info, e.g. "response_headers"
4747
*/
@@ -208,6 +208,9 @@ protected static function perform(ClientState $multi, array &$responses): void
208208
$multi->handlesActivity[$id][] = null;
209209
$multi->handlesActivity[$id][] = $e;
210210
}
211+
} elseif ($chunk instanceof \Throwable) {
212+
$multi->handlesActivity[$id][] = null;
213+
$multi->handlesActivity[$id][] = $chunk;
211214
} else {
212215
// Data or timeout chunk
213216
$multi->handlesActivity[$id][] = $chunk;
@@ -300,16 +303,20 @@ private static function readResponse(self $response, array $options, ResponseInt
300303
$body = $mock instanceof self ? $mock->body : $mock->getContent(false);
301304

302305
if (!\is_string($body)) {
303-
foreach ($body as $chunk) {
304-
if ('' === $chunk = (string) $chunk) {
305-
// simulate an idle timeout
306-
$response->body[] = new ErrorChunk($offset, sprintf('Idle timeout reached for "%s".', $response->info['url']));
307-
} else {
308-
$response->body[] = $chunk;
309-
$offset += \strlen($chunk);
310-
// "notify" download progress
311-
$onProgress($offset, $dlSize, $response->info);
306+
try {
307+
foreach ($body as $chunk) {
308+
if ('' === $chunk = (string) $chunk) {
309+
// simulate an idle timeout
310+
$response->body[] = new ErrorChunk($offset, sprintf('Idle timeout reached for "%s".', $response->info['url']));
311+
} else {
312+
$response->body[] = $chunk;
313+
$offset += \strlen($chunk);
314+
// "notify" download progress
315+
$onProgress($offset, $dlSize, $response->info);
316+
}
312317
}
318+
} catch (\Throwable $e) {
319+
$response->body[] = $e;
313320
}
314321
} elseif ('' !== $body) {
315322
$response->body[] = $body;

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\HttpClient\Tests;
1313

14+
use Symfony\Component\HttpClient\Chunk\DataChunk;
15+
use Symfony\Component\HttpClient\Chunk\ErrorChunk;
16+
use Symfony\Component\HttpClient\Chunk\FirstChunk;
1417
use Symfony\Component\HttpClient\Exception\TransportException;
1518
use Symfony\Component\HttpClient\MockHttpClient;
1619
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -184,6 +187,46 @@ public function invalidResponseFactoryProvider()
184187
];
185188
}
186189

190+
public function testThrowExceptionInBodyGenerator()
191+
{
192+
$mockHttpClient = new MockHttpClient([
193+
new MockResponse((static function (): \Generator {
194+
yield 'foo';
195+
throw new TransportException('foo ccc');
196+
})()),
197+
new MockResponse((static function (): \Generator {
198+
yield 'bar';
199+
throw new \RuntimeException('bar ccc');
200+
})()),
201+
]);
202+
203+
try {
204+
$mockHttpClient->request('GET', 'https://symfony.com', [])->getContent();
205+
$this->fail();
206+
} catch (TransportException $e) {
207+
$this->assertEquals(new TransportException('foo ccc'), $e->getPrevious());
208+
$this->assertSame('foo ccc', $e->getMessage());
209+
}
210+
211+
$chunks = [];
212+
try {
213+
foreach ($mockHttpClient->stream($mockHttpClient->request('GET', 'https://symfony.com', [])) as $chunk) {
214+
$chunks[] = $chunk;
215+
}
216+
$this->fail();
217+
} catch (TransportException $e) {
218+
$this->assertEquals(new \RuntimeException('bar ccc'), $e->getPrevious());
219+
$this->assertSame('bar ccc', $e->getMessage());
220+
}
221+
222+
$this->assertCount(3, $chunks);
223+
$this->assertEquals(new FirstChunk(0, ''), $chunks[0]);
224+
$this->assertEquals(new DataChunk(0, 'bar'), $chunks[1]);
225+
$this->assertInstanceOf(ErrorChunk::class, $chunks[2]);
226+
$this->assertSame(3, $chunks[2]->getOffset());
227+
$this->assertSame('bar ccc', $chunks[2]->getError());
228+
}
229+
187230
protected function getHttpClient(string $testCase): HttpClientInterface
188231
{
189232
$responses = [];
@@ -299,7 +342,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
299342
case 'testResolve':
300343
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
301344
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
302-
$responses[] = new MockResponse((function () { throw new \Exception('Fake connection timeout'); yield ''; })(), ['response_headers' => $headers]);
345+
$responses[] = new MockResponse((function () { yield ''; })(), ['response_headers' => $headers]);
303346
break;
304347

305348
case 'testTimeoutOnStream':

src/Symfony/Component/String/AbstractUnicodeString.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ abstract class AbstractUnicodeString extends AbstractString
4949
private const TRANSLIT_TO = ['AE', 'D', 'O', 'TH', 'ss', 'ae', 'd', 'o', 'th', 'D', 'd', 'H', 'h', 'i', 'q', 'L', 'l', 'L', 'l', '\'n', 'N', 'n', 'OE', 'oe', 'T', 't', 'b', 'B', 'B', 'b', 'C', 'c', 'D', 'D', 'D', 'd', 'E', 'F', 'f', 'G', 'hv', 'I', 'I', 'K', 'k', 'l', 'N', 'n', 'OI', 'oi', 'P', 'p', 't', 'T', 't', 'T', 'V', 'Y', 'y', 'Z', 'z', 'DZ', 'Dz', 'dz', 'G', 'g', 'd', 'Z', 'z', 'l', 'n', 't', 'j', 'db', 'qp', 'A', 'C', 'c', 'L', 'T', 's', 'z', 'B', 'U', 'E', 'e', 'J', 'j', 'R', 'r', 'Y', 'y', 'b', 'c', 'd', 'd', 'e', 'j', 'g', 'g', 'G', 'h', 'h', 'i', 'I', 'l', 'l', 'l', 'm', 'n', 'n', 'N', 'OE', 'r', 'r', 'r', 'R', 's', 't', 'u', 'v', 'Y', 'z', 'z', 'B', 'G', 'H', 'j', 'L', 'q', 'dz', 'dz', 'ts', 'ls', 'lz', 'A', 'AE', 'B', 'C', 'D', 'D', 'E', 'J', 'K', 'L', 'M', 'O', 'P', 'T', 'U', 'V', 'W', 'Z', 'ue', 'b', 'd', 'f', 'm', 'n', 'p', 'r', 'r', 's', 't', 'z', 'th', 'I', 'p', 'U', 'b', 'd', 'f', 'g', 'k', 'l', 'm', 'n', 'p', 'r', 's', 'v', 'x', 'z', 'a', 'd', 'e', 'e', 'i', 'u', 'a', 's', 's', 'SS', 'LL', 'll', 'V', 'v', 'Y', 'y', '(C)', '(R)', 'CE', 'Cr', 'Fr.', 'L.', 'Pts', 'TL', 'Rs', 'x', 'Rx', 'm/s', 'rad/s', 'C/kg', 'pH', 'V/m', 'A/m', ' 1/4', ' 1/2', ' 3/4', ' 1/3', ' 2/3', ' 1/5', ' 2/5', ' 3/5', ' 4/5', ' 1/6', ' 5/6', ' 1/8', ' 3/8', ' 5/8', ' 7/8', ' 1/', '0', '\'', '\'', ',', '\'', '"', '"', ',,', '"', '\'', '"', '"', '"', '<<', '>>', '<', '>', < F438 span class=pl-s>'-', '-', '-', '-', '-', '-', '-', '-', '-', '||', '/', '[', ']', '*', ',', '.', '<', '>', '<<', '>>', '[', ']', '[', ']', '[', ']', ',', '.', '[', ']', '<<', '>>', '<', '>', ',', '[', ']', '((', '))', '.', ',', '*', '/', '-', '/', '\\', '|', '||', '<<', '>>', '((', '))'];
5050

5151
private static $transliterators = [];
52+
private static $tableZero;
53+
private static $tableWide;
5254

5355
public static function fromCodePoints(int ...$codes): static
5456
{
@@ -553,39 +555,37 @@ private function wcswidth(string $string): int
553555
return -1;
554556
}
555557

556-
static $tableZero;
557-
if (null === $tableZero) {
558-
$tableZero = require __DIR__.'/Resources/data/wcswidth_table_zero.php';
558+
if (null === self::$tableZero) {
559+
self::$tableZero = require __DIR__.'/Resources/data/wcswidth_table_zero.php';
559560
}
560561

561-
if ($codePoint >= $tableZero[0][0] && $codePoint <= $tableZero[$ubound = \count($tableZero) - 1][1]) {
562+
if ($codePoint >= self::$tableZero[0][0] && $codePoint <= self::$tableZero[$ubound = \count(self::$tableZero) - 1][1]) {
562563
$lbound = 0;
563564
while ($ubound >= $lbound) {
564565
$mid = floor(($lbound + $ubound) / 2);
565566

566-
if ($codePoint > $tableZero[$mid][1]) {
567+
if ($codePoint > self::$tableZero[$mid][1]) {
567568
$lbound = $mid + 1;
568-
} elseif ($codePoint < $tableZero[$mid][0]) {
569+
} elseif ($codePoint < self::$tableZero[$mid][0]) {
569570
$ubound = $mid - 1;
570571
} else {
571572
continue 2;
572573
}
573574
}
574575
}
575576

576-
static $tableWide;
577-
if (null === $tableWide) {
578-
$tableWide = require __DIR__.'/Resources/data/wcswidth_table_wide.php';
577+
if (null === self::$tableWide) {
578+
self::$tableWide = require __DIR__.'/Resources/data/wcswidth_table_wide.php';
579579
}
580580

581-
if ($codePoint >= $tableWide[0][0] && $codePoint <= $tableWide[$ubound = \count($tableWide) - 1][1]) {
581+
if ($codePoint >= self::$tableWide[0][0] && $codePoint <= self::$tableWide[$ubound = \count(self::$tableWide) - 1][1]) {
582582
$lbound = 0;
583583
while ($ubound >= $lbound) {
584584
$mid = floor(($lbound + $ubound) / 2);
585585

586-
if ($codePoint > $tableWide[$mid][1]) {
586+
if ($codePoint > self::$tableWide[$mid][1]) {
587587
$lbound = $mid + 1;
588-
} elseif ($codePoint < $tableWide[$mid][0]) {
588+
} elseif ($codePoint < self::$tableWide[$mid][0]) {
589589
$ubound = $mid - 1;
590590
} else {
591591
$width += 2;

0 commit comments

Comments
 (0)
0