Skip to content

Commit 03faa65

Browse files
committed
check if pecl extesion is enabled for tests
1 parent 46cdf3a commit 03faa65

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/Connectors/PhpRedisConnector.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Redis\Connectors\PhpRedisConnector as LaravelPhpRedisConnector;
7+
use LogicException;
78
use Monospice\LaravelRedisSentinel\Connections\PhpRedisConnection;
89
use Redis;
910
use RedisSentinel;
@@ -88,10 +89,13 @@ public function connect(array $servers, array $options = [ ])
8889
*
8990
* @param array $options
9091
* @return Redis
92+
*
93+
* @throws LogicException
9194
*/
9295
protected function createClientWithSentinel(array $options)
9396
{
9497
$servers = $this->servers;
98+
$service = isset($options['service']) ? $options['service'] : 'mymaster';
9599
$timeout = isset($options['sentinel_timeout']) ? $options['sentinel_timeout'] : 0;
96100
$persistent = isset($options['sentinel_peristent']) ? $options['sentinel_peristent'] : null;
97101
$retryWait = isset($options['retry_wait']) ? $options['retry_wait'] : 0;
@@ -101,11 +105,20 @@ protected function createClientWithSentinel(array $options)
101105
// Shuffle the servers to perform some loadbalancing.
102106
shuffle($servers);
103107

108+
// Check if the redis extension is enabled.
109+
if (! extension_loaded('redis')) {
110+
throw new LogicException('Please make sure the PHP Redis extension is installed and enabled.');
111+
}
112+
113+
// Check if the extension is up to date and contains RedisSentinel.
114+
if (! class_exists(RedisSentinel::class)) {
115+
throw new LogicException('Please make sure the PHP Redis extension is up to date.');
116+
}
117+
104118
// Try to connect to any of the servers.
105119
foreach ($servers as $idx => $server) {
106120
$host = isset($server['host']) ? $server['host'] : 'localhost';
107121
$port = isset($server['port']) ? $server['port'] : 26739;
108-
$service = isset($options['service']) ? $options['service'] : 'mymaster';
109122

110123
// Create a connection to the Sentinel instance.
111124
$sentinel = new RedisSentinel($host, $port, $timeout, $persistent, $retryWait, $readTimeout);

tests/Integration/Connections/PhpRedisConnectionTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Monospice\LaravelRedisSentinel\Tests\Integration\Connections;
44

5-
use Mockery;
65
use Monospice\LaravelRedisSentinel\Connections\PhpRedisConnection;
76
use Monospice\LaravelRedisSentinel\Connectors\PhpRedisConnector;
87
use Monospice\LaravelRedisSentinel\Tests\Support\DummyException;
@@ -29,19 +28,13 @@ public function setUp()
2928
{
3029
parent::setUp();
3130

32-
$this->subject = $this->makeConnection();
33-
}
31+
if (! extension_loaded('redis')) {
32+
$this->markTestSkipped('The redis extension is not installed. Please install the extension to enable '.__CLASS__);
3433

35-
/**
36-
* Run this cleanup after each test.
37-
*
38-
* @return void
39-
*/
40-
public function tearDown()
41-
{
42-
parent::tearDown();
34+
return;
35+
}
4336

44-
Mockery::close();
37+
$this->subject = $this->makeConnection();
4538
}
4639

4740
public function testAllowsTransactionsOnAggregateConnection()

0 commit comments

Comments
 (0)