8
8
9
9
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
10
11
+ /**
12
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13
+ */
11
14
class RowTest extends \PHPUnit \Framework \TestCase
12
15
{
13
16
/**
@@ -59,6 +62,8 @@ protected function setUp()
59
62
{
60
63
$ objectManager = new ObjectManager ($ this );
61
64
65
+ $ attributeTable = 'catalog_product_entity_int ' ;
66
+ $ statusId = 22 ;
62
67
$ this ->connection = $ this ->createMock (\Magento \Framework \DB \Adapter \AdapterInterface::class);
63
68
$ this ->resource = $ this ->createMock (\Magento \Framework \App \ResourceConnection::class);
64
69
$ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )
@@ -68,12 +73,41 @@ protected function setUp()
68
73
$ this ->store = $ this ->createMock (\Magento \Store \Model \Store::class);
69
74
$ this ->store ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ('store_id_1 ' ));
70
75
$ this ->storeManager ->expects ($ this ->any ())->method ('getStores ' )->will ($ this ->returnValue ([$ this ->store ]));
71
- $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
72
76
$ this ->flatItemEraser = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Eraser::class);
73
77
$ this ->flatItemWriter = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Indexer::class);
74
78
$ this ->flatTableBuilder = $ this ->createMock (
75
79
\Magento \Catalog \Model \Indexer \Product \Flat \FlatTableBuilder::class
76
80
);
81
+ $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
82
+ $ statusAttributeMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute::class)
83
+ ->disableOriginalConstructor ()
84
+ ->getMock ();
85
+ $ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getAttribute ' )
86
+ ->with ('status ' )
87
+ ->willReturn ($ statusAttributeMock );
88
+ $ backendMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute \Backend \AbstractBackend::class)
89
+ ->disableOriginalConstructor ()
90
+ ->getMock ();
91
+ $ backendMock ->expects ($ this ->any ())->method ('getTable ' )->willReturn ($ attributeTable );
92
+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getBackend ' )->willReturn (
93
+ $ backendMock
94
+ );
95
+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ statusId );
96
+ $ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
97
+ ->disableOriginalConstructor ()
98
+ ->getMock ();
99
+ $ this ->connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ selectMock );
100
+ $ selectMock ->expects ($ this ->any ())->method ('from ' )->with (
101
+ $ attributeTable ,
102
+ ['value ' ]
103
+ )->willReturnSelf ();
104
+ $ selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
105
+ $ pdoMock = $ this ->createMock (\Zend_Db_Statement_Pdo::class);
106
+ $ this ->connection ->expects ($ this ->any ())
107
+ ->method ('query ' )
108
+ ->with ($ selectMock )
109
+ ->will ($ this ->returnValue ($ pdoMock ));
110
+ $ pdoMock ->expects ($ this ->any ())->method ('fetch ' )->will ($ this ->returnValue (['value ' => 1 ]));
77
111
78
112
$ this ->model = $ objectManager ->getObject (
79
113
\Magento \Catalog \Model \Indexer \Product \Flat \Action \Row::class,
0 commit comments