Skip to content

Commit f0539ff

Browse files
committed
Add support of php 8.4 to cloud-components
1 parent dd52d1f commit f0539ff

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

Test/Unit/Model/UrlFinder/EntityTest.php

+47-51
Original file line numberDiff line numberDiff line change
@@ -60,65 +60,25 @@ public function testGetEmptyStores()
6060
public function testGet()
6161
{
6262
$storeMock1 = $this->createMock(Store::class);
63-
$storeMock1->expects($this->exactly(2))
64-
->method('getId')
65-
->willReturn('store1');
6663
$storeMock2 = $this->createMock(Store::class);
67-
$storeMock2->expects($this->exactly(2))
68-
->method('getId')
69-
->willReturn('store2');
7064

7165
$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-
8366
$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();
9467

9568
$urlRewriteMock1 = $this->createMock(UrlRewrite::class);
96-
$urlRewriteMock1
97-
->expects($this->once())
98-
->method('getRequestPath')
99-
->willReturn('/path1');
10069
$urlRewriteMock2 = $this->createMock(UrlRewrite::class);
101-
$urlRewriteMock2
102-
->expects($this->once())
103-
->method('getRequestPath')
104-
->willReturn('/path2');
10570

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');
11273

113-
if ($callCount === 1) {
114-
return $urlMock1;
115-
}
74+
$this->setupStoreMocks($storeMock1, 'store1', 2);
75+
$this->setupStoreMocks($storeMock2, 'store2', 2);
11676

117-
return $urlMock2;
118-
});
77+
$this->setupUrlRewriteMocks($urlRewriteMock1, '/path1');
78+
$this->setupUrlRewriteMocks($urlRewriteMock2, '/path2');
11979

120-
$this->urlFinderMock
121-
->expects($this->exactly(2))
80+
$this->setupUrlFactoryMock($urlMock1, $urlMock2);
81+
$this->urlFinderMock->expects($this->exactly(2))
12282
->method('findAllByData')
12383
->willReturnCallback(function ($data) use ($urlRewriteMock1, $urlRewriteMock2) {
12484
$expected1 = ['store_id' => 'store1', 'entity_type' => 'category'];
@@ -135,8 +95,7 @@ public function testGet()
13595
return [];
13696
});
13797

138-
$this->urlFixerMock
139-
->expects($this->exactly(2))
98+
$this->urlFixerMock->expects($this->exactly(2))
14099
->method('run')
141100
->willReturnCallback(function ($store, $url) use ($storeMock1, $storeMock2) {
142101
static $callCount = 0;
@@ -154,7 +113,6 @@ public function testGet()
154113
});
155114

156115
$entity = $this->createEntity('category', [$storeMock1, $storeMock2]);
157-
158116
$this->assertEquals(
159117
[
160118
'http://site1.com/fixed/path1',
@@ -164,6 +122,44 @@ public function testGet()
164122
);
165123
}
166124

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+
167163
/**
168164
* @param string $entityType
169165
* @param array $stores

0 commit comments

Comments
 (0)