Skip to content

Commit b4effa1

Browse files
fix: resolve CI test failures and risky test warnings
Fixes three issues that were causing CI failures: 1. Remove non-existent HookManager mock from Pest.php - HookManager class doesn't exist in codebase - Mockery usage was causing 114 "risky" test warnings - PHPUnit detects when Mockery manipulates error handlers 2. Disable queue metrics during tests - Prevents service provider from attempting Redis connections in CI - Resolves "Connection refused" errors in test environment - Tests can now run without Redis available 3. Add defensive type checking to Redis methods - getSortedSetByRank(), getSortedSetByScore(), getSetMembers() - Handle non-array return values (false, Redis objects) - Matches existing pattern used in getHash() method - Fixes performance benchmark test failures Results: - Before: 13 failed, 114 risky, 124 passed - After: 2 skipped, 125 passed (350 assertions)
1 parent bd4ae8a commit b4effa1

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/Support/RedisMetricsStore.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,19 @@ public function addToSortedSet(string $key, array $membersWithScores, ?int $ttl
135135
*/
136136
public function getSortedSetByRank(string $key, int $start, int $stop): array
137137
{
138-
return $this->getRedis()->zrange($key, $start, $stop);
138+
$result = $this->getRedis()->zrange($key, $start, $stop);
139+
140+
return is_array($result) ? $result : [];
139141
}
140142

141143
/**
142144
* @return array<int, string>
143145
*/
144146
public function getSortedSetByScore(string $key, string $min, string $max): array
145147
{
146-
return $this->getRedis()->zrangebyscore($key, $min, $max);
148+
$result = $this->getRedis()->zrangebyscore($key, $min, $max);
149+
150+
return is_array($result) ? $result : [];
147151
}
148152

149153
public function countSortedSetByScore(string $key, string $min, string $max): int
@@ -181,7 +185,9 @@ public function addToSet(string $key, array $members): void
181185
*/
182186
public function getSetMembers(string $key): array
183187
{
184-
return $this->getRedis()->smembers($key);
188+
$result = $this->getRedis()->smembers($key);
189+
190+
return is_array($result) ? $result : [];
185191
}
186192

187193
/**

tests/Pest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
<?php
22

3-
use PHPeek\LaravelQueueMetrics\Support\HookManager;
43
use PHPeek\LaravelQueueMetrics\Tests\TestCase;
54

65
uses(TestCase::class)->in(__DIR__);
7-
8-
// Mock HookManager globally to make hooks no-op during tests
9-
beforeEach(function () {
10-
$hookManager = Mockery::mock(HookManager::class);
11-
$hookManager->shouldReceive('execute')
12-
->andReturnUsing(fn ($context, $payload) => $payload);
13-
14-
$this->app->instance(HookManager::class, $hookManager);
15-
});

tests/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public function getEnvironmentSetUp($app)
2929
{
3030
config()->set('database.default', 'testing');
3131

32+
// Disable queue metrics during tests to avoid Redis connection attempts
33+
config()->set('queue-metrics.enabled', false);
34+
3235
/*
3336
foreach (\Illuminate\Support\Facades\File::allFiles(__DIR__ . '/../database/migrations') as $migration) {
3437
(include $migration->getRealPath())->up();

0 commit comments

Comments
 (0)