Skip to content

Commit 8a1a5a2

Browse files
authored
[10.x] Test Improvements for Cache tests (#50684)
* [10.x] Test Improvements for Cache tests Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Update MemcachedTaggedCacheTestCase.php * Update PhpRedisCacheLockTest.php * wip --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent f2ec6fa commit 8a1a5a2

File tree

7 files changed

+18
-58
lines changed

7 files changed

+18
-58
lines changed

tests/Integration/Cache/DynamoDbStoreTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@
77
use Illuminate\Contracts\Cache\Repository;
88
use Illuminate\Support\Facades\Cache;
99
use Illuminate\Support\Str;
10+
use Orchestra\Testbench\Attributes\RequiresEnv;
1011
use Orchestra\Testbench\TestCase;
1112

13+
#[RequiresEnv('DYNAMODB_CACHE_TABLE')]
1214
class DynamoDbStoreTest extends TestCase
1315
{
14-
protected function setUp(): void
15-
{
16-
if (! env('DYNAMODB_CACHE_TABLE')) {
17-
$this->markTestSkipped('DynamoDB not configured.');
18-
}
19-
20-
parent::setUp();
21-
}
22-
2316
public function testItemsCanBeStoredAndRetrieved()
2417
{
2518
Cache::driver('dynamodb')->put('name', 'Taylor', 10);

tests/Integration/Cache/FileCacheLockTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@
44

55
use Exception;
66
use Illuminate\Support\Facades\Cache;
7+
use Orchestra\Testbench\Attributes\WithConfig;
78
use Orchestra\Testbench\TestCase;
89

10+
#[WithConfig('cache.default', 'file')]
911
class FileCacheLockTest extends TestCase
1012
{
11-
/**
12-
* Define environment setup.
13-
*
14-
* @param \Illuminate\Foundation\Application $app
15-
* @return void
16-
*/
17-
protected function getEnvironmentSetUp($app)
18-
{
19-
$app['config']->set('cache.default', 'file');
20-
}
21-
2213
public function testLocksCanBeAcquiredAndReleased()
2314
{
2415
Cache::lock('foo')->forceRelease();

tests/Integration/Cache/MemcachedCacheLockTestCase.php

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

55
use Illuminate\Contracts\Cache\LockTimeoutException;
66
use Illuminate\Support\Facades\Cache;
7+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
78

8-
/**
9-
* @requires extension memcached
10-
*/
9+
#[RequiresPhpExtension('memcached')]
1110
class MemcachedCacheLockTestCase extends MemcachedIntegrationTestCase
1211
{
1312
public function testMemcachedLocksCanBeAcquiredAndReleased()

tests/Integration/Cache/MemcachedTaggedCacheTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Illuminate\Tests\Integration\Cache;
44

55
use Illuminate\Support\Facades\Cache;
6+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
67

7-
/**
8-
* @requires extension memcached
9-
*/
8+
#[RequiresPhpExtension('memcached')]
109
class MemcachedTaggedCacheTestCase extends MemcachedIntegrationTestCase
1110
{
1211
public function testMemcachedCanStoreAndRetrieveTaggedCacheItems()

tests/Integration/Cache/NoLockTest.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@
33
namespace Illuminate\Tests\Integration\Cache;
44

55
use Illuminate\Support\Facades\Cache;
6+
use Orchestra\Testbench\Attributes\WithConfig;
67
use Orchestra\Testbench\TestCase;
78

9+
#[WithConfig('cache.default', 'null')]
10+
#[WithConfig('cache.stores.null', ['driver' => 'null'])]
811
class NoLockTest extends TestCase
912
{
10-
/**
11-
* Define environment setup.
12-
*
13-
* @param \Illuminate\Foundation\Application $app
14-
* @return void
15-
*/
16-
protected function getEnvironmentSetUp($app)
17-
{
18-
$app['config']->set('cache.default', 'null');
19-
20-
$app['config']->set('cache.stores', [
21-
'null' => [
22-
'driver' => 'null',
23-
],
24-
]);
25-
}
26-
2713
public function testLocksCanAlwaysBeAcquiredAndReleased()
2814
{
2915
Cache::lock('foo')->forceRelease();

tests/Integration/Cache/PhpRedisCacheLockTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
66
use Illuminate\Support\Facades\Cache;
77
use Orchestra\Testbench\TestCase;
8+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
89
use Redis;
910

1011
class PhpRedisCacheLockTest extends TestCase
@@ -138,9 +139,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithMsgpackSerialization()
138139
$this->assertNull($store->lockConnection()->get($store->getPrefix().'foo'));
139140
}
140141

141-
/**
142-
* @requires extension lzf
143-
*/
142+
#[RequiresPhpExtension('lzf')]
144143
public function testRedisLockCanBeAcquiredAndReleasedWithLzfCompression()
145144
{
146145
if (! defined('Redis::COMPRESSION_LZF')) {
@@ -167,9 +166,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithLzfCompression()
167166
$this->assertNull($store->lockConnection()->get($store->getPrefix().'foo'));
168167
}
169168

170-
/**
171-
* @requires extension zstd
172-
*/
169+
#[RequiresPhpExtension('zstd')]
173170
public function testRedisLockCanBeAcquiredAndReleasedWithZstdCompression()
174171
{
175172
if (! defined('Redis::COMPRESSION_ZSTD')) {
@@ -215,9 +212,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithZstdCompression()
215212
$this->assertNull($store->lockConnection()->get($store->getPrefix().'foo'));
216213
}
217214

218-
/**
219-
* @requires extension lz4
220-
*/
215+
#[RequiresPhpExtension('lz4')]
221216
public function testRedisLockCanBeAcquiredAndReleasedWithLz4Compression()
222217
{
223218
if (! defined('Redis::COMPRESSION_LZ4')) {
@@ -263,9 +258,7 @@ public function testRedisLockCanBeAcquiredAndReleasedWithLz4Compression()
263258
$this->assertNull($store->lockConnection()->get($store->getPrefix().'foo'));
264259
}
265260

266-
/**
267-
* @requires extension Lzf
268-
*/
261+
#[RequiresPhpExtension('Lzf')]
269262
public function testRedisLockCanBeAcquiredAndReleasedWithSerializationAndCompression()
270263
{
271264
if (! defined('Redis::COMPRESSION_LZF')) {

tests/Integration/Cache/Psr6RedisTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\Cache;
77
use Illuminate\Tests\Integration\Cache\Fixtures\Unserializable;
88
use Orchestra\Testbench\TestCase;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910

1011
class Psr6RedisTest extends TestCase
1112
{
@@ -25,9 +26,7 @@ protected function tearDown(): void
2526
$this->tearDownRedis();
2627
}
2728

28-
/**
29-
* @dataProvider redisClientDataProvider
30-
*/
29+
#[DataProvider('redisClientDataProvider')]
3130
public function testTransactionIsNotOpenedWhenSerializationFails($redisClient): void
3231
{
3332
$this->app['config']['cache.default'] = 'redis';

0 commit comments

Comments
 (0)