Skip to content

Commit eaf96d4

Browse files
Merge branch '5.4' into 6.2
* 5.4: [Cache] Send Predis SSL options in the $hosts parameter [Contracts] Rename ServiceLocatorTest [Cache] Fix success interpretation when pruning cache [Security] Fix return type of AuthenticationSuccessHandlerInterface::onAuthenticationSuccess()
2 parents 6f77fa0 + 638703d commit eaf96d4

File tree

7 files changed

+140
-80
lines changed

7 files changed

+140
-80
lines changed

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function prune(): bool
7979
}
8080

8181
if ($time >= $expiresAt) {
82-
$pruned = $this->doUnlink($file) && !file_exists($file) && $pruned;
82+
$pruned = ($this->doUnlink($file) || !file_exists($file)) && $pruned;
8383
}
8484
}
8585
} finally {

src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ public function testCreateConnection()
4949
$this->assertSame($params, $connection->getParameters()->toArray());
5050
}
5151

52+
public function testCreateSslConnection()
53+
{
54+
$redisHost = getenv('REDIS_HOST');
55+
56+
$redis = RedisAdapter::createConnection('rediss://'.$redisHost.'/1?ssl[verify_peer]=0', ['class' => \Predis\Client::class, 'timeout' => 3]);
57+
$this->assertInstanceOf(\Predis\Client::class, $redis);
58+
59+
$connection = $redis->getConnection();
60+
$this->assertInstanceOf(StreamConnection::class, $connection);
61+
62+
$redisHost = explode(':', $redisHost);
63+
$params = [
64+
'scheme' => 'tls',
65+
'host' => $redisHost[0],
66+
'port' => (int) ($redisHost[1] ?? 6379),
67+
'ssl' => ['verify_peer' => '0'],
68+
'persistent' => 0,
69+
'timeout' => 3,
70+
'read_write_timeout' => 0,
71+
'tcp_nodelay' => true,
72+
'database' => '1',
73+
];
74+
$this->assertSame($params, $connection->getParameters()->toArray());
75+
}
76+
5277
public function testAclUserPasswordAuth()
5378
{
5479
// creating user via php-redis cause Predis (v1.1.10) does not support ACL command yet

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function prune(): bool
3838

3939
if (($expiresAt = (int) fgets($h)) && $time >= $expiresAt) {
4040
fclose($h);
41-
$pruned = @unlink($file) && !file_exists($file) && $pruned;
41+
$pruned = (@unlink($file) || !file_exists($file)) && $pruned;
4242
} else {
4343
fclose($h);
4444
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ public static function createConnection(string $dsn, array $options = []): \Redi
330330
$params['parameters']['password'] = $auth;
331331
}
332332
}
333+
334+
if (isset($params['ssl'])) {
335+
foreach ($hosts as $i => $host) {
336+
$hosts[$i]['ssl'] ??= $params['ssl'];
337+
}
338+
}
339+
333340
if (1 === \count($hosts) && !($params['redis_cluster'] || $params['redis_sentinel'])) {
334341
$hosts = $hosts[0];
335342
} elseif (\in_array($params['failover'], ['slaves', 'distribute'], true) && !isset($params['replication'])) {
@@ -338,7 +345,7 @@ public static function createConnection(string $dsn, array $options = []): \Redi
338345
}
339346
$params['exceptions'] = false;
340347

341-
$redis = new $class($hosts, array_diff_key($params, array_diff_key(self::$defaultConnectionOptions, ['ssl' => null])));
348+
$redis = new $class($hosts, array_diff_key($params, self::$defaultConnectionOptions));
342349
if (isset($params['redis_sentinel'])) {
343350
$redis->getConnection()->setSentinelTimeout($params['timeout']);
344351
}

src/Symfony/Component/DependencyInjection/Tests/ServiceLocatorTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1919
use Symfony\Component\DependencyInjection\ServiceLocator;
2020
use Symfony\Contracts\Service\ServiceSubscriberInterface;
21-
use Symfony\Contracts\Service\Test\ServiceLocatorTest as BaseServiceLocatorTest;
21+
use Symfony\Contracts\Service\Test\ServiceLocatorTest as LegacyServiceLocatorTestCase;
22+
use Symfony\Contracts\Service\Test\ServiceLocatorTestCase;
2223

23-
class ServiceLocatorTest extends BaseServiceLocatorTest
24+
if (!class_exists(ServiceLocatorTestCase::class)) {
25+
class_alias(LegacyServiceLocatorTestCase::class, ServiceLocatorTestCase::class);
26+
}
27+
28+
class ServiceLocatorTest extends ServiceLocatorTestCase
2429
{
2530
public function getServiceLocator(array $factories): ContainerInterface
2631
{

src/Symfony/Contracts/Service/Test/ServiceLocatorTest.php

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,13 @@
1111

1212
namespace Symfony\Contracts\Service\Test;
1313

14-
use PHPUnit\Framework\TestCase;
15-
use Psr\Container\ContainerInterface;
16-
use Symfony\Contracts\Service\ServiceLocatorTrait;
14+
class_alias(ServiceLocatorTestCase::class, ServiceLocatorTest::class);
1715

18-
abstract class ServiceLocatorTest extends TestCase
19-
{
20-
protected function getServiceLocator(array $factories): ContainerInterface
16+
if (false) {
17+
/**
18+
* @deprecated since PHPUnit 9.6
19+
*/
20+
class ServiceLocatorTest
2121
{
22-
return new class($factories) implements ContainerInterface {
23-
use ServiceLocatorTrait;
24-
};
25-
}
26-
27-
public function testHas()
28-
{
29-
$locator = $this->getServiceLocator([
30-
'foo' => function () { return 'bar'; },
31-
'bar' => function () { return 'baz'; },
32-
function () { return 'dummy'; },
33-
]);
34-
35-
$this->assertTrue($locator->has('foo'));
36-
$this->assertTrue($locator->has('bar'));
37-
$this->assertFalse($locator->has('dummy'));
38-
}
39-
40-
public function testGet()
41-
{
42-
$locator = $this->getServiceLocator([
43-
'foo' => function () { return 'bar'; },
44-
'bar' => function () { return 'baz'; },
45-
]);
46-
47-
$this->assertSame('bar', $locator->get('foo'));
48-
$this->assertSame('baz', $locator->get('bar'));
49-
}
50-
51-
public function testGetDoesNotMemoize()
52-
{
53-
$i = 0;
54-
$locator = $this->getServiceLocator([
55-
'foo' => function () use (&$i) {
56-
++$i;
57-
58-
return 'bar';
59-
},
60-
]);
61-
62-
$this->assertSame('bar', $locator->get('foo'));
63-
$this->assertSame('bar', $locator->get('foo'));
64-
$this->assertSame(2, $i);
65-
}
66-
67-
public function testThrowsOnUndefinedInternalService()
68-
{
69-
if (!$this->getExpectedException()) {
70-
$this->expectException(\Psr\Container\NotFoundExceptionInterface::class);
71-
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
72-
}
73-
$locator = $this->getServiceLocator([
74-
'foo' => function () use (&$locator) { return $locator->get('bar'); },
75-
]);
76-
77-
$locator->get('foo');
78-
}
79-
80-
public function testThrowsOnCircularReference()
81-
{
82-
$this->expectException(\Psr\Container\ContainerExceptionInterface::class);
83-
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
84-
$locator = $this->getServiceLocator([
85-
'foo' => function () use (&$locator) { return $locator->get('bar'); },
86-
'bar' => function () use (&$locator) { return $locator->get('baz'); },
87-
'baz' => function () use (&$locator) { return $locator->get('bar'); },
88-
]);
89-
90-
$locator->get('foo');
9122
}
9223
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Contracts\Service\Test;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Psr\Container\ContainerInterface;
16+
use Symfony\Contracts\Service\ServiceLocatorTrait;
17+
18+
abstract class ServiceLocatorTest extends TestCase
19+
{
20+
protected function getServiceLocator(array $factories): ContainerInterface
21+
{
22+
return new class($factories) implements ContainerInterface {
23+
use ServiceLocatorTrait;
24+
};
25+
}
26+
27+
public function testHas()
28+
{
29+
$locator = $this->getServiceLocator([
30+
'foo' => function () { return 'bar'; },
31+
'bar' => function () { return 'baz'; },
32+
function () { return 'dummy'; },
33+
]);
34+
35+
$this->assertTrue($locator->has('foo'));
36+
$this->assertTrue($locator->has('bar'));
37+
$this->assertFalse($locator->has('dummy'));
38+
}
39+
40+
public function testGet()
41+
{
42+
$locator = $this->getServiceLocator([
43+
'foo' => function () { return 'bar'; },
44+
'bar' => function () { return 'baz'; },
45+
]);
46+
47+
$this->assertSame('bar', $locator->get('foo'));
48+
$this->assertSame('baz', $locator->get('bar'));
49+
}
50+
51+
public function testGetDoesNotMemoize()
52+
{
53+
$i = 0;
54+
$locator = $this->getServiceLocator([
55+
'foo' => function () use (&$i) {
56+
++$i;
57+
58+
return 'bar';
59+
},
60+
]);
61+
62+
$this->assertSame('bar', $locator->get('foo'));
63+
$this->assertSame('bar', $locator->get('foo'));
64+
$this->assertSame(2, $i);
65+
}
66+
67+
public function testThrowsOnUndefinedInternalService()
68+
{
69+
if (!$this->getExpectedException()) {
70+
$this->expectException(\Psr\Container\NotFoundExceptionInterface::class);
71+
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
72+
}
73+
$locator = $this->getServiceLocator([
74+
'foo' => function () use (&$locator) { return $locator->get('bar'); },
75+
]);
76+
77+
$locator->get('foo');
78+
}
79+
80+
public function testThrowsOnCircularReference()
81+
{
82+
$this->expectException(\Psr\Container\ContainerExceptionInterface::class);
83+
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
84+
$locator = $this->getServiceLocator([
85+
'foo' => function () use (&$locator) { return $locator->get('bar'); },
86+
'bar' => function () use (&$locator) { return $locator->get('baz'); },
87+
'baz' => function () use (&$locator) { return $locator->get('bar'); },
88+
]);
89+
90+
$locator->get('foo');
91+
}
92+
}

0 commit comments

Comments
 (0)