From 3602713d154880f06c1a7dd239921b822dbfefa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= <honza.kuchar@grifart.cz> Date: Sun, 8 May 2016 21:41:10 +0200 Subject: [PATCH] renamed: ICursorDriver -> ICursor (+all related objects) --- .../{CursorDriver.php => Cursor.php} | 2 +- ...sorDriverFactory.php => CursorFactory.php} | 10 ++-- .../{ICursorDriver.php => ICursor.php} | 2 +- src/PostgresDriver/ICursorDriverFactory.php | 11 ---- src/PostgresDriver/SemanticCursor.php | 12 ++--- src/PostgresDriver/TrackedCursor.php | 15 ++---- .../PostgresDriver/CursorDriverTest.phpt | 45 ---------------- tests/Store/PostgresDriver/CursorTest.phpt | 54 +++---------------- ...ursorInterfaceTest.php => ICursorTest.php} | 12 ++--- .../SemanticCursorIntegration.phpt | 12 ++--- ...ticCursor.phpt => SemanticCursorTest.phpt} | 17 +++--- .../PostgresDriver/TrackedCursorTest.phpt | 10 ++-- 12 files changed, 46 insertions(+), 156 deletions(-) rename src/PostgresDriver/{CursorDriver.php => Cursor.php} (98%) rename src/PostgresDriver/{CursorDriverFactory.php => CursorFactory.php} (81%) rename src/PostgresDriver/{ICursorDriver.php => ICursor.php} (98%) delete mode 100644 src/PostgresDriver/ICursorDriverFactory.php delete mode 100644 tests/Store/PostgresDriver/CursorDriverTest.phpt rename tests/Store/PostgresDriver/{CursorInterfaceTest.php => ICursorTest.php} (96%) rename tests/Store/PostgresDriver/{SemanticCursor.phpt => SemanticCursorTest.phpt} (90%) diff --git a/src/PostgresDriver/CursorDriver.php b/src/PostgresDriver/Cursor.php similarity index 98% rename from src/PostgresDriver/CursorDriver.php rename to src/PostgresDriver/Cursor.php index 7ecfa98..0685104 100644 --- a/src/PostgresDriver/CursorDriver.php +++ b/src/PostgresDriver/Cursor.php @@ -18,7 +18,7 @@ use Dibi\Row; * * @package Grifart\Mappi\Store\PostgresDriver */ -final class CursorDriver implements ICursorDriver +final class Cursor implements ICursor { /** @var Connection */ private $connection; diff --git a/src/PostgresDriver/CursorDriverFactory.php b/src/PostgresDriver/CursorFactory.php similarity index 81% rename from src/PostgresDriver/CursorDriverFactory.php rename to src/PostgresDriver/CursorFactory.php index 8164b1b..b317d2e 100644 --- a/src/PostgresDriver/CursorDriverFactory.php +++ b/src/PostgresDriver/CursorFactory.php @@ -7,7 +7,7 @@ namespace Grifart\Mappi\Store\PostgresDriver; use Dibi\Connection; -final class CursorDriverFactory +final class CursorFactory { /** @var Connection */ private $connection; @@ -22,16 +22,16 @@ final class CursorDriverFactory } /** - * Creates new instance of CursorDriver + * Creates new instance of Cursor * * Warning: creating cursor requires to be IN transaction block. * Please enter transaction before calling create() * * @param string $sql * @param bool $scroll - * @return ICursorDriver + * @return ICursor */ - public function create(string $sql, bool $scroll) : ICursorDriver + public function create(string $sql, bool $scroll) : ICursor { $this->connection->query( "DECLARE %n %SQL CURSOR FOR (%SQL)", @@ -40,7 +40,7 @@ final class CursorDriverFactory $sql ); - return new CursorDriver( + return new Cursor( $this->connection, $name ); diff --git a/src/PostgresDriver/ICursorDriver.php b/src/PostgresDriver/ICursor.php similarity index 98% rename from src/PostgresDriver/ICursorDriver.php rename to src/PostgresDriver/ICursor.php index 697c274..59b0ab4 100644 --- a/src/PostgresDriver/ICursorDriver.php +++ b/src/PostgresDriver/ICursor.php @@ -12,7 +12,7 @@ use Dibi\Connection; * @link http://www.postgresql.org/docs/8.1/static/sql-move.html * @package Grifart\Mappi\Store\PostgresDriver */ -interface ICursorDriver +interface ICursor { const FETCH_REMAINING = PHP_INT_MAX; const FETCH_FOREGOING = PHP_INT_MIN; diff --git a/src/PostgresDriver/ICursorDriverFactory.php b/src/PostgresDriver/ICursorDriverFactory.php deleted file mode 100644 index 5f8a6ce..0000000 --- a/src/PostgresDriver/ICursorDriverFactory.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php declare(strict_types = 1); -/** - * This file is part of mappi/store. - */ - -namespace Grifart\Mappi\Store\PostgresDriver; - -interface ICursorDriverFactory -{ - public function create(string $sql, bool $scroll) : ICursorDriver; -} \ No newline at end of file diff --git a/src/PostgresDriver/SemanticCursor.php b/src/PostgresDriver/SemanticCursor.php index 457f9c6..5d3ce73 100644 --- a/src/PostgresDriver/SemanticCursor.php +++ b/src/PostgresDriver/SemanticCursor.php @@ -16,15 +16,15 @@ namespace Grifart\Mappi\Store\PostgresDriver; * * @package Grifart\Mappi\Store\PostgresDriver */ -class SemanticCursor implements ICursorDriver +class SemanticCursor implements ICursor { - /** @var ICursorDriver */ + /** @var ICursor */ private $cursor; /** - * @param ICursorDriver $cursor + * @param ICursor $cursor */ - public function __construct(ICursorDriver $cursor) + public function __construct(ICursor $cursor) { $this->cursor = $cursor; } @@ -196,7 +196,7 @@ class SemanticCursor implements ICursorDriver public function fetchRemaining() : array { return $this->cursor->fetchRange( - ICursorDriver::FETCH_REMAINING + ICursor::FETCH_REMAINING ); } @@ -208,7 +208,7 @@ class SemanticCursor implements ICursorDriver public function fetchForegoing() : array { return $this->cursor->fetchRange( - ICursorDriver::FETCH_FOREGOING + ICursor::FETCH_FOREGOING ); } diff --git a/src/PostgresDriver/TrackedCursor.php b/src/PostgresDriver/TrackedCursor.php index fc4aaf6..d4b820a 100644 --- a/src/PostgresDriver/TrackedCursor.php +++ b/src/PostgresDriver/TrackedCursor.php @@ -7,17 +7,12 @@ namespace Grifart\Mappi\Store\PostgresDriver; use Dibi\Connection; -class TrackedCursor implements ICursorDriver +class TrackedCursor implements ICursor { - /** @var int */ - private $total; - - /** - * @var CursorPosition - */ + /** @var CursorPosition */ private $position; - /** @var ICursorDriver */ + /** @var ICursor */ private $cursor; /** @var Connection */ @@ -27,10 +22,10 @@ class TrackedCursor implements ICursorDriver * Tip: if you are not sure that cursor will be in initial state, call * ->moveToBeginning() after initialization. * @param Connection $connection - * @param ICursorDriver $cursor CursorDriver in initial state (index=0) + * @param ICursor $cursor Cursor in initial state (index=0) * @param CursorPosition $initialPosition */ - public function __construct(Connection $connection, ICursorDriver $cursor, CursorPosition $initialPosition) + public function __construct(Connection $connection, ICursor $cursor, CursorPosition $initialPosition) { $this->cursor = $cursor; $this->connection = $connection; diff --git a/tests/Store/PostgresDriver/CursorDriverTest.phpt b/tests/Store/PostgresDriver/CursorDriverTest.phpt deleted file mode 100644 index 1a32aae..0000000 --- a/tests/Store/PostgresDriver/CursorDriverTest.phpt +++ /dev/null @@ -1,45 +0,0 @@ -<?php -/** - * @testCase - */ - -namespace Grifart\Mappi\Tests\Store\Store\PostgresDriver; - -use Grifart\Mappi\Store\PostgresDriver\CursorDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorDriverFactory; -use Grifart\Mappi\Store\PostgresDriver\CursorException; -use Grifart\Mappi\Store\PostgresDriver\CursorFactory; -use Grifart\Mappi\Store\PostgresDriver\ICursorDriver; -use Grifart\Mappi\Tests\Store\BaseTest; -use Tester\Assert; - -require_once __DIR__ . "/../../bootstrap.php"; -require_once __DIR__ . "/CursorInterfaceTest.php"; - -class CursorDriverTest extends CursorInterfaceTest -{ - /** @var ICursorDriver */ - protected $uut; - - protected function setUp() - { - global $connection, $SQL_thousandRowsAscending; - $connection->begin(); - - $factory = new CursorDriverFactory($connection); - $this->uut = $factory->create($SQL_thousandRowsAscending, true); - - parent::setUp(); - } - - public function tearDown() - { - global $connection; - $connection->rollback(); - - parent::tearDown(); - } - -} - -(new CursorDriverTest())->run(); diff --git a/tests/Store/PostgresDriver/CursorTest.phpt b/tests/Store/PostgresDriver/CursorTest.phpt index 076f0c1..bb08846 100644 --- a/tests/Store/PostgresDriver/CursorTest.phpt +++ b/tests/Store/PostgresDriver/CursorTest.phpt @@ -5,18 +5,17 @@ namespace Grifart\Mappi\Tests\Store\Store\PostgresDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorException; -use Grifart\Mappi\Store\PostgresDriver\CursorDriver; use Grifart\Mappi\Store\PostgresDriver\CursorFactory; -use Tester\Assert; -use Tester\Environment; +use Grifart\Mappi\Store\PostgresDriver\ICursor; require_once __DIR__ . "/../../bootstrap.php"; -require_once __DIR__ . "/CursorInterfaceTest.php"; +require_once __DIR__ . "/ICursorTest.php"; -Environment::skip(); -class CursorTest extends CursorInterfaceTest +class CursorTest extends ICursorTest { + /** @var ICursor */ + protected $uut; + protected function setUp() { global $connection, $SQL_thousandRowsAscending; @@ -24,6 +23,7 @@ class CursorTest extends CursorInterfaceTest $factory = new CursorFactory($connection); $this->uut = $factory->create($SQL_thousandRowsAscending, true); + parent::setUp(); } @@ -35,46 +35,6 @@ class CursorTest extends CursorInterfaceTest parent::tearDown(); } - public function test_givenFirstPosition_whenMoveToLeft_thenGetError() - { - $this->uut->moveToFirst(); - - Assert::exception(function() { - $this->uut->moveBy(-1); - }, CursorException::class, CursorException::MESSAGE_OVERFLOW); - - // todo: unfortunately moveBy moved cursor into index=0 even when exception occured - // todo: this should be supported or should not modify state - - Assert::exception(function() { - $this->uut->fetchCurrentSingle(); - }, CursorException::class, CursorException::MESSAGE_NO_DATA_TO_FETCH); - } - - public function test_givenLastPosition_whenMoveToRight_thenGetError() - { - $this->uut->moveToLast(); - - Assert::exception(function() { - $this->uut->moveBy(1); - }, CursorException::class, CursorException::MESSAGE_OVERFLOW); - - // todo: unfortunately moveBy moved cursor into index=0 even when exception occured - // todo: this should be supported or should not modify state - - Assert::exception(function() { - $this->uut->fetchCurrentSingle(); - }, CursorException::class, CursorException::MESSAGE_NO_DATA_TO_FETCH); - } - - public function test_giveSomePosition_whenMoveToBeginning_thenGetError() - { - $this->uut->moveTo(1); - // todo: fixme? - Assert::exception(function() { - $this->uut->moveTo(0); - }, CursorException::class); - } } (new CursorTest())->run(); diff --git a/tests/Store/PostgresDriver/CursorInterfaceTest.php b/tests/Store/PostgresDriver/ICursorTest.php similarity index 96% rename from tests/Store/PostgresDriver/CursorInterfaceTest.php rename to tests/Store/PostgresDriver/ICursorTest.php index 76ff314..a022e02 100644 --- a/tests/Store/PostgresDriver/CursorInterfaceTest.php +++ b/tests/Store/PostgresDriver/ICursorTest.php @@ -5,21 +5,21 @@ namespace Grifart\Mappi\Tests\Store\Store\PostgresDriver; -use Grifart\Mappi\Store\PostgresDriver\ICursorDriver; +use Grifart\Mappi\Store\PostgresDriver\ICursor; use Grifart\Mappi\Tests\Store\BaseTest; use Tester\Assert; /** - * Every implementation of ICursorDriver must pass this test. + * Every implementation of ICursor must pass this test. * * This file is using Given-When-Then naming convention. * @link http://martinfowler.com/bliki/GivenWhenThen.html * * @package Grifart\Mappi\Tests\Store\Store\PostgresDriver */ -abstract class CursorInterfaceTest extends BaseTest +abstract class ICursorTest extends BaseTest { - /** @var ICursorDriver */ + /** @var ICursor */ protected $uut; @@ -266,7 +266,7 @@ abstract class CursorInterfaceTest extends BaseTest { $this->uut->moveTo(995); - $result = $this->uut->fetchRange(ICursorDriver::FETCH_REMAINING); + $result = $this->uut->fetchRange(ICursor::FETCH_REMAINING); Assert::count(5, $result); Assert::same(996, current($result[0])); @@ -286,7 +286,7 @@ abstract class CursorInterfaceTest extends BaseTest { $this->uut->moveTo(6); - $result = $this->uut->fetchRange(ICursorDriver::FETCH_FOREGOING); + $result = $this->uut->fetchRange(ICursor::FETCH_FOREGOING); Assert::count(5, $result); Assert::same(5, current($result[0])); diff --git a/tests/Store/PostgresDriver/SemanticCursorIntegration.phpt b/tests/Store/PostgresDriver/SemanticCursorIntegration.phpt index 2c6d0c5..89b1fea 100644 --- a/tests/Store/PostgresDriver/SemanticCursorIntegration.phpt +++ b/tests/Store/PostgresDriver/SemanticCursorIntegration.phpt @@ -5,18 +5,12 @@ namespace Grifart\Mappi\Tests\Store\Store\PostgresDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorDriverFactory; -use Grifart\Mappi\Store\PostgresDriver\CursorException; use Grifart\Mappi\Store\PostgresDriver\CursorFactory; -use Grifart\Mappi\Store\PostgresDriver\ICursorDriver; use Grifart\Mappi\Store\PostgresDriver\SemanticCursor; -use Grifart\Mappi\Tests\Store\BaseTest; use Mockery; -use Tester\Assert; require_once __DIR__ . "/../../bootstrap.php"; -require_once __DIR__ . "/CursorInterfaceTest.php"; +require_once __DIR__ . "/ICursorTest.php"; /** * Behavioral test for SemanticCursor using mocking. @@ -24,7 +18,7 @@ require_once __DIR__ . "/CursorInterfaceTest.php"; * * @package Grifart\Mappi\Tests\Store\Store\PostgresDriver */ -class SemanticCursorIntegrationTest extends CursorInterfaceTest +class SemanticCursorIntegrationTest extends ICursorTest { /** @var SemanticCursor */ @@ -36,7 +30,7 @@ class SemanticCursorIntegrationTest extends CursorInterfaceTest $connection->begin(); $this->uut = new SemanticCursor( - (new CursorDriverFactory($connection)) + (new CursorFactory($connection)) ->create($SQL_thousandRowsAscending, true) ); diff --git a/tests/Store/PostgresDriver/SemanticCursor.phpt b/tests/Store/PostgresDriver/SemanticCursorTest.phpt similarity index 90% rename from tests/Store/PostgresDriver/SemanticCursor.phpt rename to tests/Store/PostgresDriver/SemanticCursorTest.phpt index 5d75532..087ec1e 100644 --- a/tests/Store/PostgresDriver/SemanticCursor.phpt +++ b/tests/Store/PostgresDriver/SemanticCursorTest.phpt @@ -5,18 +5,15 @@ namespace Grifart\Mappi\Tests\Store\Store\PostgresDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorDriverFactory; use Grifart\Mappi\Store\PostgresDriver\CursorException; -use Grifart\Mappi\Store\PostgresDriver\CursorFactory; -use Grifart\Mappi\Store\PostgresDriver\ICursorDriver; +use Grifart\Mappi\Store\PostgresDriver\ICursor; use Grifart\Mappi\Store\PostgresDriver\SemanticCursor; use Grifart\Mappi\Tests\Store\BaseTest; use Mockery; use Tester\Assert; require_once __DIR__ . "/../../bootstrap.php"; -require_once __DIR__ . "/CursorInterfaceTest.php"; +require_once __DIR__ . "/ICursorTest.php"; /** * Behavioral test for SemanticCursor using mocking. @@ -29,15 +26,15 @@ class SemanticCursorTest extends BaseTest /** @var SemanticCursor */ private $uut; - /** @var ICursorDriver|Mockery\Mock */ + /** @var ICursor|Mockery\Mock */ private $mockedCursor; protected function setUp() { parent::setUp(); - /** @var ICursorDriver|Mockery\Mock $cursor */ - $this->mockedCursor = Mockery::mock(ICursorDriver::class); + /** @var ICursor|Mockery\Mock $cursor */ + $this->mockedCursor = Mockery::mock(ICursor::class); $this->uut = new SemanticCursor($this->mockedCursor); } @@ -213,7 +210,7 @@ class SemanticCursorTest extends BaseTest public function test_fetchRemaining() { $this->mockedCursor->shouldReceive("fetchRange") - ->with(ICursorDriver::FETCH_REMAINING)->once() + ->with(ICursor::FETCH_REMAINING)->once() ->andReturn([["next1"],["next2"]]); Assert::equal( @@ -225,7 +222,7 @@ class SemanticCursorTest extends BaseTest public function test_fetchForegoing() { $this->mockedCursor->shouldReceive("fetchRange") - ->with(ICursorDriver::FETCH_FOREGOING)->once() + ->with(ICursor::FETCH_FOREGOING)->once() ->andReturn([["prev1"],["prev2"]]); Assert::equal( diff --git a/tests/Store/PostgresDriver/TrackedCursorTest.phpt b/tests/Store/PostgresDriver/TrackedCursorTest.phpt index 4e0af67..b7183d0 100644 --- a/tests/Store/PostgresDriver/TrackedCursorTest.phpt +++ b/tests/Store/PostgresDriver/TrackedCursorTest.phpt @@ -8,17 +8,17 @@ namespace Grifart\Mappi\Tests\Store\Store\PostgresDriver; -use Grifart\Mappi\Store\PostgresDriver\CursorDriverFactory; +use Grifart\Mappi\Store\PostgresDriver\CursorFactory; use Grifart\Mappi\Store\PostgresDriver\CursorPosition; -use Grifart\Mappi\Store\PostgresDriver\ICursorDriver; +use Grifart\Mappi\Store\PostgresDriver\ICursor; use Grifart\Mappi\Store\PostgresDriver\TrackedCursor; use Grifart\Mappi\Tests\Store\BaseTest; use Tester\Assert; require_once __DIR__ . "/../../bootstrap.php"; -require_once __DIR__ . "/CursorInterfaceTest.php"; +require_once __DIR__ . "/ICursorTest.php"; -class TrackedCursorTest extends CursorInterfaceTest +class TrackedCursorTest extends ICursorTest { /** @link https://en.wikipedia.org/wiki/42_(number)#Hitchhiker.27s_Guide_to_the_Galaxy */ const THE_MAGIC_NUMBER = 42; @@ -31,7 +31,7 @@ class TrackedCursorTest extends CursorInterfaceTest global $connection, $SQL_thousandRowsAscending; $connection->begin(); - $factory = new CursorDriverFactory($connection); + $factory = new CursorFactory($connection); $this->uut = new TrackedCursor( $connection, $factory->create($SQL_thousandRowsAscending, TRUE), -- GitLab