@@ -40,13 +40,13 @@ class SubscriptionTest extends \PHPUnit_Framework_TestCase
40
40
protected function setUp ()
41
41
{
42
42
$ this ->connectionMock = $ this ->getMock (\Magento \Framework \DB \Adapter \Pdo \Mysql::class, [], [], '' , false );
43
- $ this ->resourceMock = $ this ->getMock (
44
- \Magento \Framework \App \ResourceConnection::class,
45
- [],
46
- [],
47
- '' ,
48
- false ,
49
- false
43
+ $ this ->resourceMock = $ this ->getMock (
44
+ \Magento \Framework \App \ResourceConnection::class,
45
+ [],
46
+ [],
47
+ '' ,
48
+ false ,
49
+ false
50
50
);
51
51
52
52
$ this ->connectionMock ->expects ($ this ->any ())
@@ -57,19 +57,19 @@ protected function setUp()
57
57
->method ('getConnection ' )
58
58
->willReturn ($ this ->connectionMock );
59
59
60
- $ this ->triggerFactoryMock = $ this ->getMock (
60
+ $ this ->triggerFactoryMock = $ this ->getMock (
61
61
\Magento \Framework \DB \Ddl \TriggerFactory::class, [], [], '' , false , false
62
62
);
63
- $ this ->viewCollectionMock = $ this ->getMockForAbstractClass (
63
+ $ this ->viewCollectionMock = $ this ->getMockForAbstractClass (
64
64
\Magento \Framework \Mview \View \CollectionInterface::class, [], '' , false , false , true , []
65
65
);
66
- $ this ->viewMock = $ this ->getMockForAbstractClass (
66
+ $ this ->viewMock = $ this ->getMockForAbstractClass (
67
67
\Magento \Framework \Mview \ViewInterface::class, [], '' , false , false , true , []
68
68
);
69
69
70
70
$ this ->resourceMock ->expects ($ this ->any ())
71
71
->method ('getTableName ' )
72
- ->willReturn ($ this ->tableName );
72
+ ->will ($ this ->returnArgument ( 0 ) );
73
73
74
74
$ this ->model = new Subscription (
75
75
$ this ->resourceMock ,
@@ -96,11 +96,15 @@ public function testGetColumnName()
96
96
$ this ->assertEquals ('columnName ' , $ this ->model ->getColumnName ());
97
97
}
98
98
99
+ /**
100
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
101
+ */
99
102
public function testCreate ()
100
103
{
101
104
$ triggerName = 'trigger_name ' ;
102
105
$ this ->resourceMock ->expects ($ this ->atLeastOnce ())->method ('getTriggerName ' )->willReturn ($ triggerName );
103
106
$ triggerMock = $ this ->getMockBuilder (\Magento \Framework \DB \Ddl \Trigger::class)
107
+ ->setMethods (['setName ' , 'getName ' , 'setTime ' , 'setEvent ' , 'setTable ' , 'addStatement ' ])
104
108
->disableOriginalConstructor ()
105
109
->getMock ();
106
110
$ triggerMock ->expects ($ this ->exactly (3 ))
@@ -121,11 +125,38 @@ public function testCreate()
121
125
->method ('setTable ' )
122
126
->with ($ this ->tableName )
123
127
->will ($ this ->returnSelf ());
124
- $ triggerMock ->expects ($ this ->exactly (6 ))
128
+
129
+ $ triggerMock ->expects ($ this ->at (4 ))
130
+ ->method ('addStatement ' )
131
+ ->with ("INSERT IGNORE INTO test_view_cl (entity_id) VALUES (NEW.columnName); " )
132
+ ->will ($ this ->returnSelf ());
133
+
134
+ $ triggerMock ->expects ($ this ->at (5 ))
135
+ ->method ('addStatement ' )
136
+ ->with ("INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (NEW.columnName); " )
137
+ ->will ($ this ->returnSelf ());
138
+
139
+ $ triggerMock ->expects ($ this ->at (11 ))
140
+ ->method ('addStatement ' )
141
+ ->with ("INSERT IGNORE INTO test_view_cl (entity_id) VALUES (NEW.columnName); " )
142
+ ->will ($ this ->returnSelf ());
143
+
144
+ $ triggerMock ->expects ($ this ->at (12 ))
145
+ ->method ('addStatement ' )
146
+ ->with ("INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (NEW.columnName); " )
147
+ ->will ($ this ->returnSelf ());
148
+
149
+ $ triggerMock ->expects ($ this ->at (18 ))
150
+ ->method ('addStatement ' )
151
+ ->with ("INSERT IGNORE INTO test_view_cl (entity_id) VALUES (OLD.columnName); " )
152
+ ->will ($ this ->returnSelf ());
153
+
154
+ $ triggerMock ->expects ($ this ->at (19 ))
125
155
->method ('addStatement ' )
156
+ ->with ("INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (OLD.columnName); " )
126
157
->will ($ this ->returnSelf ());
127
158
128
- $ changelogMock = $ this ->getMockForAbstractClass (
159
+ $ changelogMock = $ this ->getMockForAbstractClass (
129
160
\Magento \Framework \Mview \View \ChangelogInterface::class, [], '' , false , false , true , []
130
161
);
131
162
$ changelogMock ->expects ($ this ->exactly (3 ))
@@ -143,7 +174,7 @@ public function testCreate()
143
174
->method ('create ' )
144
175
->will ($ this ->returnValue ($ triggerMock ));
145
176
146
- $ otherChangelogMock = $ this ->getMockForAbstractClass (
177
+ $ otherChangelogMock = $ this ->getMockForAbstractClass (
147
178
\Magento \Framework \Mview \View \ChangelogInterface::class, [], '' , false , false , true , []
148
179
);
149
180
$ otherChangelogMock ->expects ($ this ->exactly (3 ))
@@ -153,7 +184,7 @@ public function testCreate()
153
184
->method ('getColumnName ' )
154
185
->will ($ this ->returnValue ('entity_id ' ));
155
186
156
- $ otherViewMock = $ this ->getMockForAbstractClass (
187
+ $ otherViewMock = $ this ->getMockForAbstractClass (
157
188
\Magento \Framework \Mview \ViewInterface::class, [], '' , false , false , true , []
158
189
);
159
190
$ otherViewMock ->expects ($ this ->exactly (1 ))
@@ -216,7 +247,7 @@ public function testRemove()
216
247
->method ('create ' )
217
248
->will ($ this ->returnValue ($ triggerMock ));
218
249
219
- $ otherChangelogMock = $ this ->getMockForAbstractClass (
250
+ $ otherChangelogMock = $ this ->getMockForAbstractClass (
220
251
\Magento \Framework \Mview \View \ChangelogInterface::class, [], '' , false , false , true , []
221
252
);
222
253
$ otherChangelogMock ->expects ($ this ->exactly (3 ))
@@ -226,7 +257,7 @@ public function testRemove()
226
257
->method ('getColumnName ' )
227
258
->will ($ this ->returnValue ('entity_id ' ));
228
259
229
- $ otherViewMock = $ this ->getMockForAbstractClass (
260
+ $ otherViewMock = $ this ->getMockForAbstractClass (
230
261
\Magento \Framework \Mview \ViewInterface::class, [], '' , false , false , true , []
231
262
);
232
263
$ otherViewMock ->expects ($ this ->exactly (1 ))
0 commit comments