1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2015 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
15
15
use Magento \Framework \Mview \View \AdditionalColumnsProcessor \ProcessorFactory ;
16
16
use Magento \Framework \Mview \View \Changelog ;
17
17
use Magento \Framework \Mview \View \ChangelogInterface ;
18
+ use Magento \Framework \Setup \Declaration \Schema \Dto \Factories \Table as DtoFactoriesTable ;
18
19
use PHPUnit \Framework \MockObject \MockObject ;
19
20
use PHPUnit \Framework \TestCase ;
20
21
@@ -28,33 +29,44 @@ class ChangelogTest extends TestCase
28
29
/**
29
30
* @var Changelog
30
31
*/
31
- protected $ model ;
32
+ private $ model ;
32
33
33
34
/**
34
35
* Mysql PDO DB adapter mock
35
36
*
36
- * @var MockObject|\Magento\Framework\DB\Adapter\Pdo\ Mysql
37
+ * @var MockObject|Mysql
37
38
*/
38
- protected $ connectionMock ;
39
+ private $ connectionMock ;
39
40
40
41
/**
41
42
* @var MockObject|ResourceConnection
42
43
*/
43
- protected $ resourceMock ;
44
+ private $ resourceMock ;
44
45
45
46
/**
46
47
* @var ProcessorFactory|MockObject
47
48
*/
48
- protected $ processorFactory ;
49
+ private $ processorFactory ;
50
+
51
+ /**
52
+ * @var DtoFactoriesTable|MockObject
53
+ */
54
+ private $ dtoFactoriesTableMock ;
49
55
50
56
protected function setUp (): void
51
57
{
52
58
$ this ->connectionMock = $ this ->createMock (Mysql::class);
53
59
$ this ->resourceMock = $ this ->createMock (ResourceConnection::class);
54
60
$ this ->mockGetConnection ($ this ->connectionMock );
55
61
$ this ->processorFactory = $ this ->createMock (ProcessorFactory::class);
62
+ $ this ->dtoFactoriesTableMock = $ this ->createMock (DtoFactoriesTable::class);
56
63
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
+ );
58
70
}
59
71
60
72
/**
@@ -73,11 +85,7 @@ private function getMviewConfigMock()
73
85
74
86
public function testInstanceOf ()
75
87
{
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 );
81
89
}
82
90
83
91
public function testCheckConnectionException ()
@@ -308,6 +316,21 @@ public function testGetListWithException()
308
316
$ this ->model ->getList (random_int (1 , 200 ), random_int (201 , 400 ));
309
317
}
310
318
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
+
311
334
public function testClearWithException ()
312
335
{
313
336
$ changelogTableName = 'viewIdtest_cl ' ;
0 commit comments