11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2015 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
1515use Magento \Framework \Mview \View \AdditionalColumnsProcessor \ProcessorFactory ;
1616use Magento \Framework \Mview \View \Changelog ;
1717use Magento \Framework \Mview \View \ChangelogInterface ;
18+ use Magento \Framework \Setup \Declaration \Schema \Dto \Factories \Table as DtoFactoriesTable ;
1819use PHPUnit \Framework \MockObject \MockObject ;
1920use PHPUnit \Framework \TestCase ;
2021
@@ -28,33 +29,44 @@ class ChangelogTest extends TestCase
2829 /**
2930 * @var Changelog
3031 */
31- protected $ model ;
32+ private $ model ;
3233
3334 /**
3435 * Mysql PDO DB adapter mock
3536 *
36- * @var MockObject|\Magento\Framework\DB\Adapter\Pdo\ Mysql
37+ * @var MockObject|Mysql
3738 */
38- protected $ connectionMock ;
39+ private $ connectionMock ;
3940
4041 /**
4142 * @var MockObject|ResourceConnection
4243 */
43- protected $ resourceMock ;
44+ private $ resourceMock ;
4445
4546 /**
4647 * @var ProcessorFactory|MockObject
4748 */
48- protected $ processorFactory ;
49+ private $ processorFactory ;
50+
51+ /**
52+ * @var DtoFactoriesTable|MockObject
53+ */
54+ private $ dtoFactoriesTableMock ;
4955
5056 protected function setUp (): void
5157 {
5258 $ this ->connectionMock = $ this ->createMock (Mysql::class);
5359 $ this ->resourceMock = $ this ->createMock (ResourceConnection::class);
5460 $ this ->mockGetConnection ($ this ->connectionMock );
5561 $ this ->processorFactory = $ this ->createMock (ProcessorFactory::class);
62+ $ this ->dtoFactoriesTableMock = $ this ->createMock (DtoFactoriesTable::class);
5663
57- $ this ->model = new Changelog ($ this ->resourceMock , $ this ->getMviewConfigMock (), $ this ->processorFactory );
64+ $ this ->model = new Changelog (
65+ $ this ->resourceMock ,
66+ $ this ->getMviewConfigMock (),
67+ $ this ->processorFactory ,
68+ $ this ->dtoFactoriesTableMock ,
69+ );
5870 }
5971
6072 /**
@@ -73,11 +85,7 @@ private function getMviewConfigMock()
7385
7486 public function testInstanceOf ()
7587 {
76- $ resourceMock =
77- $ this ->createMock (ResourceConnection::class);
78- $ resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn (true );
79- $ model = new Changelog ($ resourceMock , $ this ->getMviewConfigMock (), $ this ->processorFactory );
80- $ this ->assertInstanceOf (ChangelogInterface::class, $ model );
88+ $ this ->assertInstanceOf (ChangelogInterface::class, $ this ->model );
8189 }
8290
8391 public function testCheckConnectionException ()
@@ -308,6 +316,21 @@ public function testGetListWithException()
308316 $ this ->model ->getList (random_int (1 , 200 ), random_int (201 , 400 ));
309317 }
310318
319+ public function testClear ()
320+ {
321+ $ versionId = 100 ;
322+ $ tableName = 'viewIdtest_cl ' ;
323+ $ this ->resourceMock ->expects (self ::once ())->method ('getTableName ' )->willReturn ($ tableName );
324+ $ this ->connectionMock ->expects (self ::once ())->method ('isTableExists ' )->with ($ tableName )->willReturn (true );
325+
326+ $ stmtMock = $ this ->createMock (\Zend_Db_Statement_Interface::class);
327+ $ stmtMock ->expects (self ::exactly (3 ))->method ('rowCount ' )->willReturnOnConsecutiveCalls (10000 , 5000 , 0 );
328+ $ this ->connectionMock ->expects (self ::exactly (3 ))->method ('query ' )->willReturn ($ stmtMock );
329+
330+ $ this ->model ->setViewId ('viewIdtest ' );
331+ $ this ->model ->clear ($ versionId );
332+ }
333+
311334 public function testClearWithException ()
312335 {
313336 $ changelogTableName = 'viewIdtest_cl ' ;
0 commit comments