diff --git a/lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php b/lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php index b16b7c87e87ac..2d585fe33aba3 100644 --- a/lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php +++ b/lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php @@ -6,6 +6,11 @@ namespace Magento\Framework\Mview\Test\Unit\View; +/** + * Test Coverage for Changelog View. + * + * @see \Magento\Framework\Mview\View\Changelog + */ class ChangelogTest extends \PHPUnit\Framework\TestCase { /** @@ -45,7 +50,7 @@ public function testInstanceOf() } /** - * @expectedException \Exception + * @expectedException \Magento\Framework\DB\Adapter\ConnectionException * @expectedExceptionMessage The write connection to the database isn't available. Please try again later. */ public function testCheckConnectionException() @@ -74,7 +79,7 @@ public function testGetViewId() } /** - * @expectedException \Exception + * @expectedException \DomainException * @expectedExceptionMessage View's identifier is not set */ public function testGetNameWithException() @@ -101,6 +106,10 @@ public function testGetVersion() $this->assertEquals(10, $this->model->getVersion()); } + /** + * @expectedException \Magento\Framework\Exception\RuntimeException + * @expectedExceptionMessage Table status for viewIdtest_cl is incorrect. Can`t fetch version id. + */ public function testGetVersionWithExceptionNoAutoincrement() { $changelogTableName = 'viewIdtest_cl'; @@ -111,8 +120,6 @@ public function testGetVersionWithExceptionNoAutoincrement() ->method('fetchRow') ->will($this->returnValue([])); - $this->expectException('Exception'); - $this->expectExceptionMessage("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id."); $this->model->setViewId('viewIdtest'); $this->model->getVersion(); } @@ -215,10 +222,10 @@ public function testGetList() $this->connectionMock->expects($this->once()) ->method('fetchCol') ->with($selectMock) - ->will($this->returnValue(['some_data'])); + ->will($this->returnValue([1])); $this->model->setViewId('viewIdtest'); - $this->assertEquals(['some_data'], $this->model->getList(1, 2)); + $this->assertEquals([1], $this->model->getList(1, 2)); } public function testGetListWithException() diff --git a/lib/internal/Magento/Framework/Mview/View.php b/lib/internal/Magento/Framework/Mview/View.php index 1b32238813f86..20736eb21963a 100644 --- a/lib/internal/Magento/Framework/Mview/View.php +++ b/lib/internal/Magento/Framework/Mview/View.php @@ -285,7 +285,7 @@ public function update() for ($vsFrom = $lastVersionId; $vsFrom < $currentVersionId; $vsFrom += $versionBatchSize) { // Don't go past the current version for atomicy. $versionTo = min($currentVersionId, $vsFrom + $versionBatchSize); - $ids = array_map('intval', $this->getChangelog()->getList($vsFrom, $versionTo)); + $ids = $this->getChangelog()->getList($vsFrom, $versionTo); // We run the actual indexer in batches. // Chunked AFTER loading to avoid duplicates in separate chunks. diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 4fb06ce3f06fd..d51f5b13f01a2 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -6,8 +6,13 @@ namespace Magento\Framework\Mview\View; +use Magento\Framework\DB\Adapter\ConnectionException; +use Magento\Framework\Exception\RuntimeException; use Magento\Framework\Phrase; +/** + * Class Changelog for manipulations with the mview_state table. + */ class Changelog implements ChangelogInterface { /** @@ -41,6 +46,7 @@ class Changelog implements ChangelogInterface /** * @param \Magento\Framework\App\ResourceConnection $resource + * @throws ConnectionException */ public function __construct(\Magento\Framework\App\ResourceConnection $resource) { @@ -53,12 +59,14 @@ public function __construct(\Magento\Framework\App\ResourceConnection $resource) * Check DB connection * * @return void - * @throws \Exception + * @throws ConnectionException */ protected function checkConnection() { if (!$this->connection) { - throw new \Exception("The write connection to the database isn't available. Please try again later."); + throw new ConnectionException( + new Phrase("The write connection to the database isn't available. Please try again later.") + ); } } @@ -154,14 +162,15 @@ public function getList($fromVersionId, $toVersionId) (int)$toVersionId ); - return $this->connection->fetchCol($select); + return array_map('intval', $this->connection->fetchCol($select)); } /** * Get maximum version_id from changelog + * * @return int * @throws ChangelogTableNotExistsException - * @throws \Exception + * @throws RuntimeException */ public function getVersion() { @@ -173,7 +182,9 @@ public function getVersion() if (isset($row['Auto_increment'])) { return (int)$row['Auto_increment'] - 1; } else { - throw new \Exception("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id."); + throw new RuntimeException( + new Phrase("Table status for %1 is incorrect. Can`t fetch version id.", [$changelogTableName]) + ); } } @@ -182,13 +193,15 @@ public function getVersion() * * Build a changelog name by concatenating view identifier and changelog name suffix. * - * @throws \Exception + * @throws \DomainException * @return string */ public function getName() { if (strlen($this->viewId) == 0) { - throw new \Exception("View's identifier is not set"); + throw new \DomainException( + new Phrase("View's identifier is not set") + ); } return $this->viewId . '_' . self::NAME_SUFFIX; } @@ -216,6 +229,8 @@ public function setViewId($viewId) } /** + * Get view's identifier + * * @return string */ public function getViewId()