12
12
13
13
class SubscriptionTest extends \PHPUnit_Framework_TestCase
14
14
{
15
- /**
16
- * @var \Magento\Framework\Mview\View\Subscription
17
- */
18
- protected $ model ;
19
-
20
15
/**
21
16
* Mysql PDO DB adapter mock
22
17
*
23
18
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql
24
19
*/
25
20
protected $ connectionMock ;
26
21
27
- /**
28
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Resource
29
- */
22
+ /** @var \Magento\Framework\Mview\View\Subscription */
23
+ protected $ model ;
24
+
25
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Resource */
30
26
protected $ resourceMock ;
31
27
32
- /**
33
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Ddl\TriggerFactory
34
- */
28
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Ddl\TriggerFactory */
35
29
protected $ triggerFactoryMock ;
36
30
37
- /**
38
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mview\View\CollectionInterface
39
- */
31
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mview\View\CollectionInterface */
40
32
protected $ viewCollectionMock ;
41
33
42
- /**
43
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mview\ViewInterface
44
- */
34
+ /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mview\ViewInterface */
45
35
protected $ viewMock ;
46
36
37
+ /** @var string */
38
+ private $ tableName ;
39
+
47
40
protected function setUp ()
48
41
{
49
42
$ this ->connectionMock = $ this ->getMock ('Magento\Framework\DB\Adapter\Pdo\Mysql ' , [], [], '' , false );
43
+ $ this ->resourceMock = $ this ->getMock ('Magento\Framework\App\Resource ' , [], [], '' , false , false );
44
+
45
+ $ this ->connectionMock ->expects ($ this ->any ())
46
+ ->method ('quoteIdentifier ' )
47
+ ->will ($ this ->returnArgument (0 ));
48
+
49
+ $ this ->resourceMock ->expects ($ this ->atLeastOnce ())
50
+ ->method ('getConnection ' )
51
+ ->willReturn ($ this ->connectionMock );
50
52
51
- $ this ->resourceMock = $ this ->getMock (
52
- 'Magento\Framework\App\Resource ' , ['getConnection ' , 'getTableName ' ], [], '' , false , false
53
- );
54
- $ this ->mockGetConnection ($ this ->connectionMock );
55
53
$ this ->triggerFactoryMock = $ this ->getMock (
56
54
'Magento\Framework\DB\Ddl\TriggerFactory ' , [], [], '' , false , false
57
55
);
@@ -62,16 +60,16 @@ protected function setUp()
62
60
'Magento\Framework\Mview\ViewInterface ' , [], '' , false , false , true , []
63
61
);
64
62
65
- $ this ->connectionMock ->expects ($ this ->any ())
66
- ->method ('quoteIdentifier ' )
67
- ->will ($ this ->returnArgument ( 0 ) );
63
+ $ this ->resourceMock ->expects ($ this ->any ())
64
+ ->method ('getTableName ' )
65
+ ->willReturn ($ this ->tableName );
68
66
69
67
$ this ->model = new Subscription (
70
68
$ this ->resourceMock ,
71
69
$ this ->triggerFactoryMock ,
72
70
$ this ->viewCollectionMock ,
73
71
$ this ->viewMock ,
74
- ' tableName ' ,
72
+ $ this -> tableName ,
75
73
'columnName '
76
74
);
77
75
}
@@ -83,7 +81,7 @@ public function testGetView()
83
81
84
82
public function testGetTableName ()
85
83
{
86
- $ this ->assertEquals (' tableName ' , $ this ->model ->getTableName ());
84
+ $ this ->assertEquals ($ this -> tableName , $ this ->model ->getTableName ());
87
85
}
88
86
89
87
public function testGetColumnName ()
@@ -93,13 +91,14 @@ public function testGetColumnName()
93
91
94
92
public function testCreate ()
95
93
{
96
- $ this ->mockGetTableName ();
97
- $ shortTriggerName = 'short_trigger_name ' ;
98
- $ this ->connectionMock ->expects ($ this ->atLeastOnce ())->method ('getTriggerName ' )->willReturn ($ shortTriggerName );
99
- $ triggerMock = $ this ->getMock ('Magento\Framework\DB\Ddl\Trigger ' , [], [], '' , false , false );
94
+ $ triggerName = 'trigger_name ' ;
95
+ $ this ->resourceMock ->expects ($ this ->atLeastOnce ())->method ('getTriggerName ' )->willReturn ($ triggerName );
96
+ $ triggerMock = $ this ->getMockBuilder ('Magento\Framework\DB\Ddl\Trigger ' )
97
+ ->disableOriginalConstructor ()
98
+ ->getMock ();
100
99
$ triggerMock ->expects ($ this ->exactly (3 ))
101
100
->method ('setName ' )
102
- ->with ($ shortTriggerName )
101
+ ->with ($ triggerName )
103
102
->will ($ this ->returnSelf ());
104
103
$ triggerMock ->expects ($ this ->exactly (3 ))
105
104
->method ('getName ' )
@@ -113,7 +112,7 @@ public function testCreate()
113
112
->will ($ this ->returnSelf ());
114
113
$ triggerMock ->expects ($ this ->exactly (3 ))
115
114
->method ('setTable ' )
116
- ->with (' tableName ' )
115
+ ->with ($ this -> tableName )
117
116
->will ($ this ->returnSelf ());
118
117
$ triggerMock ->expects ($ this ->exactly (6 ))
119
118
->method ('addStatement ' )
@@ -155,7 +154,7 @@ public function testCreate()
155
154
->will ($ this ->returnValue ('other_id ' ));
156
155
$ otherViewMock ->expects ($ this ->exactly (1 ))
157
156
->method ('getSubscriptions ' )
158
- ->will ($ this ->returnValue ([['name ' => ' tableName ' ], ['name ' => 'otherTableName ' ]]));
157
+ ->will ($ this ->returnValue ([['name ' => $ this -> tableName ], ['name ' => 'otherTableName ' ]]));
159
158
$ otherViewMock ->expects ($ this ->exactly (3 ))
160
159
->method ('getChangelog ' )
161
160
->will ($ this ->returnValue ($ otherChangelogMock ));
@@ -184,8 +183,6 @@ public function testCreate()
184
183
185
184
public function testRemove ()
186
185
{
187
- $ this ->mockGetTableName ();
188
-
189
186
$ triggerMock = $ this ->getMock ('Magento\Framework\DB\Ddl\Trigger ' , [], [], '' , false , false );
190
187
$ triggerMock ->expects ($ this ->exactly (3 ))
191
188
->method ('setName ' )
@@ -202,7 +199,7 @@ public function testRemove()
202
199
->will ($ this ->returnSelf ());
203
200
$ triggerMock ->expects ($ this ->exactly (3 ))
204
201
->method ('setTable ' )
205
- ->with (' tableName ' )
202
+ ->with ($ this -> tableName )
206
203
->will ($ this ->returnSelf ());
207
204
$ triggerMock ->expects ($ this ->exactly (3 ))
208
205
->method ('addStatement ' )
@@ -230,7 +227,7 @@ public function testRemove()
230
227
->will ($ this ->returnValue ('other_id ' ));
231
228
$ otherViewMock ->expects ($ this ->exactly (1 ))
232
229
->method ('getSubscriptions ' )
233
- ->will ($ this ->returnValue ([['name ' => ' tableName ' ], ['name ' => 'otherTableName ' ]]));
230
+ ->will ($ this ->returnValue ([['name ' => $ this -> tableName ], ['name ' => 'otherTableName ' ]]));
234
231
$ otherViewMock ->expects ($ this ->exactly (3 ))
235
232
->method ('getChangelog ' )
236
233
->will ($ this ->returnValue ($ otherChangelogMock ));
@@ -261,25 +258,4 @@ public function testRemove()
261
258
262
259
$ this ->model ->remove ();
263
260
}
264
-
265
- /**
266
- * @param $connection
267
- */
268
- protected function mockGetConnection ($ connection )
269
- {
270
- $ this ->resourceMock ->expects ($ this ->atLeastOnce ())
271
- ->method ('getConnection ' )
272
- ->will ($ this ->returnValue ($ connection ));
273
- }
274
-
275
- protected function mockGetTableName ()
276
- {
277
- $ this ->resourceMock ->expects ($ this ->any ())
278
- ->method ('getTableName ' )
279
- ->will ($ this ->returnArgument (0 ));
280
- }
281
-
282
- public function testGetTriggerName ()
283
- {
284
- }
285
261
}
0 commit comments