@@ -60,65 +60,25 @@ public function testGetEmptyStores()
60
60
public function testGet ()
61
61
{
62
62
$ storeMock1 = $ this ->createMock (Store::class);
63
- $ storeMock1 ->expects ($ this ->exactly (2 ))
64
- ->method ('getId ' )
65
- ->willReturn ('store1 ' );
66
63
$ storeMock2 = $ this ->createMock (Store::class);
67
- $ storeMock2 ->expects ($ this ->exactly (2 ))
68
- ->method ('getId ' )
69
- ->willReturn ('store2 ' );
70
64
71
65
$ urlMock1 = $ this ->createMock (UrlInterface::class);
72
- $ urlMock1
73
- ->expects ($ this ->any ())
74
- ->method ('setScope ' )
75
- ->with ('store1 ' )
76
- ->willReturnSelf ();
77
- $ urlMock1
78
- ->expects ($ this ->any ())
79
- ->method ('getUrl ' )
80
- ->with ('/path1 ' )
81
- ->willReturn ('http://site1.com/path1 ' );
82
-
83
66
$ urlMock2 = $ this ->createMock (UrlInterface::class);
84
- $ urlMock2
85
- ->expects ($ this ->any ())
86
- ->method ('getUrl ' )
87
- ->with ('/path2 ' )
88
- ->willReturn ('http://site2.com/path2 ' );
89
- $ urlMock2
90
- ->expects ($ this ->any ())
91
- ->method ('setScope ' )
92
- ->with ('store2 ' )
93
- ->willReturnSelf ();
94
67
95
68
$ urlRewriteMock1 = $ this ->createMock (UrlRewrite::class);
96
- $ urlRewriteMock1
97
- ->expects ($ this ->once ())
98
- ->method ('getRequestPath ' )
99
- ->willReturn ('/path1 ' );
100
69
$ urlRewriteMock2 = $ this ->createMock (UrlRewrite::class);
101
- $ urlRewriteMock2
102
- ->expects ($ this ->once ())
103
- ->method ('getRequestPath ' )
104
- ->willReturn ('/path2 ' );
105
70
106
- $ this ->urlFactoryMock
107
- ->expects ($ this ->exactly (2 ))
108
- ->method ('create ' )
109
- ->willReturnCallback (function () use ($ urlMock1 , $ urlMock2 ) {
110
- static $ callCount = 0 ;
111
- $ callCount ++;
71
+ $ this ->setupUrlMocks ($ urlMock1 , '/path1 ' , 'http://site1.com/path1 ' , 'store1 ' );
72
+ $ this ->setupUrlMocks ($ urlMock2 , '/path2 ' , 'http://site2.com/path2 ' , 'store2 ' );
112
73
113
- if ($ callCount === 1 ) {
114
- return $ urlMock1 ;
115
- }
74
+ $ this ->setupStoreMocks ($ storeMock1 , 'store1 ' , 2 );
75
+ $ this ->setupStoreMocks ($ storeMock2 , 'store2 ' , 2 );
116
76
117
- return $ urlMock2 ;
118
- } );
77
+ $ this -> setupUrlRewriteMocks ( $ urlRewriteMock1 , ' /path1 ' ) ;
78
+ $ this -> setupUrlRewriteMocks ( $ urlRewriteMock2 , ' /path2 ' );
119
79
120
- $ this ->urlFinderMock
121
- ->expects ($ this ->exactly (2 ))
80
+ $ this ->setupUrlFactoryMock ( $ urlMock1 , $ urlMock2 );
81
+ $ this -> urlFinderMock ->expects ($ this ->exactly (2 ))
122
82
->method ('findAllByData ' )
123
83
->willReturnCallback (function ($ data ) use ($ urlRewriteMock1 , $ urlRewriteMock2 ) {
124
84
$ expected1 = ['store_id ' => 'store1 ' , 'entity_type ' => 'category ' ];
@@ -135,8 +95,7 @@ public function testGet()
135
95
return [];
136
96
});
137
97
138
- $ this ->urlFixerMock
139
- ->expects ($ this ->exactly (2 ))
98
+ $ this ->urlFixerMock ->expects ($ this ->exactly (2 ))
140
99
->method ('run ' )
141
100
->willReturnCallback (function ($ store , $ url ) use ($ storeMock1 , $ storeMock2 ) {
142
101
static $ callCount = 0 ;
@@ -154,7 +113,6 @@ public function testGet()
154
113
});
155
114
156
115
$ entity = $ this ->createEntity ('category ' , [$ storeMock1 , $ storeMock2 ]);
157
-
158
116
$ this ->assertEquals (
159
117
[
160
118
'http://site1.com/fixed/path1 ' ,
@@ -164,6 +122,44 @@ public function testGet()
164
122
);
165
123
}
166
124
125
+ private function setupStoreMocks ($ storeMock , $ storeId , $ times )
126
+ {
127
+ $ storeMock ->expects ($ this ->exactly ($ times ))
128
+ ->method ('getId ' )
129
+ ->willReturn ($ storeId );
130
+ }
131
+
132
+ private function setupUrlMocks ($ urlMock , $ requestPath , $ returnUrl , $ storeId )
133
+ {
134
+ $ urlMock ->expects ($ this ->any ())
135
+ ->method ('setScope ' )
136
+ ->with ($ storeId )
137
+ ->willReturnSelf ();
138
+ $ urlMock ->expects ($ this ->any ())
139
+ ->method ('getUrl ' )
140
+ ->with ($ requestPath )
141
+ ->willReturn ($ returnUrl );
142
+ }
143
+
144
+ private function setupUrlRewriteMocks ($ urlRewriteMock , $ requestPath )
145
+ {
146
+ $ urlRewriteMock ->expects ($ this ->once ())
147
+ ->method ('getRequestPath ' )
148
+ ->willReturn ($ requestPath );
149
+ }
150
+
151
+ private function setupUrlFactoryMock ($ urlMock1 , $ urlMock2 )
152
+ {
153
+ $ this ->urlFactoryMock ->expects ($ this ->exactly (2 ))
154
+ ->method ('create ' )
155
+ ->willReturnCallback (function () use ($ urlMock1 , $ urlMock2 ) {
156
+ static $ callCount = 0 ;
157
+ $ callCount ++;
158
+
159
+ return $ callCount === 1 ? $ urlMock1 : $ urlMock2 ;
160
+ });
161
+ }
162
+
167
163
/**
168
164
* @param string $entityType
169
165
* @param array $stores
0 commit comments