Skip to content

Commit 5724840

Browse files
Merge pull request #43 from magento-commerce/MCLOUD-13148
MCLOUD-13148: Added support for PHP8.4
2 parents 47cdba6 + f0539ff commit 5724840

File tree

6 files changed

+96
-56
lines changed

6 files changed

+96
-56
lines changed

Test/Functional/Acceptance/AcceptanceCest.php

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
namespace Magento\CloudComponents\Test\Functional\Acceptance;
99

10+
/**
11+
* Class AcceptanceCest
12+
*
13+
* This class provides acceptance tests for Magento Cloud components.
14+
*/
1015
abstract class AcceptanceCest
1116
{
1217
/**

Test/Unit/Model/UrlFinder/EntityTest.php

+79-48
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class EntityTest extends TestCase
4343
protected function setUp(): void
4444
{
4545
$this->urlFactoryMock = $this->createMock(UrlFactory::class);
46-
$this->urlFinderMock = $this->getMockForAbstractClass(UrlFinderInterface::class);
46+
$this->urlFinderMock = $this->createMock(UrlFinderInterface::class);
4747
$this->urlFixerMock = $this->createMock(UrlFixer::class);
4848
}
4949

@@ -60,66 +60,59 @@ 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

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())
77-
->method('setScope')
78-
->with('store1')
79-
->willReturnSelf();
80-
$urlMock2 = $this->getMockForAbstractClass(UrlInterface::class);
81-
$urlMock2->expects($this->once())
82-
->method('getUrl')
83-
->with('/path2')
84-
->willReturn('http://site2.com/path2');
85-
$urlMock2->expects($this->once())
86-
->method('setScope')
87-
->with('store2')
88-
->willReturnSelf();
65+
$urlMock1 = $this->createMock(UrlInterface::class);
66+
$urlMock2 = $this->createMock(UrlInterface::class);
8967

9068
$urlRewriteMock1 = $this->createMock(UrlRewrite::class);
91-
$urlRewriteMock1->expects($this->once())
92-
->method('getRequestPath')
93-
->willReturn('/path1');
9469
$urlRewriteMock2 = $this->createMock(UrlRewrite::class);
95-
$urlRewriteMock2->expects($this->once())
96-
->method('getRequestPath')
97-
->willReturn('/path2');
9870

99-
$this->urlFactoryMock->expects($this->exactly(2))
100-
->method('create')
101-
->willReturnOnConsecutiveCalls($urlMock1, $urlMock2);
71+
$this->setupUrlMocks($urlMock1, '/path1', 'http://site1.com/path1', 'store1');
72+
$this->setupUrlMocks($urlMock2, '/path2', 'http://site2.com/path2', 'store2');
73+
74+
$this->setupStoreMocks($storeMock1, 'store1', 2);
75+
$this->setupStoreMocks($storeMock2, 'store2', 2);
76+
77+
$this->setupUrlRewriteMocks($urlRewriteMock1, '/path1');
78+
$this->setupUrlRewriteMocks($urlRewriteMock2, '/path2');
79+
80+
$this->setupUrlFactoryMock($urlMock1, $urlMock2);
10281
$this->urlFinderMock->expects($this->exactly(2))
10382
->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-
);
83+
->willReturnCallback(function ($data) use ($urlRewriteMock1, $urlRewriteMock2) {
84+
$expected1 = ['store_id' => 'store1', 'entity_type' => 'category'];
85+
$expected2 = ['store_id' => 'store2', 'entity_type' => 'category'];
86+
87+
if (array_intersect_assoc($expected1, $data) == $expected1) {
88+
return [$urlRewriteMock1];
89+
}
90+
91+
if (array_intersect_assoc($expected2, $data) == $expected2) {
92+
return [$urlRewriteMock2];
93+
}
94+
95+
return [];
96+
});
11297

11398
$this->urlFixerMock->expects($this->exactly(2))
11499
->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');
100+
->willReturnCallback(function ($store, $url) use ($storeMock1, $storeMock2) {
101+
static $callCount = 0;
102+
$callCount++;
120103

121-
$entity = $this->createEntity('category', [$storeMock1, $storeMock2]);
104+
if ($callCount === 1 && $store === $storeMock1 && $url === '/path1') {
105+
return 'http://site1.com/fixed/path1';
106+
}
107+
108+
if ($callCount === 2 && $store === $storeMock2 && $url === '/path2') {
109+
return 'http://site2.com/fixed/path2';
110+
}
122111

112+
return '';
113+
});
114+
115+
$entity = $this->createEntity('category', [$storeMock1, $storeMock2]);
123116
$this->assertEquals(
124117
[
125118
'http://site1.com/fixed/path1',
@@ -129,6 +122,44 @@ public function testGet()
129122
);
130123
}
131124

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+
132163
/**
133164
* @param string $entityType
134165
* @param array $stores

Test/Unit/Model/UrlFixerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testRunWithConfigRewrites(
7373
/**
7474
* @return array
7575
*/
76-
public function runDataProvider(): array
76+
public static function runDataProvider(): array
7777
{
7878
return [
7979
'rewrites enabled, url without "magento" part' => [

Test/Unit/phpunit.xml.dist

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/10.5/phpunit.xsd"
55
colors="true"
66
columns="max"
77
bootstrap="../../vendor/autoload.php"
@@ -12,7 +12,11 @@
1212
<directory suffix="Test.php">./</directory>
1313
</testsuite>
1414
</testsuites>
15-
15+
<source>
16+
<include>
17+
<directory>../../</directory>
18+
</include>
19+
</source>
1620
<php>
1721
<ini name="date.timezone" value="UTC"/>
1822
</php>

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/magento-cloud-components",
33
"description": "Cloud Components Module for Magento 2.x",
44
"type": "magento2-module",
5-
"version": "1.0.13",
5+
"version": "1.0.14",
66
"require": {
77
"php": "^8.0",
88
"ext-json": "*",
@@ -22,9 +22,9 @@
2222
"codeception/module-rest": "^3.0",
2323
"consolidation/robo": "^3.0",
2424
"phpmd/phpmd": "@stable",
25-
"phpstan/phpstan": "~1.2.0",
26-
"phpunit/phpunit": "^9.5",
27-
"squizlabs/php_codesniffer": "^3.0"
25+
"phpstan/phpstan": "~1.2.0 || ^2.0",
26+
"phpunit/phpunit": "^10.0",
27+
"squizlabs/php_codesniffer": "^3.7"
2828
},
2929
"config": {
3030
"sort-packages": true

tests/static/phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parameters:
44
- %currentWorkingDirectory%/Console
55
- %currentWorkingDirectory%/Model
66
- %currentWorkingDirectory%/Cron
7-
excludes_analyse:
7+
excludePaths:
88
- %currentWorkingDirectory%/Test/*
99
reportUnmatchedIgnoredErrors: false
1010
ignoreErrors:

0 commit comments

Comments
 (0)