Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Redis drivers to new namespace #341

Merged
merged 2 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/drivers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@ your ``composer.json`` file, to make sure it is installed:

<?php

use Bernard\Driver\PhpRedisDriver;
use Bernard\Driver\PhpRedis\Driver;

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->setOption(Redis::OPT_PREFIX, 'bernard:');

$driver = new PhpRedisDriver($redis);
$driver = new Driver($redis);

Predis
------
Expand All @@ -415,14 +415,14 @@ Requires the installation of predis. Add the following to your

<?php

use Bernard\Driver\PredisDriver;
use Bernard\Driver\Predis\Driver;
use Predis\Client;

$predis = new Client('tcp://localhost', array(
'prefix' => 'bernard:',
));

$driver = new PredisDriver($predis);
$driver = new Driver($predis);

Amazon SQS
----------
Expand Down
4 changes: 2 additions & 2 deletions example/phpredis.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Bernard\Driver\PhpRedisDriver;
use Bernard\Driver\PhpRedis\Driver;

/**
* Must be defined before including bootstrap.php
Expand All @@ -11,7 +11,7 @@ function get_driver() {
$redis->connect('localhost');
$redis->setOption(Redis::OPT_PREFIX, 'bernard:');

return new PhpRedisDriver($redis);
return new Driver($redis);
}

require 'bootstrap.php';
4 changes: 2 additions & 2 deletions example/predis.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

use Predis\Client;
use Bernard\Driver\PredisDriver;
use Bernard\Driver\Predis\Driver;

/**
* Must be defined before including bootstrap.php
* as this is the only custom part in the example.
*/
function get_driver() {
return new PredisDriver(new Client(null, array(
return new Driver(new Client(null, array(
'prefix' => 'bernard:',
)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bernard\Driver;
namespace Bernard\Driver\PhpRedis;

use Redis;

Expand All @@ -9,7 +9,7 @@
*
* @package Bernard
*/
class PhpRedisDriver implements \Bernard\Driver
class Driver implements \Bernard\Driver
{
protected $redis;

Expand Down
6 changes: 2 additions & 4 deletions src/Driver/PredisDriver.php → src/Driver/Predis/Driver.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

namespace Bernard\Driver;
namespace Bernard\Driver\Predis;

use Predis\ClientInterface;

/**
* @package Bernard
*/
class PredisDriver extends PhpRedisDriver
final class Driver extends \Bernard\Driver\PhpRedis\Driver
{
protected $redis;

/**
* @param ClientInterface $redis
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Bernard\Tests\Driver;
namespace Bernard\Tests\Driver\PhpRedis;

use Bernard\Driver\PhpRedisDriver;
use Bernard\Driver\PhpRedis\Driver;

class PhpRedisDriverTest extends \PHPUnit\Framework\TestCase
class DriverTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
Expand All @@ -25,12 +25,12 @@ public function setUp()
'sRem',
))->getMock();

$this->connection = new PhpRedisDriver($this->redis);
$this->connection = new Driver($this->redis);
}

public function testItImplementsDriverInterface()
{
$this->assertInstanceOf('Bernard\Driver', $this->connection);
$this->assertInstanceOf(\Bernard\Driver::class, $this->connection);
}

public function testItCountsNumberOfMessagesInQueue()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php

namespace Bernard\Tests\Driver;
namespace Bernard\Tests\Driver\Predis;

use Bernard\Driver\PredisDriver;
use Bernard\Driver\Predis\Driver;
use Predis\Client;

class PredisDriverTest extends PhpRedisDriverTest
class DriverTest extends \Bernard\Tests\Driver\PhpRedis\DriverTest
{
public function setUp()
{
// Because predis uses __call all methods that needs mocking must be
// explicitly defined.
$this->redis = $this->getMockBuilder('Predis\Client')->setMethods(array(
$this->redis = $this->getMockBuilder(Client::class)->setMethods(array(
'lLen',
'sMembers',
'lRange',
Expand All @@ -23,7 +24,7 @@ public function setUp()
'sRem',
))->getMock();

$this->connection = new PredisDriver($this->redis);
$this->connection = new Driver($this->redis);
}

public function testItPopMessages()
Expand Down