@@ -70,6 +70,17 @@ protected function setUp()
70
70
->getMock ();
71
71
72
72
$ this ->dataProviderMock = $ this ->getMockForAbstractClass (DataProviderInterface::class);
73
+
74
+ $ this ->contextMock ->expects ($ this ->any ())
75
+ ->method ('getNamespace ' )
76
+ ->willReturn (DateRange::NAME );
77
+ $ this ->contextMock ->expects ($ this ->any ())
78
+ ->method ('addComponentDefinition ' )
79
+ ->with (DateRange::NAME , ['extends ' => DateRange::NAME ]);
80
+
81
+ $ this ->contextMock ->expects ($ this ->any ())
82
+ ->method ('getDataProvider ' )
83
+ ->willReturn ($ this ->dataProviderMock );
73
84
}
74
85
75
86
/**
@@ -84,29 +95,15 @@ protected function setUp()
84
95
*/
85
96
public function testPrepare ($ name , $ filterData , $ expectedCondition )
86
97
{
87
- /** @var FormDate PHPUnit_Framework_MockObject_MockObject|$uiComponent */
88
- $ uiComponent = $ this ->getMockBuilder (FormDate::class)
89
- ->disableOriginalConstructor ()
90
- ->getMock ();
91
-
92
- $ uiComponent ->expects ($ this ->any ())
93
- ->method ('getContext ' )
94
- ->willReturn ($ this ->contextMock );
95
-
96
- $ this ->contextMock ->expects ($ this ->any ())
97
- ->method ('getNamespace ' )
98
- ->willReturn (DateRange::NAME );
99
- $ this ->contextMock ->expects ($ this ->any ())
100
- ->method ('addComponentDefinition ' )
101
- ->with (DateRange::NAME , ['extends ' => DateRange::NAME ]);
102
-
103
98
$ this ->contextMock ->expects ($ this ->any ())
104
99
->method ('getFiltersParams ' )
105
100
->willReturn ($ filterData );
106
101
107
- $ this ->contextMock ->expects ($ this ->any ())
108
- ->method ('getDataProvider ' )
109
- ->willReturn ($ this ->dataProviderMock );
102
+ $ uiComponent = $ this ->getMockBuilder (FormDate::class)->disableOriginalConstructor ()->getMock ();
103
+
104
+ $ uiComponent ->expects ($ this ->any ())
105
+ ->method ('getContext ' )
106
+ ->willReturn ($ this ->contextMock );
110
107
111
108
if ($ expectedCondition !== null ) {
112
109
if (is_string ($ filterData [$ name ])) {
@@ -173,20 +170,8 @@ public function testPrepare($name, $filterData, $expectedCondition)
173
170
new \DateTime ($ filterData [$ name ]['to ' ] . ' 23:59:00 ' , new \DateTimeZone ('UTC ' ))
174
171
],
175
172
]);
176
- $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
177
- ->method ('setConditionType ' )
178
- ->willReturnSelf ();
179
- $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
180
- ->method ('setField ' )
181
- ->willReturnSelf ();
182
- $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
183
- ->method ('setValue ' )
184
- ->willReturnSelf ();
185
173
186
- $ filterMock = $ this ->getMock (Filter::class);
187
- $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
188
- ->method ('create ' )
189
- ->willReturn ($ filterMock );
174
+ $ filterMock = $ this ->getFilterMockWithoutExpectedCondition ();
190
175
$ this ->dataProviderMock ->expects (static ::exactly (2 ))
191
176
->method ('addFilter ' )
192
177
->with ($ filterMock );
@@ -241,6 +226,31 @@ private function getFilterMock($name, $expectedType, $expectedDate, &$i)
241
226
return $ filterMock ;
242
227
}
243
228
229
+ /**
230
+ * Gets Filter mock without expected condition
231
+ *
232
+ * @return Filter|\PHPUnit_Framework_MockObject_MockObject
233
+ */
234
+ private function getFilterMockWithoutExpectedCondition ()
235
+ {
236
+ $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
237
+ ->method ('setConditionType ' )
238
+ ->willReturnSelf ();
239
+ $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
240
+ ->method ('setField ' )
241
+ ->willReturnSelf ();
242
+ $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
243
+ ->method ('setValue ' )
244
+ ->willReturnSelf ();
245
+
246
+ $ filterMock = $ this ->getMock (Filter::class);
247
+ $ this ->filterBuilderMock ->expects (static ::exactly (2 ))
248
+ ->method ('create ' )
249
+ ->willReturn ($ filterMock );
250
+
251
+ return $ filterMock ;
252
+ }
253
+
244
254
/**
245
255
* @return array
246
256
*/
0 commit comments