10000 Merge branch '5.4' into 6.4 · symfony/symfony@1a49e27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a49e27

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: [Cache] Improve `dbindex` DSN parameter parsing Support for PHP-CS-Fixer's parallel runner use more entropy with uniqid() [Contracts][HttpClient] Skip tests when zlib's `ob_gzhandler()` doesn't exist
2 parents 7b5d17f + b5dba85 commit 1a49e27

File tree

12 files changed

+102
-8
lines changed

12 files changed

+102
-8
lines changed

.php-cs-fixer.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
EOF;
2424

2525
return (new PhpCsFixer\Config())
26+
// @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777
27+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
2628
->setRules([
2729
'@PHP71Migration' => true,
2830
'@PHPUnit75Migration:risky' => true,

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/log_file.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test DeprecationErrorHandler with log file
33
--FILE--
44
<?php
5-
$filename = tempnam(sys_get_temp_dir(), 'sf-').uniqid();
5+
$filename = tempnam(sys_get_temp_dir(), 'sf-').uniqid('', true);
66
$k = 'SYMFONY_DEPRECATIONS_HELPER';
77
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'logFile='.$filename);
88
putenv('ANSICON');

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AnnotationsCacheWarmerTest extends TestCase
3434

3535
protected function setUp(): void
3636
{
37-
$this->cacheDir = sys_get_temp_dir().'/'.uniqid();
37+
$this->cacheDir = sys_get_temp_dir().'/'.uniqid('', true);
3838
$fs = new Filesystem();
3939
$fs->mkdir($this->cacheDir);
4040
parent::setUp();

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ConfigBuilderCacheWarmerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ConfigBuilderCacheWarmerTest extends TestCase
3737

3838
protected function setUp(): void
3939
{
40-
$this->varDir = sys_get_temp_dir().'/'.uniqid();
40+
$this->varDir = sys_get_temp_dir().'/'.uniqid('', true);
4141
$fs = new Filesystem();
4242
$fs->mkdir($this->varDir);
4343
}

src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Cache\Tests\Traits;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1516
use Symfony\Component\Cache\Traits\RedisTrait;
1617

1718
/**
@@ -132,4 +133,78 @@ public function testPconnectSelectsCorrectDatabase()
132133
ini_set('redis.pconnect.connection_limit', $prevPoolSize);
133134
}
134135
}
136+
137+
/**
138+
* @dataProvider provideDbIndexDsnParameter
139+
*/
140+
public function testDbIndexDsnParameter(string $dsn, int $expectedDb)
141+
{
142+
if (!getenv('REDIS_AUTHENTICATED_HOST')) {
143+
self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.');
144+
}
145+
146+
$mock = new class () {
147+
use RedisTrait;
148+
};
149+
$connection = $mock::createConnection($dsn);
150+
self::assertSame($expectedDb, $connection->getDbNum());
151+
}
152+
153+
public static function provideDbIndexDsnParameter(): array
154+
{
155+
return [
156+
[
157+
'redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST'),
158+
0,
159+
],
160+
[
161+
'redis:?host['.getenv('REDIS_HOST').']',
162+
0,
163+
],
164+
[
165+
'redis:?host['.getenv('REDIS_HOST').']&dbindex=1',
166+
1,
167+
],
168+
[
169+
'redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST').'?dbindex=2',
170+
2,
171+
],
172+
[
173+
'redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST').'/4',
174+
4,
175+
],
176+
[
177+
'redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST').'/?dbindex=5',
178+
5,
179+
],
180+
];
181+
}
182+
183+
/**
184+
* @dataProvider provideInvalidDbIndexDsnParameter
185+
*/
186+
public function testInvalidDbIndexDsnParameter(string $dsn)
187+
{
188+
if (!getenv('REDIS_AUTHENTICATED_HOST')) {
189+
self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.');
190+
}
191+
$this->expectException(InvalidArgumentException::class);
192+
193+
$mock = new class () {
194+
use RedisTrait;
195+
};
196+
$mock::createConnection($dsn);
197+
}
198+
199+
public static function provideInvalidDbIndexDsnParameter(): array
200+
{
201+
return [
202+
[
203+
'redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST').'/abc'
204+
],
205+
[
206+
'redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST').'/3?dbindex=6'
207+
]
208+
];
209+
}
135210
}

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
149149
if (isset($params['host']) || isset($params['path'])) {
150150
if (!isset($params['dbindex']) && isset($params['path'])) {
151151
if (preg_match('#/(\d+)?$#', $params['path'], $m)) {
152-
$params['dbindex'] = $m[1] ?? '0';
152+
$params['dbindex'] = $m[1] ?? $query['dbindex'] ?? '0';
153153
$params['path'] = substr($params['path'], 0, -\strlen($m[0]));
154154
} elseif (isset($params['host'])) {
155-
throw new InvalidArgumentException('Invalid Redis DSN: query parameter "dbindex" must be a number.');
155+
throw new InvalidArgumentException('Invalid Redis DSN: parameter "dbindex" must be a number.');
156156
}
157157
}
158158

@@ -167,6 +167,10 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
167167
throw new InvalidArgumentException('Invalid Redis DSN: missing host.');
168168
}
169169

170+
if (isset($params['dbindex'], $query['dbindex']) && $params['dbindex'] !== $query['dbindex']) {
171+
throw new InvalidArgumentException('Invalid Redis DSN: path and query "dbindex" parameters mismatch.');
172+
}
173+
170174
$params += $query + $options + self::$defaultConnectionOptions;
171175

172176
if (isset($params['redis_sentinel']) && !class_exists(\Predis\Client::class) && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static function tearDownAfterClass(): void
3737
TestHttpServer::stop();
3838
}
3939

40+
/**
41+
* @requires function ob_gzhandler
42+
*/
4043
public function testSendRequest()
4144
{
4245
$client = new HttplugClient(new NativeHttpClient());
@@ -51,6 +54,9 @@ public function testSendRequest()
5154
$this->assertSame('HTTP/1.1', $body['SERVER_PROTOCOL']);
5255
}
5356

57+
/**
58+
* @requires function ob_gzhandler
59+
*/
5460
public function testSendAsyncRequest()
5561
{
5662
$client = new HttplugClient(new NativeHttpClient());

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public static function tearDownAfterClass(): void
3333
TestHttpServer::stop();
3434
}
3535

36+
/**
37+
* @requires function ob_gzhandler
38+
*/
3639
public function testSendRequest()
3740
{
3841
$factory = new Psr17Factory();

src/Symfony/Component/Notifier/Bridge/Iqsms/IqsmsTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function doSend(MessageInterface $message): SentMessage
6464
'phone' => $message->getPhone(),
6565
'text' => $message->getSubject(),
6666
'sender' => $message->getFrom() ?: $this->from,
67-
'clientId' => uniqid(),
67+
'clientId' => uniqid('', true),
6868
],
6969
],
7070
'login' => $this->login,

src/Symfony/Component/Routing/Tests/Matcher/Dumper/CompiledUrlMatcherDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
{
3131
parent::setUp();
3232

33-
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_matcher.'.uniqid('CompiledUrlMatcher').'.php';
33+
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_matcher.'.uniqid('CompiledUrlMatcher', true).'.php';
3434
}
3535

3636
protected function tearDown(): void

src/Symfony/Component/Serializer/Tests/Mapping/Factory/ClassMetadataFactoryCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class ClassMetadataFactoryCompilerTest extends TestCase
2727

2828
protected function setUp(): void
2929
{
30-
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_serializer_metadata.'.uniqid('CompiledClassMetadataFactory').'.php';
30+
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_serializer_metadata.'.uniqid('CompiledClassMetadataFactory', true).'.php';
3131
}
3232

3333
protected function tearDown(): void

src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ abstract class HttpClientTestCase extends TestCase
2525
{
2626
public static function setUpBeforeClass(): void
2727
{
28+
if (!function_exists('ob_gzhandler')) {
29+
static::markTestSkipped('The "ob_gzhandler" function is not available.');
30+
}
31+
2832
TestHttpServer::start();
2933
}
3034

0 commit comments

Comments
 (0)
0