Skip to content

Commit f792f96

Browse files
committed
- updates the namespace
- skips tests if Redis or memcached are not available
1 parent e292cbf commit f792f96

10 files changed

Lines changed: 90 additions & 47 deletions

Tests/CacheItemTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
namespace Koded\Caching;
3+
namespace Tests\Koded\Caching;
44

5+
use Koded\Caching\CachePool;
56
use PHPUnit\Framework\TestCase;
67

78
class CacheItemTest extends TestCase
89
{
9-
1010
public function test_expiresAfter_with_global_ttl()
1111
{
1212
$pool = CachePool::use('memory', ['ttl' => 60]);

Tests/CachePoolFactoryTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
<?php
22

3-
namespace Koded\Caching;
3+
namespace Tests\Koded\Caching;
44

5-
use Koded\Caching\Client\{FileClient, MemcachedClient, MemoryClient, PredisClient, RedisClient};
5+
use Koded\Caching\Client\{FileClient, MemcachedClient, MemoryClient, PredisClient, RedisClient, ShmopClient};
6+
use Koded\Caching\CachePool;
67
use PHPUnit\Framework\TestCase;
78

89
class CachePoolFactoryTest extends TestCase
910
{
10-
1111
public function test_MemcachedClient()
1212
{
13+
if (false === \extension_loaded('memcached')) {
14+
$this->markTestSkipped('memcached extension is not loaded');
15+
}
1316
$pool = CachePool::use('memcached');
1417
$this->assertAttributeInstanceOf(MemcachedClient::class, 'client', $pool);
1518
}
1619

1720
public function test_RedisClient()
1821
{
22+
if (false === \extension_loaded('redis')) {
23+
$this->markTestSkipped('redis extension is not loaded');
24+
}
1925
$pool = CachePool::use('redis', [
2026
'host' => getenv('REDIS_SERVER_HOST'),
2127
]);
@@ -24,12 +30,24 @@ public function test_RedisClient()
2430

2531
public function test_PredisClient()
2632
{
33+
if (false === \extension_loaded('redis')) {
34+
$this->markTestSkipped('redis extension is not loaded');
35+
}
2736
$pool = CachePool::use('predis', [
2837
'host' => getenv('REDIS_SERVER_HOST'),
2938
]);
3039
$this->assertAttributeInstanceOf(PredisClient::class, 'client', $pool);
3140
}
3241

42+
public function test_ShmopClient()
43+
{
44+
if (false === \extension_loaded('shmop')) {
45+
$this->markTestSkipped('shmop extension is not loaded');
46+
}
47+
$pool = CachePool::use('shmop');
48+
$this->assertAttributeInstanceOf(ShmopClient::class, 'client', $pool);
49+
}
50+
3351
public function test_MemoryClient()
3452
{
3553
$pool1 = CachePool::use('memory');

Tests/Integration/CachePoolIntegrationTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

55
use Cache\IntegrationTests\CachePoolTest;
66

77
abstract class CachePoolIntegrationTest extends CachePoolTest
88
{
9+
protected $skippedTests = [
10+
'testGetItemInvalidKeys' => 'Does not make sense for typed arguments',
11+
'testGetItemsInvalidKeys' => 'Does not make sense for typed arguments',
12+
'testHasItemInvalidKeys' => 'Does not make sense for typed arguments',
13+
];
914

1015
public static function invalidKeys()
1116
{

Tests/Integration/FileClientTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

55
use Koded\Caching\CachePool;
66
use org\bovigo\vfs\{vfsStream, vfsStreamDirectory};
77
use Psr\Cache\CacheItemPoolInterface;
88

99
class FileClientTest extends CachePoolIntegrationTest
1010
{
11-
12-
/**
13-
* @var vfsStreamDirectory
14-
*/
15-
private $dir;
11+
private vfsStreamDirectory $dir;
1612

1713
/**
1814
* @return CacheItemPoolInterface that is used in the tests

Tests/Integration/MemcachedClientTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

55
use Koded\Caching\CachePool;
66
use Psr\Cache\CacheItemPoolInterface;
77

88
class MemcachedClientTest extends CachePoolIntegrationTest
99
{
10-
1110
/**
1211
* @return CacheItemPoolInterface that is used in the tests
1312
*/
1413
public function createCachePool()
1514
{
16-
return CachePool::use('redis', [
17-
'host' => getenv('REDIS_SERVER_HOST'),
18-
'servers' => [["memcached", 11211]],
15+
if (false === \extension_loaded('memcached')) {
16+
$this->markTestSkipped('Memcached extension is not loaded.');
17+
}
18+
19+
return CachePool::use('memcached', [
20+
'servers' => [["memcached", 11211], ['127.0.0.1', 11211]],
1921
]);
2022
}
2123

2224
protected function setUp(): void
2325
{
24-
if (false === extension_loaded('memcached')) {
26+
if (false === \extension_loaded('memcached')) {
2527
$this->markTestSkipped('Memcached extension is not loaded.');
2628
}
2729

28-
$this->skippedTests = [
29-
'testKeyLength' => 'Memcached max key length is 250 chars',
30-
];
30+
$this->skippedTests['testKeyLength'] = 'Memcached max key length is 250 chars';
3131

3232
parent::setUp();
3333
}

Tests/Integration/MemoryClientTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

55
use Koded\Caching\CachePool;
66
use Psr\Cache\CacheItemPoolInterface;
77

88
class MemoryClientTest extends CachePoolIntegrationTest
99
{
10-
1110
/**
1211
* @return CacheItemPoolInterface that is used in the tests
1312
*/
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

5+
use Koded\Caching\CacheException;
56
use Koded\Caching\CachePool;
67
use Psr\Cache\CacheItemPoolInterface;
78

89
class PredisClientTest extends CachePoolIntegrationTest
910
{
10-
1111
/**
1212
* @return CacheItemPoolInterface that is used in the tests
1313
*/
1414
public function createCachePool()
1515
{
16-
return CachePool::use('predis', [
17-
'host' => getenv('REDIS_SERVER_HOST'),
18-
]);
16+
try {
17+
$client = CachePool::use('predis',
18+
[
19+
'host' => getenv('REDIS_SERVER_HOST'),
20+
]);
21+
$client->client()->connect();
22+
return $client;
23+
} catch (CacheException $e) {
24+
$this->markTestSkipped($e->getMessage());
25+
}
1926
}
2027
}
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

5+
use Koded\Caching\CacheException;
56
use Koded\Caching\CachePool;
6-
use Koded\Stdlib\Interfaces\Serializer;
7+
use Koded\Stdlib\Serializer;
78
use Psr\Cache\CacheItemPoolInterface;
89

910
class PredisJsonClientTest extends CachePoolIntegrationTest
@@ -13,10 +14,17 @@ class PredisJsonClientTest extends CachePoolIntegrationTest
1314
*/
1415
public function createCachePool()
1516
{
16-
return CachePool::use('predis', [
17-
'host' => getenv('REDIS_SERVER_HOST'),
18-
'serializer' => Serializer::JSON,
19-
'binary' => Serializer::PHP,
20-
]);
17+
try {
18+
$client = CachePool::use('predis',
19+
[
20+
'host' => getenv('REDIS_SERVER_HOST'),
21+
'serializer' => Serializer::JSON,
22+
'binary' => Serializer::PHP,
23+
]);
24+
$client->client()->connect();
25+
return $client;
26+
} catch (CacheException $e) {
27+
$this->markTestSkipped($e->getMessage());
28+
}
2129
}
2230
}

Tests/Integration/RedisClientTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

5+
use Koded\Caching\CacheException;
56
use Koded\Caching\CachePool;
67
use Psr\Cache\CacheItemPoolInterface;
78

89
class RedisClientTest extends CachePoolIntegrationTest
910
{
10-
1111
/**
1212
* @return CacheItemPoolInterface that is used in the tests
1313
*/
1414
public function createCachePool()
1515
{
16-
return CachePool::use('redis', [
17-
'host' => getenv('REDIS_SERVER_HOST'),
18-
]);
16+
try {
17+
return CachePool::use('redis', [
18+
'host' => getenv('REDIS_SERVER_HOST'),
19+
]);
20+
} catch (CacheException $e) {
21+
$this->markTestSkipped($e->getMessage());
22+
}
1923
}
2024

2125
protected function setUp(): void

Tests/Integration/RedisJsonClientTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
namespace Koded\Caching\Tests\Integration;
3+
namespace Tests\Koded\Caching\Integration;
44

5+
use Koded\Caching\CacheException;
56
use Koded\Caching\CachePool;
6-
use Koded\Stdlib\Interfaces\Serializer;
7+
use Koded\Stdlib\Serializer;
78
use Psr\Cache\CacheItemPoolInterface;
89

910
class RedisJsonClientTest extends CachePoolIntegrationTest
@@ -13,12 +14,17 @@ class RedisJsonClientTest extends CachePoolIntegrationTest
1314
*/
1415
public function createCachePool()
1516
{
16-
return CachePool::use('redis', [
17-
'host' => getenv('REDIS_SERVER_HOST'),
17+
try {
18+
return CachePool::use('redis',
19+
[
20+
'host' => getenv('REDIS_SERVER_HOST'),
1821

19-
'serializer' => Serializer::JSON,
20-
'binary' => Serializer::PHP,
21-
]);
22+
'serializer' => Serializer::JSON,
23+
'binary' => Serializer::PHP,
24+
]);
25+
} catch (CacheException $e) {
26+
$this->markTestSkipped($e->getMessage());
27+
}
2228
}
2329

2430
protected function setUp(): void

0 commit comments

Comments
 (0)