Skip to content

Commit efda998

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: fix compatibility with Redis Relay 0.8.1 use more entropy with uniqid() [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 [Serializer] Raise correct exception in ArrayDenormalizer
2 parents 89bd1b4 + ef28767 commit efda998

File tree

21 files changed

+311
-29
lines changed

21 files changed

+311
-29
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/Bridge/PsrHttpMessage/Tests/Factory/HttpFoundationFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function testCreateUploadedFile()
172172
$symfonyUploadedFile = $this->callCreateUploadedFile($uploadedFile);
173173
$size = $symfonyUploadedFile->getSize();
174174

175-
$uniqid = uniqid();
175+
$uniqid = uniqid('', true);
176176
$symfonyUploadedFile->move($this->tmpDir, $uniqid);
177177

178178
$this->assertEquals($uploadedFile->getSize(), $size);
@@ -198,7 +198,7 @@ public function testCreateUploadedFileWithError()
198198

199199
private function createUploadedFile(string $content, int $error, string $clientFileName, string $clientMediaType): UploadedFile
200200
{
201-
$filePath = tempnam($this->tmpDir, uniqid());
201+
$filePath = tempnam($this->tmpDir, uniqid('', true));
202202
file_put_contents($filePath, $content);
203203

204204
return new UploadedFile($filePath, filesize($filePath), $error, $clientFileName, $clientMediaType);

src/Symfony/Bridge/PsrHttpMessage/Tests/Factory/PsrHttpFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testGetContentCanBeCalledAfterRequestCreation()
131131

132132
private function createUploadedFile(string $content, string $originalName, string $mimeType, int $error): UploadedFile
133133
{
134-
$path = tempnam($this->tmpDir, uniqid());
134+
$path = tempnam($this->tmpDir, uniqid('', true));
135135
file_put_contents($path, $content);
136136

137137
return new UploadedFile($path, $originalName, $mimeType, $error, true);
@@ -182,7 +182,7 @@ public function testCreateResponseFromStreamed()
182182

183183
public function testCreateResponseFromBinaryFile()
184184
{
185-
$path = tempnam($this->tmpDir, uniqid());
185+
$path = tempnam($this->tmpDir, uniqid('', true));
186186
file_put_contents($path, 'Binary');
187187

188188
$response = new BinaryFileResponse($path);
@@ -194,7 +194,7 @@ public function testCreateResponseFromBinaryFile()
194194

195195
public function testCreateResponseFromBinaryFileWithRange()
196196
{
197-
$path = tempnam($this->tmpDir, uniqid());
197+
$path = tempnam($this->tmpDir, uniqid('', true));
198198
file_put_contents($path, 'Binary');
199199

200200
$request = new Request();

src/Symfony/Bridge/PsrHttpMessage/Tests/Functional/CovertTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public static function responseProvider(): array
217217

218218
private static function createUploadedFile(string $content, string $originalName, string $mimeType, int $error): UploadedFile
219219
{
220-
$path = tempnam(sys_get_temp_dir(), uniqid());
220+
$path = tempnam(sys_get_temp_dir(), uniqid('', true));
221221
file_put_contents($path, $content);
222222

223223
return new UploadedFile($path, $originalName, $mimeType, $error, true);

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/RedisProxiesTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Relay\Relay;
16+
use Symfony\Component\Cache\Traits\RelayProxy;
1617
use Symfony\Component\VarExporter\LazyProxyTrait;
1718
use Symfony\Component\VarExporter\ProxyHelper;
1819

@@ -61,14 +62,30 @@ public function testRelayProxy()
6162
{
6263
$proxy = file_get_contents(\dirname(__DIR__, 2).'/Traits/RelayProxy.php');
6364
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
65+
$expectedProxy = $proxy;
6466
$methods = [];
67+
$expectedMethods = [];
68+
69+
foreach ((new \ReflectionClass(RelayProxy::class))->getMethods() as $method) {
70+
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
71+
continue;
72+
}
73+
74+
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
75+
$expectedMethods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
76+
{
77+
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
78+
}
79+
80+
EOPHP;
81+
}
6582

6683
foreach ((new \ReflectionClass(Relay::class))->getMethods() as $method) {
6784
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
6885
continue;
6986
}
7087
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
71-
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
88+
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
7289
{
7390
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
7491
}
@@ -79,6 +96,9 @@ public function testRelayProxy()
7996
uksort($methods, 'strnatcmp');
8097
$proxy .= implode('', $methods)."}\n";
8198

82-
$this->assertStringEqualsFile(\dirname(__DIR__, 2).'/Traits/RelayProxy.php', $proxy);
99+
uksort($expectedMethods, 'strnatcmp');
100+
$expectedProxy .= implode('', $expectedMethods)."}\n";
101+
102+
$this->assertEquals($expectedProxy, $proxy);
83103
}
84104
}

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']) && isset($params['sentinel_master'])) {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RelayProxy extends \Relay\Relay implements ResetInterface, LazyObjectInter
2828
use LazyProxyTrait {
2929
resetLazyObject as reset;
3030
}
31+
use RelayProxyTrait;
3132

3233
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
3334

@@ -291,11 +292,6 @@ public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $re
291292
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
292293
}
293294

294-
public function copy($src, $dst, $options = null): \Relay\Relay|false|int
295-
{
296-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
297-
}
298-
299295
public function echo($arg): \Relay\Relay|bool|string
300296
{
301297
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());

0 commit comments

Comments
 (0)