Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"php": "^8.4",
"symfony/dependency-injection": "^7.3",
"symfony/http-kernel": "^7.3",
"symfony/cache": "^7.3"
"symfony/cache": "^7.3",
"ext-redis": "*"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
Expand Down Expand Up @@ -49,4 +50,4 @@
"php": "8.4.0"
}
}
}
}
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ private function getCleanedUseLinesForReflection(ReflectionClass $reflection, ar
if ($file === false) {
return [];
}
$test = 'concatmoretext';

return $this->getUseLinesFromFile($file, $excludeUseStrings);
}
Expand Down
88 changes: 42 additions & 46 deletions src/Service/RedisAbstractionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,7 @@ public function flushAll(): Redis|bool
return $this->getClient()->flushAll();
}

$masters = $this->_masters();

$flushSuccess = true;
foreach ($masters as $master) {
$host = $master[0];
$port = $master[1];

$tempClient = new Redis();

try {
if ($tempClient->connect($host, $port, 0.5)) {
$tempClient->flushAll();
}
} catch (RedisException) {
$flushSuccess = false;
} finally {
if ($tempClient->isConnected()) {
$tempClient->close();
}
}
}

return $flushSuccess;
return $this->flushCluster(true);
}

public function flushDb(?bool $sync = null): Redis|bool
Expand All @@ -115,29 +93,7 @@ public function flushDb(?bool $sync = null): Redis|bool
return $this->getClient()->flushDb($sync);
}

$masters = $this->_masters();

$flushSuccess = true;
foreach ($masters as $master) {
$host = $master[0];
$port = $master[1];

$tempClient = new Redis();

try {
if ($tempClient->connect($host, $port, 0.5)) {
$tempClient->flushDB();
}
} catch (RedisException) {
$flushSuccess = false;
} finally {
if ($tempClient->isConnected()) {
$tempClient->close();
}
}
}

return $flushSuccess;
return $this->flushCluster(false);
}

public function getHost(): string
Expand Down Expand Up @@ -219,4 +175,44 @@ private function getClient(): Redis|RedisCluster

return $this->redisClientProvider->getRedisClient();
}

private function flushCluster(bool $all): Redis|bool
{
if (!$this->isCluster()) {
throw new BadMethodCallException('flushCluster can only be called on a Redis Cluster client');
}

$masters = $this->_masters();

$flushSuccess = true;
foreach ($masters as $master) {
$host = $master[0];
$port = $master[1];

$tempClient = new Redis();

try {
if ($tempClient->connect($host, $port, 0.5)) {
if ($all) {
$tempClient->flushAll();
} else {
$tempClient->flushDb();
}
}
} catch (RedisException) {
$flushSuccess = false;
} finally {
if ($tempClient->isConnected()) {
$tempClient->close();
}
}
}

return $flushSuccess;
if ($all) {
return $this->flushAll();
} else {
return $this->flushDb();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function testGetSrcDirByVendorMaxIterationsExceeded(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingVendorWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDirByVendor');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5/6/7/8/9', 5);
$this->assertFalse($src);
}
Expand All @@ -70,7 +69,6 @@ public function testGetSrcDirByVendorSibling(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingVendorWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDirByVendor');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertSame($sourceDir . '/src', $src);
Expand All @@ -80,7 +78,6 @@ public function testGetSrcDirByVendorSiblingWithoutSrc(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingVendorWithoutSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDirByVendor');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertFalse($src);
Expand All @@ -90,7 +87,6 @@ public function testGetSrcDirByVendorWithinSrc(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingVendorWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDirByVendor');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertSame($sourceDir . '/src', $src);
Expand All @@ -100,7 +96,6 @@ public function testGetSrcDirByComposerJsonMaxIterationsExceeded(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingComposerWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcByComposerJson');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5/6/7/8/9', 5);
$this->assertFalse($src);
}
Expand All @@ -109,7 +104,6 @@ public function testGetSrcDirByComposerJsonWithSrc(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingComposerWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcByComposerJson');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertSame($sourceDir . '/src', $src);
Expand All @@ -119,7 +113,6 @@ public function testGetSrcDirByComposerJsonWithoutSrc(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingComposerWithoutSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcByComposerJson');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertFalse($src);
Expand All @@ -129,7 +122,6 @@ public function testGetSrcDirSucceedingComposer(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingComposerWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDir');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertSame($sourceDir . '/src', $src);
Expand All @@ -139,7 +131,6 @@ public function testGetSrcDirSucceedingVendor(): void
{
$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingVendorWithSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDir');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');

$this->assertSame($sourceDir . '/src', $src);
Expand All @@ -151,7 +142,6 @@ public function testGetSrcDirFailing(): void

$sourceDir = __DIR__ . '/FetchAllCachedServicesTestStructure/ExistingVendorWithoutSrc';
$method = new ReflectionMethod(FetchAllCachedServices::class, 'getSrcDir');
$method->setAccessible(true);
$src = $method->invoke(null, $sourceDir . '/1/2/3/4/5');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,9 @@ class: TestServiceA::class,
// Clear the cache
$reflectionClass = new ReflectionClass(KeyGeneratorService::class);
$cacheKeyPrefixCacheProperty = $reflectionClass->getProperty('cacheKeyPrefixCache');
$cacheKeyPrefixCacheProperty->setAccessible(true);
$cacheKeyPrefixCacheProperty->setValue(null, []);

$methodReflection = new ReflectionMethod(KeyGeneratorService::class, 'getCacheKeyPrefix');
$methodReflection->setAccessible(true);
$prefix1 = $methodReflection->invoke(null, $methodCallObject);
$this->assertEquals('test_service_a', $prefix1);

Expand Down
3 changes: 0 additions & 3 deletions tests/DataCollector/MultiLevelCacheDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function testWhenNotCollecting(): void
// simulate not collecting by directly setting data
$ref = new ReflectionClass($collector);
$property = $ref->getProperty('data');
$property->setAccessible(true);
$property->setValue($collector, ['grouped_instances' => []]);

// add instance should not do anything
Expand Down Expand Up @@ -242,7 +241,6 @@ public function testGetStatisticsObjectWithInvalidGroup(): void

$ref = new ReflectionClass($collector);
$method = $ref->getMethod('getStatisticsObject');
$method->setAccessible(true);
$stats = $method->invokeArgs($collector, ['nonexistent_group', 0]);

$this->assertNull($stats);
Expand All @@ -261,7 +259,6 @@ class: stdClass::class,

$ref = new ReflectionClass($collector);
$method = $ref->getMethod('getStatisticsObject');
$method->setAccessible(true);
$stats = $method->invokeArgs($collector, ['valid_group', 7]);

$this->assertNull($stats);
Expand Down
5 changes: 0 additions & 5 deletions tests/Factory/MultiLevelCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,18 @@ public function __construct()
$rc = new ReflectionClass(MultiLevelCacheFactory::class);

$prop = $rc->getProperty('redisClientProvider');
$prop->setAccessible(true);
$prop->setValue($factory, RedisClientFactoryTest::wrapClient($redisMock));

$prop = $rc->getProperty('redisDsn');
$prop->setAccessible(true);
$prop->setValue($factory, 'redis://localhost');

$prop = $rc->getProperty('stopwatch');
$prop->setAccessible(true);
$prop->setValue($factory, $stopwatchMock);

$prop = $rc->getProperty('cacheDataCollector');
$prop->setAccessible(true);
$prop->setValue($factory, $collectorMock);

$prop = $rc->getProperty('cacheReadDisabled');
$prop->setAccessible(true);
$prop->setValue($factory, false);

return $factory;
Expand Down
2 changes: 0 additions & 2 deletions tests/Service/MultiLevelCacheServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ public function testGetCacheImplementationForInvalidLevel(): void
$this->expectException(InvalidArgumentException::class);

$methodReleflection = new ReflectionMethod(MultiLevelCacheService::class, 'getCacheImplementation');
$methodReleflection->setAccessible(true);
$service = new MultiLevelCacheService(
caches: [new InMemoryCacheService(5)],
);
Expand All @@ -785,7 +784,6 @@ public function testConstructorHelperSetupDataCollector(): void
);

$methodReflection = new ReflectionMethod(MultiLevelCacheService::class, 'getStatisticsObject');
$methodReflection->setAccessible(true);
$statisticsObject = $methodReflection->invoke($service, 0);
$this->assertInstanceOf(CacheStatistics::class, $statisticsObject, 'The getStatisticsObject method should return an instance of CacheStatistics');
$this->assertIsArray($statisticsObject->getConfigData(), 'The config data in the statistics object should be an array');
Expand Down
Loading