From aaac08232439e88966a7a9088689e70bfda1f4fb Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 16 Nov 2013 16:34:34 +0100 Subject: [PATCH] Rename classes in Predis\Transaction. --- lib/Predis/Client.php | 8 +++--- .../Transaction/AbortedMultiExecException.php | 6 ++--- .../{MultiExecContext.php => MultiExec.php} | 26 +++++++++++-------- tests/Predis/ClientTest.php | 8 +++--- .../AbortedMultiExecExceptionTest.php | 2 +- ...iExecContextTest.php => MultiExecTest.php} | 12 ++++----- 6 files changed, 33 insertions(+), 29 deletions(-) rename lib/Predis/Transaction/{MultiExecContext.php => MultiExec.php} (94%) rename tests/Predis/Transaction/{MultiExecContextTest.php => MultiExecTest.php} (98%) diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index db7ff131..b6c1967c 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -25,7 +25,7 @@ use Predis\Pipeline\PipelineContext; use Predis\Profile\ServerProfile; use Predis\PubSub; use Predis\Response; -use Predis\Transaction\MultiExecContext; +use Predis\Transaction; /** * Client class used for connecting and executing commands on Redis. @@ -391,7 +391,7 @@ class Client implements ClientInterface * of a transaction executed inside the optionally provided callable object. * * @param mixed $arg,... Options for the context, or a callable, or both. - * @return MultiExecContext|array + * @return Transaction\MultiExec|array */ public function transaction(/* arguments */) { @@ -403,11 +403,11 @@ class Client implements ClientInterface * * @param array $options Options for the context. * @param mixed $callable Optional callable used to execute the context. - * @return MultiExecContext|array + * @return Transaction\MultiExec|array */ protected function createTransaction(Array $options = null, $callable = null) { - $transaction = new MultiExecContext($this, $options); + $transaction = new Transaction\MultiExec($this, $options); if (isset($callable)) { return $transaction->execute($callable); diff --git a/lib/Predis/Transaction/AbortedMultiExecException.php b/lib/Predis/Transaction/AbortedMultiExecException.php index bccaa870..2365bbf5 100644 --- a/lib/Predis/Transaction/AbortedMultiExecException.php +++ b/lib/Predis/Transaction/AbortedMultiExecException.php @@ -23,11 +23,11 @@ class AbortedMultiExecException extends PredisException private $transaction; /** - * @param MultiExecContext $transaction Transaction that generated the exception. + * @param MultiExec $transaction Transaction that generated the exception. * @param string $message Error message. * @param int $code Error code. */ - public function __construct(MultiExecContext $transaction, $message, $code = null) + public function __construct(MultiExec $transaction, $message, $code = null) { parent::__construct($message, $code); $this->transaction = $transaction; @@ -36,7 +36,7 @@ class AbortedMultiExecException extends PredisException /** * Returns the transaction that generated the exception. * - * @return MultiExecContext + * @return MultiExec */ public function getTransaction() { diff --git a/lib/Predis/Transaction/MultiExecContext.php b/lib/Predis/Transaction/MultiExec.php similarity index 94% rename from lib/Predis/Transaction/MultiExecContext.php rename to lib/Predis/Transaction/MultiExec.php index e2dc2f2f..5049ddf3 100644 --- a/lib/Predis/Transaction/MultiExecContext.php +++ b/lib/Predis/Transaction/MultiExec.php @@ -28,7 +28,7 @@ use Predis\Protocol\ProtocolException; * * @author Daniele Alessandri */ -class MultiExecContext implements BasicClientInterface, ExecutableContextInterface +class MultiExec implements BasicClientInterface, ExecutableContextInterface { const STATE_RESET = 0; // 0b00000 const STATE_INITIALIZED = 1; // 0b00001 @@ -45,8 +45,8 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa protected $commands; /** - * @param ClientInterface $client Client instance used by the context. - * @param array $options Options for the context initialization. + * @param ClientInterface $client Client instance used by the transaction. + * @param array $options Initialization options. */ public function __construct(ClientInterface $client, Array $options = null) { @@ -109,20 +109,24 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa /** * Checks if the passed client instance satisfies the required conditions - * needed to initialize a transaction context. + * needed to initialize the transaction object. * - * @param ClientInterface $client Client instance used by the context. + * @param ClientInterface $client Client instance used by the transaction object. */ private function checkCapabilities(ClientInterface $client) { if ($client->getConnection() instanceof AggregatedConnectionInterface) { - throw new NotSupportedException('Cannot initialize a MULTI/EXEC context when using aggregated connections'); + throw new NotSupportedException( + 'Cannot initialize a MULTI/EXEC transaction when using aggregated connections' + ); } $profile = $client->getProfile(); if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) { - throw new NotSupportedException('The current profile does not support MULTI, EXEC and DISCARD'); + throw new NotSupportedException( + 'The current profile does not support MULTI, EXEC and DISCARD' + ); } $this->canWatch = $profile->supportsCommands(array('watch', 'unwatch')); @@ -242,7 +246,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa /** * Finalizes the transaction on the server by executing MULTI on the server. * - * @return MultiExecContext + * @return MultiExec */ public function multi() { @@ -259,7 +263,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa /** * Executes UNWATCH. * - * @return MultiExecContext + * @return MultiExec */ public function unwatch() { @@ -274,7 +278,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa * Resets a transaction by UNWATCHing the keys that are being WATCHed and * DISCARDing the pending commands that have been already sent to the server. * - * @return MultiExecContext + * @return MultiExec */ public function discard() { @@ -398,7 +402,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa } /** - * Passes the current transaction context to a callable block for execution. + * Passes the current transaction object to a callable block for execution. * * @param mixed $callable Callback. */ diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 3ea8b889..c7f42112 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -688,23 +688,23 @@ class ClientTest extends StandardTestCase /** * @group disconnected */ - public function testTransactionWithoutArgumentsReturnsMultiExecContext() + public function testTransactionWithoutArgumentsReturnsMultiExec() { $client = new Client(); - $this->assertInstanceOf('Predis\Transaction\MultiExecContext', $client->transaction()); + $this->assertInstanceOf('Predis\Transaction\MultiExec', $client->transaction()); } /** * @group disconnected */ - public function testTransactionWithArrayReturnsMultiExecContextWithOptions() + public function testTransactionWithArrayReturnsTransactionMultiExecWithOptions() { $options = array('cas' => true, 'retry' => 3); $client = new Client(); - $this->assertInstanceOf('Predis\Transaction\MultiExecContext', $tx = $client->transaction($options)); + $this->assertInstanceOf('Predis\Transaction\MultiExec', $tx = $client->transaction($options)); $reflection = new \ReflectionProperty($tx, 'options'); $reflection->setAccessible(true); diff --git a/tests/Predis/Transaction/AbortedMultiExecExceptionTest.php b/tests/Predis/Transaction/AbortedMultiExecExceptionTest.php index 101831b0..3801c811 100644 --- a/tests/Predis/Transaction/AbortedMultiExecExceptionTest.php +++ b/tests/Predis/Transaction/AbortedMultiExecExceptionTest.php @@ -26,7 +26,7 @@ class AbortedMultiExecExceptionTest extends StandardTestCase public function testExceptionClass() { $client = new Client(); - $transaction = new MultiExecContext($client); + $transaction = new MultiExec($client); $exception = new AbortedMultiExecException($transaction, 'ABORTED'); $this->assertInstanceOf('Predis\PredisException', $exception); diff --git a/tests/Predis/Transaction/MultiExecContextTest.php b/tests/Predis/Transaction/MultiExecTest.php similarity index 98% rename from tests/Predis/Transaction/MultiExecContextTest.php rename to tests/Predis/Transaction/MultiExecTest.php index 5eecc43b..56060f71 100644 --- a/tests/Predis/Transaction/MultiExecContextTest.php +++ b/tests/Predis/Transaction/MultiExecTest.php @@ -20,7 +20,7 @@ use Predis\Response; /** * @group realm-transaction */ -class MultiExecContextTest extends StandardTestCase +class MultiExecTest extends StandardTestCase { /** * @group disconnected @@ -31,7 +31,7 @@ class MultiExecContextTest extends StandardTestCase { $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); $client = new Client($connection, array('profile' => '1.2')); - $tx = new MultiExecContext($client); + $tx = new MultiExec($client); } /** @@ -43,7 +43,7 @@ class MultiExecContextTest extends StandardTestCase { $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); $client = new Client($connection, array('profile' => '2.0')); - $tx = new MultiExecContext($client, array('options' => 'cas')); + $tx = new MultiExec($client, array('options' => 'cas')); $tx->watch('foo'); } @@ -645,18 +645,18 @@ class MultiExecContextTest extends StandardTestCase } /** - * Returns a mocked instance of Predis\Transaction\MultiExecContext using + * Returns a mocked instance of Predis\Transaction\MultiExec using * the specified callback to return values from the executeCommand method * of the underlying connection. * * @param \Closure $executeCallback - * @return MultiExecContext + * @return MultiExec */ protected function getMockedTransaction($executeCallback, $options = array()) { $connection = $this->getMockedConnection($executeCallback); $client = new Client($connection); - $transaction = new MultiExecContext($client, $options); + $transaction = new MultiExec($client, $options); return $transaction; }