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 7ecfa98ace30e6fcc23c31c63330673be04d451e..0685104f21dece412842a86db8753a1983d18a53 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 8164b1befb8a24358d0bbac951e258e5918bc1e3..b317d2eaf2c728e5eb8979804a5e14b2f112445b 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 697c27469b73338e5296a52323fb28c34ee70738..59b0ab49d13f659b6c71fca4f6707320c9811a61 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 5f8a6cef3ed6d145491e6d25a5fac74786c58857..0000000000000000000000000000000000000000 --- 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 457f9c6cdf57807bcee512c8ba7f3b22cda04d74..5d3ce73037435a2517141c982425fa5affd6b871 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 fc4aaf66e2cc57c980c74ea3b13686cbcdc9e6d2..d4b820aed15d4d76a6dfcb7a8e9d9823fcf87067 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 1a32aae3a3e98f0a0dc40314b1696eaf9ff4ff73..0000000000000000000000000000000000000000 --- 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 076f0c10585863f2110b7bf73b4e58f990d14a9f..bb0884687ae31c082c0ac608a6ac6e94dc934628 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 76ff3145dfef1559a3f4249ead4e42173918749b..a022e020582f285a602ecf0c7adfed3dd700782b 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 2c6d0c5f2dc55bbda24f5f5a31d3344f540121cb..89b1fea074503883da19173e603104a20b79e5cc 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 5d7553289c0aa5157a259ed0b97a378a4555945d..087ec1e9838a32f009c5e07be41545c325ac8299 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 4e0af673a3387ecf855a5a0247c88610e3ad651d..b7183d02d64ed2b905b361469535647f913201c9 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),