Skip to content

Commit eeebf22

Browse files
committed
Consolidate Redis cache test infrastructure into RedisCacheTestCase
- Create RedisCacheTestCase base class with mock helpers and fixed Carbon time - Update all Redis cache tests to extend RedisCacheTestCase - Remove redundant Carbon::setTestNow() calls from individual test methods - Remove redundant tearDown() methods that only called Mockery::close() - Delete MocksRedisConnections trait (merged into base class)
1 parent f4d789a commit eeebf22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+114
-352
lines changed

tests/Cache/Redis/AllTagSetTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace Hypervel\Tests\Cache\Redis;
66

77
use Hypervel\Cache\Redis\AllTagSet;
8-
use Hypervel\Testbench\TestCase;
9-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
108

119
/**
1210
* Tests for AllTagSet class.
@@ -19,10 +17,8 @@
1917
* @internal
2018
* @coversNothing
2119
*/
22-
class AllTagSetTest extends TestCase
20+
class AllTagSetTest extends RedisCacheTestCase
2321
{
24-
use MocksRedisConnections;
25-
2622
/**
2723
* @test
2824
*/

tests/Cache/Redis/AllTaggedCacheTest.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
namespace Hypervel\Tests\Cache\Redis;
66

7-
use Carbon\Carbon;
8-
use Hypervel\Testbench\TestCase;
9-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
10-
use Redis;
117
use RuntimeException;
128

139
/**
@@ -19,10 +15,8 @@
1915
* @internal
2016
* @coversNothing
2117
*/
22-
class AllTaggedCacheTest extends TestCase
18+
class AllTaggedCacheTest extends RedisCacheTestCase
2319
{
24-
use MocksRedisConnections;
25-
2620
/**
2721
* @test
2822
*/
@@ -122,8 +116,6 @@ public function testTagEntriesCanBeDecremented(): void
122116
*/
123117
public function testStaleEntriesCanBeFlushed(): void
124118
{
125-
Carbon::setTestNow('2000-01-01 00:00:00');
126-
127119
$connection = $this->mockConnection();
128120
$client = $connection->_mockClient;
129121

@@ -145,8 +137,6 @@ public function testStaleEntriesCanBeFlushed(): void
145137
*/
146138
public function testPut(): void
147139
{
148-
Carbon::setTestNow('2000-01-01 00:00:00');
149-
150140
$connection = $this->mockConnection();
151141
$client = $connection->_mockClient;
152142

@@ -172,8 +162,6 @@ public function testPut(): void
172162
*/
173163
public function testPutWithNumericValue(): void
174164
{
175-
Carbon::setTestNow('2000-01-01 00:00:00');
176-
177165
$connection = $this->mockConnection();
178166
$client = $connection->_mockClient;
179167

@@ -199,8 +187,6 @@ public function testPutWithNumericValue(): void
199187
*/
200188
public function testPutWithArray(): void
201189
{
202-
Carbon::setTestNow('2000-01-01 00:00:00');
203-
204190
$connection = $this->mockConnection();
205191
$client = $connection->_mockClient;
206192

@@ -393,8 +379,6 @@ public function testRememberReturnsExistingValueOnCacheHit(): void
393379
*/
394380
public function testRememberCallsCallbackAndStoresValueOnMiss(): void
395381
{
396-
Carbon::setTestNow('2000-01-01 00:00:00');
397-
398382
$connection = $this->mockConnection();
399383
$client = $connection->_mockClient;
400384

@@ -554,8 +538,6 @@ public function testRememberForeverPropagatesExceptionFromCallback(): void
554538
*/
555539
public function testRememberWithMultipleTags(): void
556540
{
557-
Carbon::setTestNow('2000-01-01 00:00:00');
558-
559541
$connection = $this->mockConnection();
560542
$client = $connection->_mockClient;
561543

tests/Cache/Redis/AnyTagSetTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
use Generator;
88
use Hypervel\Cache\Redis\AnyTagSet;
99
use Hypervel\Cache\RedisStore;
10-
use Hypervel\Testbench\TestCase;
11-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
1210
use Mockery as m;
13-
use Redis;
1411

1512
/**
1613
* Tests for AnyTagSet class.
@@ -21,10 +18,8 @@
2118
* @internal
2219
* @coversNothing
2320
*/
24-
class AnyTagSetTest extends TestCase
21+
class AnyTagSetTest extends RedisCacheTestCase
2522
{
26-
use MocksRedisConnections;
27-
2823
private RedisStore $store;
2924

3025
private m\MockInterface $client;

tests/Cache/Redis/AnyTaggedCacheTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Hypervel\Cache\Redis\AnyTaggedCache;
1010
use Hypervel\Cache\Redis\AnyTagSet;
1111
use Hypervel\Cache\TaggedCache;
12-
use Hypervel\Testbench\TestCase;
13-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
1412
use RuntimeException;
1513

1614
/**
@@ -22,10 +20,8 @@
2220
* @internal
2321
* @coversNothing
2422
*/
25-
class AnyTaggedCacheTest extends TestCase
23+
class AnyTaggedCacheTest extends RedisCacheTestCase
2624
{
27-
use MocksRedisConnections;
28-
2925
/**
3026
* @test
3127
*/

tests/Cache/Redis/Console/DoctorCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
*/
3232
class DoctorCommandTest extends TestCase
3333
{
34-
protected function tearDown(): void
35-
{
36-
m::close();
37-
38-
parent::tearDown();
39-
}
40-
4134
public function testDoctorFailsForNonRedisStore(): void
4235
{
4336
$nonRedisStore = m::mock(Store::class);

tests/Cache/Redis/Console/PruneStaleTagsCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
*/
2727
class PruneStaleTagsCommandTest extends TestCase
2828
{
29-
protected function tearDown(): void
30-
{
31-
m::close();
32-
33-
parent::tearDown();
34-
}
35-
3629
public function testPruneAllModeCallsCorrectOperation(): void
3730
{
3831
$intersectionPrune = m::mock(IntersectionPrune::class);

tests/Cache/Redis/ExceptionPropagationTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
use Hypervel\Cache\Redis\AnyTaggedCache;
88
use Hypervel\Cache\Redis\AnyTagSet;
9-
use Hypervel\Testbench\TestCase;
10-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
11-
use Mockery as m;
129
use RedisException;
1310

1411
/**
@@ -21,16 +18,8 @@
2118
* @internal
2219
* @coversNothing
2320
*/
24-
class ExceptionPropagationTest extends TestCase
21+
class ExceptionPropagationTest extends RedisCacheTestCase
2522
{
26-
use MocksRedisConnections;
27-
28-
protected function tearDown(): void
29-
{
30-
m::close();
31-
parent::tearDown();
32-
}
33-
3423
// =========================================================================
3524
// BASIC STORE OPERATIONS
3625
// =========================================================================

tests/Cache/Redis/Operations/AddTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Hypervel\Tests\Cache\Redis\Operations;
66

7-
use Hypervel\Testbench\TestCase;
8-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
7+
use Hypervel\Tests\Cache\Redis\RedisCacheTestCase;
98

109
/**
1110
* Tests for the Add operation.
@@ -16,10 +15,8 @@
1615
* @internal
1716
* @coversNothing
1817
*/
19-
class AddTest extends TestCase
18+
class AddTest extends RedisCacheTestCase
2019
{
21-
use MocksRedisConnections;
22-
2320
/**
2421
* @test
2522
*/

tests/Cache/Redis/Operations/AllTag/AddEntryTest.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,22 @@
44

55
namespace Hypervel\Tests\Cache\Redis\Operations\AllTag;
66

7-
use Carbon\Carbon;
87
use Hypervel\Cache\Redis\Operations\AllTag\AddEntry;
9-
use Hypervel\Testbench\TestCase;
10-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
8+
use Hypervel\Tests\Cache\Redis\RedisCacheTestCase;
119

1210
/**
1311
* Tests for the AddEntry operation.
1412
*
1513
* @internal
1614
* @coversNothing
1715
*/
18-
class AddEntryTest extends TestCase
16+
class AddEntryTest extends RedisCacheTestCase
1917
{
20-
use MocksRedisConnections;
21-
2218
/**
2319
* @test
2420
*/
2521
public function testAddEntryWithTtl(): void
2622
{
27-
Carbon::setTestNow('2000-01-01 00:00:00');
28-
2923
$connection = $this->mockConnection();
3024
$client = $connection->_mockClient;
3125

@@ -151,8 +145,6 @@ public function testAddEntryWithUpdateWhenXxCondition(): void
151145
*/
152146
public function testAddEntryWithUpdateWhenGtCondition(): void
153147
{
154-
Carbon::setTestNow('2000-01-01 00:00:00');
155-
156148
$connection = $this->mockConnection();
157149
$client = $connection->_mockClient;
158150

@@ -178,8 +170,6 @@ public function testAddEntryWithUpdateWhenGtCondition(): void
178170
*/
179171
public function testAddEntryWithMultipleTags(): void
180172
{
181-
Carbon::setTestNow('2000-01-01 00:00:00');
182-
183173
$connection = $this->mockConnection();
184174
$client = $connection->_mockClient;
185175

@@ -252,8 +242,6 @@ public function testAddEntryUsesCorrectPrefix(): void
252242
*/
253243
public function testAddEntryClusterModeUsesSequentialCommands(): void
254244
{
255-
Carbon::setTestNow('2000-01-01 00:00:00');
256-
257245
[$store, $clusterClient] = $this->createClusterStore();
258246

259247
// Should NOT use pipeline in cluster mode
@@ -274,8 +262,6 @@ public function testAddEntryClusterModeUsesSequentialCommands(): void
274262
*/
275263
public function testAddEntryClusterModeWithMultipleTags(): void
276264
{
277-
Carbon::setTestNow('2000-01-01 00:00:00');
278-
279265
[$store, $clusterClient] = $this->createClusterStore();
280266

281267
// Should NOT use pipeline in cluster mode

tests/Cache/Redis/Operations/AllTag/AddTest.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace Hypervel\Tests\Cache\Redis\Operations\AllTag;
66

7-
use Carbon\Carbon;
8-
use Hypervel\Testbench\TestCase;
9-
use Hypervel\Tests\Cache\Redis\Concerns\MocksRedisConnections;
7+
use Hypervel\Tests\Cache\Redis\RedisCacheTestCase;
108

119
/**
1210
* Tests for the Add operation (intersection tags).
@@ -17,17 +15,13 @@
1715
* @internal
1816
* @coversNothing
1917
*/
20-
class AddTest extends TestCase
18+
class AddTest extends RedisCacheTestCase
2119
{
22-
use MocksRedisConnections;
23-
2420
/**
2521
* @test
2622
*/
2723
public function testAddWithTagsReturnsTrueWhenKeyAdded(): void
2824
{
29-
Carbon::setTestNow('2000-01-01 00:00:00');
30-
3125
$connection = $this->mockConnection();
3226
$client = $connection->_mockClient;
3327

@@ -65,8 +59,6 @@ public function testAddWithTagsReturnsTrueWhenKeyAdded(): void
6559
*/
6660
public function testAddWithTagsReturnsFalseWhenKeyExists(): void
6761
{
68-
Carbon::setTestNow('2000-01-01 00:00:00');
69-
7062
$connection = $this->mockConnection();
7163
$client = $connection->_mockClient;
7264

@@ -97,8 +89,6 @@ public function testAddWithTagsReturnsFalseWhenKeyExists(): void
9789
*/
9890
public function testAddWithMultipleTags(): void
9991
{
100-
Carbon::setTestNow('2000-01-01 00:00:00');
101-
10292
$connection = $this->mockConnection();
10393
$client = $connection->_mockClient;
10494

@@ -170,8 +160,6 @@ public function testAddWithEmptyTagsSkipsPipeline(): void
170160
*/
171161
public function testAddInClusterModeUsesSequentialCommands(): void
172162
{
173-
Carbon::setTestNow('2000-01-01 00:00:00');
174-
175163
[$store, $clusterClient] = $this->createClusterStore();
176164

177165
// Should NOT use pipeline in cluster mode
@@ -204,8 +192,6 @@ public function testAddInClusterModeUsesSequentialCommands(): void
204192
*/
205193
public function testAddInClusterModeReturnsFalseWhenKeyExists(): void
206194
{
207-
Carbon::setTestNow('2000-01-01 00:00:00');
208-
209195
[$store, $clusterClient] = $this->createClusterStore();
210196

211197
// Sequential ZADD (still happens even if key exists)
@@ -263,8 +249,6 @@ public function testAddEnforcesMinimumTtlOfOne(): void
263249
*/
264250
public function testAddWithNumericValue(): void
265251
{
266-
Carbon::setTestNow('2000-01-01 00:00:00');
267-
268252
$connection = $this->mockConnection();
269253
$client = $connection->_mockClient;
270254

0 commit comments

Comments
 (0)