2020use Magento \Framework \Exception \LocalizedException ;
2121use Magento \Framework \Message \Manager ;
2222use Magento \Framework \Phrase ;
23+ use Magento \Framework \TestFramework \Unit \Helper \MockCreationTrait ;
2324use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
2425use Magento \Framework \Url ;
2526use Magento \Framework \UrlFactory ;
2627use Magento \Framework \View \Model \Layout \Merge ;
2728use Magento \Framework \View \Result \Layout ;
2829use Magento \Framework \View \Result \Page ;
2930use Magento \Framework \Webapi \Response ;
30- use Magento \Framework \Test \Unit \Helper \LayoutTestHelper ;
31- use Magento \CatalogSearch \Test \Unit \Helper \RequestTestHelper ;
3231use PHPUnit \Framework \TestCase ;
3332
3433/**
3534 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3635 */
3736class ResultTest extends TestCase
3837{
38+ use MockCreationTrait;
3939 /**
4040 * Test result action filters set before load layout scenario
4141 *
@@ -52,10 +52,10 @@ public function testResultActionFiltersSetBeforeLoadLayout()
5252 );
5353 $ update = $ this ->createPartialMock (Merge::class, ['getHandles ' ]);
5454 $ update ->expects ($ this ->once ())->method ('getHandles ' )->willReturn ([]);
55- $ layout = $ this ->getMockBuilder (LayoutTestHelper::class)
56- -> onlyMethods ([ ' getUpdate ' ])
57- -> disableOriginalConstructor ()
58- -> getMock ( );
55+ $ layout = $ this ->createPartialMockWithReflection (
56+ Layout::class,
57+ [ ' getUpdate ' ]
58+ );
5959 $ layout ->expects ($ this ->once ())->method ('getUpdate ' )->willReturn ($ update );
6060 $ view ->expects ($ this ->once ())->method ('getLayout ' )->willReturn ($ layout );
6161 $ page = $ this ->createPartialMock (Page::class, ['initLayout ' ]);
@@ -66,10 +66,10 @@ function () use (&$filters, $expectedQuery) {
6666 }
6767 );
6868
69- $ request = $ this ->getMockBuilder (RequestTestHelper::class)
70- -> onlyMethods ([ ' getQueryValue ' ])
71- -> disableOriginalConstructor ()
72- -> getMock ( );
69+ $ request = $ this ->createPartialMockWithReflection (
70+ Request::class,
71+ [ ' getQueryValue ' ]
72+ );
7373 $ request ->expects ($ this ->once ())->method ('getQueryValue ' )->willReturn ($ expectedQuery );
7474
7575 $ catalogSearchAdvanced = $ this ->createPartialMock (
@@ -107,12 +107,13 @@ public function testUrlSetOnException()
107107 $ redirectResultMock ->expects ($ this ->once ())
108108 ->method ('setUrl ' );
109109
110- $ redirectFactoryMock = $ this ->getMockBuilder (RedirectFactory::class)
111- -> onlyMethods ([ ' create ' ])
112- -> disableOriginalConstructor ()
113- -> getMock ( );
110+ $ redirectFactoryMock = $ this ->createPartialMock (
111+ RedirectFactory::class,
112+ [ ' create ' ]
113+ );
114114
115- $ redirectFactoryMock ->method ('create ' )->willReturn ($ redirectResultMock );
115+ $ redirectFactoryMock ->method ('create ' )
116+ ->willReturn ($ redirectResultMock );
116117
117118 $ catalogSearchAdvanced = $ this ->createPartialMock (
118119 Advanced::class,
@@ -133,19 +134,25 @@ public function testUrlSetOnException()
133134 $ requestMock ->method ('getQueryValue ' )->willReturn (['key ' => 'value ' ]);
134135
135136 $ redirectMock = $ this ->createMock (RedirectInterface::class);
136- $ redirectMock ->expects ( $ this -> any ())-> method ('error ' )->with ('urlstring ' );
137+ $ redirectMock ->method ('error ' )->with ('urlstring ' );
137138
138139 $ messageManagerMock = $ this ->createMock (Manager::class);
139140
140141 $ eventManagerMock = $ this ->createMock (ManagerInterface::class);
141142
142143 $ contextMock = $ this ->createMock (Context::class);
143- $ contextMock ->method ('getRequest ' )->willReturn ($ requestMock );
144- $ contextMock ->method ('getResponse ' )->willReturn ($ responseMock );
145- $ contextMock ->method ('getRedirect ' )->willReturn ($ redirectMock );
146- $ contextMock ->method ('getMessageManager ' )->willReturn ($ messageManagerMock );
147- $ contextMock ->method ('getEventManager ' )->willReturn ($ eventManagerMock );
148- $ contextMock ->method ('getResultRedirectFactory ' )->willReturn ($ redirectFactoryMock );
144+ $ contextMock ->method ('getRequest ' )
145+ ->willReturn ($ requestMock );
146+ $ contextMock ->method ('getResponse ' )
147+ ->willReturn ($ responseMock );
148+ $ contextMock ->method ('getRedirect ' )
149+ ->willReturn ($ redirectMock );
150+ $ contextMock ->method ('getMessageManager ' )
151+ ->willReturn ($ messageManagerMock );
152+ $ contextMock ->method ('getEventManager ' )
153+ ->willReturn ($ eventManagerMock );
154+ $ contextMock ->method ('getResultRedirectFactory ' )
155+ ->willReturn ($ redirectFactoryMock );
149156
150157 $ urlMock = $ this ->createMock (Url::class);
151158 $ urlMock ->expects ($ this ->once ())
@@ -186,10 +193,10 @@ public function testNoResultsHandle()
186193 $ update = $ this ->createPartialMock (Merge::class, ['getHandles ' ]);
187194 $ update ->expects ($ this ->once ())->method ('getHandles ' )->willReturn ([]);
188195
189- $ layout = $ this ->getMockBuilder (LayoutTestHelper::class)
190- -> onlyMethods ([ ' getUpdate ' ])
191- -> disableOriginalConstructor ()
192- -> getMock ( );
196+ $ layout = $ this ->createPartialMockWithReflection (
197+ Layout::class,
198+ [ ' getUpdate ' ]
199+ );
193200 $ layout ->expects ($ this ->once ())->method ('getUpdate ' )->willReturn ($ update );
194201
195202 $ page = $ this ->createPartialMock (Page::class, ['initLayout ' ]);
@@ -205,10 +212,10 @@ public function testNoResultsHandle()
205212 $ view ->expects ($ this ->once ())->method ('getPage ' )->willReturn ($ page );
206213 $ view ->expects ($ this ->once ())->method ('getLayout ' )->willReturn ($ layout );
207214
208- $ request = $ this ->getMockBuilder (RequestTestHelper::class)
209- -> onlyMethods ([ ' getQueryValue ' ])
210- -> disableOriginalConstructor ()
211- -> getMock ( );
215+ $ request = $ this ->createPartialMockWithReflection (
216+ Request::class,
217+ [ ' getQueryValue ' ]
218+ );
212219 $ request ->expects ($ this ->once ())->method ('getQueryValue ' )->willReturn ($ expectedQuery );
213220
214221 $ catalogSearchAdvanced = $ this ->createPartialMock (
0 commit comments