@@ -13,6 +13,9 @@ class PathProcessorTest extends \PHPUnit\Framework\TestCase
13
13
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Store\Model\StoreManagerInterface */
14
14
private $ storeManagerMock ;
15
15
16
+ /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ResolverInterface */
17
+ private $ localeResolverMock ;
18
+
16
19
/** @var \Magento\Webapi\Controller\PathProcessor */
17
20
private $ model ;
18
21
@@ -24,29 +27,42 @@ class PathProcessorTest extends \PHPUnit\Framework\TestCase
24
27
25
28
protected function setUp ()
26
29
{
27
- $ this ->storeManagerMock = $ this ->getMockBuilder (\Magento \Store \Model \StoreManagerInterface::class)
28
- ->disableOriginalConstructor ()
29
- ->getMock ();
30
- $ this ->storeManagerMock ->expects ($ this ->once ())
31
- ->method ('getStores ' )
32
- ->willReturn ([$ this ->arbitraryStoreCode => 'store object ' , 'default ' => 'default store object ' ]);
33
- $ this ->model = new \Magento \Webapi \Controller \PathProcessor ($ this ->storeManagerMock );
30
+ $ store = $ this ->createMock (\Magento \Store \Api \Data \StoreInterface::class);
31
+ $ store ->method ('getId ' )->willReturn (2 );
32
+
33
+ $ this ->storeManagerMock = $ this ->createConfiguredMock (
34
+ \Magento \Store \Model \StoreManagerInterface::class,
35
+ [
36
+ 'getStores ' => [$ this ->arbitraryStoreCode => 'store object ' , 'default ' => 'default store object ' ],
37
+ 'getStore ' => $ store ,
38
+ ]
39
+ );
40
+ $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStores ' );
41
+
42
+ $ this ->localeResolverMock = $ this ->createMock (\Magento \Framework \Locale \ResolverInterface::class);
43
+ $ this ->localeResolverMock ->method ('emulate ' )->with (2 );
44
+
45
+ $ this ->model = new \Magento \Webapi \Controller \PathProcessor ($ this ->storeManagerMock , $ this ->localeResolverMock );
34
46
}
35
47
36
48
/**
37
49
* @dataProvider processPathDataProvider
38
50
*
39
51
* @param string $storeCodeInPath
40
52
* @param string $storeCodeSet
41
- * @param int $setCurrentStoreCallCtr
53
+ * @param int $setCurrentStoreCallCtr
42
54
*/
43
55
public function testAllStoreCode ($ storeCodeInPath , $ storeCodeSet , $ setCurrentStoreCallCtr = 1 )
44
56
{
45
- $ storeCodeInPath = !$ storeCodeInPath ?: '/ ' . $ storeCodeInPath ; // add leading slash if store code not empty
46
- $ inPath = 'rest ' . $ storeCodeInPath . $ this ->endpointPath ;
57
+ $ storeCodeInPath = !$ storeCodeInPath ? : '/ ' . $ storeCodeInPath ; // add leading slash if store code not empty
58
+ $ inPath = 'rest ' . $ storeCodeInPath . $ this ->endpointPath ;
47
59
$ this ->storeManagerMock ->expects ($ this ->exactly ($ setCurrentStoreCallCtr ))
48
60
->method ('setCurrentStore ' )
49
61
->with ($ storeCodeSet );
62
+ if ($ setCurrentStoreCallCtr > 0 ) {
63
+ $ this ->localeResolverMock ->expects ($ this ->once ())
64
+ ->method ('emulate ' );
65
+ }
50
66
$ result = $ this ->model ->process ($ inPath );
51
67
$ this ->assertSame ($ this ->endpointPath , $ result );
52
68
}
@@ -57,10 +73,10 @@ public function testAllStoreCode($storeCodeInPath, $storeCodeSet, $setCurrentSto
57
73
public function processPathDataProvider ()
58
74
{
59
75
return [
60
- 'All store code ' => ['all ' , Store::ADMIN_CODE ],
61
- 'Default store code ' => ['' , 'default ' , 0 ],
62
- 'Arbitrary store code ' => [$ this ->arbitraryStoreCode , $ this ->arbitraryStoreCode ],
63
- 'Explicit default store code ' => ['default ' , 'default ' ]
76
+ 'All store code ' => ['all ' , Store::ADMIN_CODE ],
77
+ 'Default store code ' => ['' , 'default ' , 0 ],
78
+ 'Arbitrary store code ' => [$ this ->arbitraryStoreCode , $ this ->arbitraryStoreCode ],
79
+ 'Explicit default store code ' => ['default ' , 'default ' ],
64
80
];
65
81
}
66
82
}
0 commit comments