@@ -43,7 +43,7 @@ class EntityTest extends TestCase
43
43
protected function setUp (): void
44
44
{
45
45
$ this ->urlFactoryMock = $ this ->createMock (UrlFactory::class);
46
- $ this ->urlFinderMock = $ this ->getMockForAbstractClass (UrlFinderInterface::class);
46
+ $ this ->urlFinderMock = $ this ->createMock (UrlFinderInterface::class);
47
47
$ this ->urlFixerMock = $ this ->createMock (UrlFixer::class);
48
48
}
49
49
@@ -68,55 +68,90 @@ public function testGet()
68
68
->method ('getId ' )
69
69
->willReturn ('store2 ' );
70
70
71
- $ urlMock1 = $ this ->getMockForAbstractClass (UrlInterface::class);
72
- $ urlMock1 ->expects ($ this ->once ())
73
- ->method ('getUrl ' )
74
- ->with ('/path1 ' )
75
- ->willReturn ('http://site1.com/path1 ' );
76
- $ urlMock1 ->expects ($ this ->once ())
71
+ $ urlMock1 = $ this ->createMock (UrlInterface::class);
72
+ $ urlMock1
73
+ ->expects ($ this ->any ())
77
74
->method ('setScope ' )
78
75
->with ('store1 ' )
79
76
->willReturnSelf ();
80
- $ urlMock2 = $ this ->getMockForAbstractClass (UrlInterface::class);
81
- $ urlMock2 ->expects ($ this ->once ())
77
+ $ urlMock1
78
+ ->expects ($ this ->any ())
79
+ ->method ('getUrl ' )
80
+ ->with ('/path1 ' )
81
+ ->willReturn ('http://site1.com/path1 ' );
82
+
83
+ $ urlMock2 = $ this ->createMock (UrlInterface::class);
84
+ $ urlMock2
85
+ ->expects ($ this ->any ())
82
86
->method ('getUrl ' )
83
87
->with ('/path2 ' )
84
88
->willReturn ('http://site2.com/path2 ' );
85
- $ urlMock2 ->expects ($ this ->once ())
89
+ $ urlMock2
90
+ ->expects ($ this ->any ())
86
91
->method ('setScope ' )
87
92
->with ('store2 ' )
88
93
->willReturnSelf ();
89
94
90
95
$ urlRewriteMock1 = $ this ->createMock (UrlRewrite::class);
91
- $ urlRewriteMock1 ->expects ($ this ->once ())
96
+ $ urlRewriteMock1
97
+ ->expects ($ this ->once ())
92
98
->method ('getRequestPath ' )
93
99
->willReturn ('/path1 ' );
94
100
$ urlRewriteMock2 = $ this ->createMock (UrlRewrite::class);
95
- $ urlRewriteMock2 ->expects ($ this ->once ())
101
+ $ urlRewriteMock2
102
+ ->expects ($ this ->once ())
96
103
->method ('getRequestPath ' )
97
104
->willReturn ('/path2 ' );
98
105
99
- $ this ->urlFactoryMock ->expects ($ this ->exactly (2 ))
106
+ $ this ->urlFactoryMock
107
+ ->expects ($ this ->exactly (2 ))
100
108
->method ('create ' )
101
- ->willReturnOnConsecutiveCalls ($ urlMock1 , $ urlMock2 );
102
- $ this ->urlFinderMock ->expects ($ this ->exactly (2 ))
109
+ ->willReturnCallback (function () use ($ urlMock1 , $ urlMock2 ) {
110
+ static $ callCount = 0 ;
111
+ $ callCount ++;
112
+
113
+ if ($ callCount === 1 ) {
114
+ return $ urlMock1 ;
115
+ }
116
+
117
+ return $ urlMock2 ;
118
+ });
119
+
120
+ $ this ->urlFinderMock
121
+ ->expects ($ this ->exactly (2 ))
103
122
->method ('findAllByData ' )
104
- ->withConsecutive (
105
- [['store_id ' => 'store1 ' , 'entity_type ' => 'category ' ]],
106
- [['store_id ' => 'store2 ' , 'entity_type ' => 'category ' ]]
107
- )
108
- ->willReturnOnConsecutiveCalls (
109
- [$ urlRewriteMock1 ],
110
- [$ urlRewriteMock2 ]
111
- );
112
-
113
- $ this ->urlFixerMock ->expects ($ this ->exactly (2 ))
123
+ ->willReturnCallback (function ($ data ) use ($ urlRewriteMock1 , $ urlRewriteMock2 ) {
124
+ $ expected1 = ['store_id ' => 'store1 ' , 'entity_type ' => 'category ' ];
125
+ $ expected2 = ['store_id ' => 'store2 ' , 'entity_type ' => 'category ' ];
126
+
127
+ if (array_intersect_assoc ($ expected1 , $ data ) == $ expected1 ) {
128
+ return [$ urlRewriteMock1 ];
129
+ }
130
+
131
+ if (array_intersect_assoc ($ expected2 , $ data ) == $ expected2 ) {
132
+ return [$ urlRewriteMock2 ];
133
+ }
134
+
135
+ return [];
136
+ });
137
+
138
+ $ this ->urlFixerMock
139
+ ->expects ($ this ->exactly (2 ))
114
140
->method ('run ' )
115
- ->withConsecutive (
116
- [$ storeMock1 , 'http://site1.com/path1 ' ],
117
- [$ storeMock2 , 'http://site2.com/path2 ' ]
118
- )
119
- ->willReturnOnConsecutiveCalls ('http://site1.com/fixed/path1 ' , 'http://site2.com/fixed/path2 ' );
141
+ ->willReturnCallback (function ($ store , $ url ) use ($ storeMock1 , $ storeMock2 ) {
142
+ static $ callCount = 0 ;
143
+ $ callCount ++;
144
+
145
+ if ($ callCount === 1 && $ store === $ storeMock1 && $ url === '/path1 ' ) {
146
+ return 'http://site1.com/fixed/path1 ' ;
147
+ }
148
+
149
+ if ($ callCount === 2 && $ store === $ storeMock2 && $ url === '/path2 ' ) {
150
+ return 'http://site2.com/fixed/path2 ' ;
151
+ }
152
+
153
+ return '' ;
154
+ });
120
155
121
156
$ entity = $ this ->createEntity ('category ' , [$ storeMock1 , $ storeMock2 ]);
122
157
0 commit comments