Skip to content

Commit 6ca4709

Browse files
Merge branch 'improvement/CE-33707-update-php-unit-to-9-3-0' of github.com:bohdan-harniuk/magento2 into update-phpunit-to-9-3
2 parents 57eafb9 + 0f49073 commit 6ca4709

File tree

25 files changed

+437
-484
lines changed

25 files changed

+437
-484
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"phpcompatibility/php-compatibility": "^9.3",
9090
"phpmd/phpmd": "^2.9.1",
9191
"phpstan/phpstan": "^0.12.77",
92-
"phpunit/phpunit": "^9",
92+
"phpunit/phpunit": "9.3.0",
9393
"sebastian/phpcpd": "^6.0.3",
9494
"squizlabs/php_codesniffer": "~3.5.4",
9595
"symfony/finder": "^5.2"

composer.lock

Lines changed: 200 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/integration/framework/tests/unit/phpunit.xml.dist

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
*/
77
-->
88
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.1/phpunit.xsd"
9+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
1010
colors="true"
1111
columns="max"
1212
beStrictAboutTestsThatDoNotTestAnything="false"
13-
bootstrap="./framework/bootstrap.php"
14-
>
13+
bootstrap="./framework/bootstrap.php">
1514
<!-- Test suites definition -->
1615
<testsuites>
1716
<testsuite name="Unit Tests for Integration Tests Framework">

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AdminConfigFixtureTest.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ protected function setUp(): void
4040
public function testConfig(): void
4141
{
4242
$this->createResolverMock();
43-
$this->object->expects(
44-
$this->at(0)
45-
)->method(
46-
'_getConfigValue'
47-
)->with(
48-
'any_config'
49-
)->willReturn(
50-
'some_value'
51-
);
52-
$this->object->expects($this->at(1))->method('_setConfigValue')->with('any_config', 'some_value');
43+
$this->object
44+
->method('_getConfigValue')
45+
->withConsecutive(['any_config'], ['any_config'])
46+
->willReturnOnConsecutiveCalls('some_value', 'some_value');
47+
5348
$this->object->startTest($this);
5449

55-
$this->object->expects($this->once())->method('_setConfigValue')->with('any_config', 'some_value');
50+
$this->object
51+
->expects($this->once())
52+
->method('_setConfigValue')
53+
->with('any_config', 'some_value');
54+
5655
$this->object->endTest($this);
5756
}
5857

@@ -75,16 +74,11 @@ public function testInitStoreAfter(): void
7574
{
7675
$this->createResolverMock();
7776
$this->object->startTest($this);
78-
$this->object->expects(
79-
$this->at(0)
80-
)->method(
81-
'_getConfigValue'
82-
)->with(
83-
'any_config'
84-
)->willReturn(
85-
'some_value'
86-
);
87-
$this->object->expects($this->at(1))->method('_setConfigValue')->with('any_config', 'some_value');
77+
$this->object
78+
->method('_getConfigValue')
79+
->withConsecutive(['any_config'], ['any_config'])
80+
->willReturnOnConsecutiveCalls('some_value', 'some_value');
81+
8882
$this->object->initStoreAfter();
8983
}
9084

@@ -97,7 +91,7 @@ private function createResolverMock(): void
9791
{
9892
$mock = $this->getMockBuilder(Resolver::class)
9993
->disableOriginalConstructor()
100-
->setMethods(['applyConfigFixtures'])
94+
->onlyMethods(['applyConfigFixtures'])
10195
->getMock();
10296
$mock->method('applyConfigFixtures')
10397
->willReturn($this->getAnnotations()['method'][$this->object::ANNOTATION]);

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ public function testStartTestPreventDoubleAreaLoadingAfterReinitialization()
9393
{
9494
$annotations = ['method' => ['magentoAppArea' => ['global']]];
9595
$this->_testCaseMock->expects($this->once())->method('getAnnotations')->willReturn($annotations);
96-
$this->_applicationMock->expects($this->at(0))->method('getArea')->willReturn('adminhtml');
9796
$this->_applicationMock->expects($this->once())->method('reinitialize');
98-
$this->_applicationMock->expects($this->at(2))->method('getArea')->willReturn('global');
97+
$this->_applicationMock
98+
->method('getArea')
99+
->willReturnOnConsecutiveCalls('adminhtml', 'global');
99100
$this->_applicationMock->expects($this->never())->method('loadArea');
100101
$this->_object->startTest($this->_testCaseMock);
101102
}

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/ConfigFixtureTest.php

Lines changed: 62 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,14 @@ protected function setUp(): void
5353
public function testGlobalConfig(): void
5454
{
5555
$this->createResolverMock();
56-
$this->object->expects(
57-
$this->at(0)
58-
)->method(
59-
'_getConfigValue'
60-
)->with(
61-
'default/web/unsecure/base_url'
62-
)->willReturn(
63-
'http://localhost/'
64-
);
65-
$this->object->expects(
66-
$this->at(1)
67-
)->method(
68-
'_setConfigValue'
69-
)->with(
70-
'default/web/unsecure/base_url',
71-
'http://example.com/'
72-
);
56+
$this->object
57+
->method('_getConfigValue')
58+
->withConsecutive(['default/web/unsecure/base_url'])
59+
->willReturnOnConsecutiveCalls('http://localhost/');
60+
$this->object
61+
->method('_setConfigValue')
62+
->withConsecutive(['default/web/unsecure/base_url', 'http://example.com/']);
63+
7364
$this->object->startTest($this);
7465

7566
$this->object->expects(
@@ -91,27 +82,20 @@ public function testGlobalConfig(): void
9182
public function testSpecificWebsiteConfig(): void
9283
{
9384
$this->createResolverMock();
94-
$this->object->expects(
95-
$this->at(0)
96-
)->method(
97-
'getScopeConfigValue'
98-
)->with(
99-
'web/unsecure/base_url',
100-
ScopeInterface::SCOPE_WEBSITES,
101-
'base'
102-
)->willReturn(
103-
'http://localhost/'
104-
);
105-
$this->object->expects(
106-
$this->at(1)
107-
)->method(
108-
'setScopeConfigValue'
109-
)->with(
110-
'web/unsecure/base_url',
111-
'http://example.com/',
112-
ScopeInterface::SCOPE_WEBSITES,
113-
'base'
114-
);
85+
$this->object
86+
->method('getScopeConfigValue')
87+
->withConsecutive(['web/unsecure/base_url', ScopeInterface::SCOPE_WEBSITES, 'base'])
88+
->willReturnOnConsecutiveCalls('http://localhost/');
89+
$this->object
90+
->method('setScopeConfigValue')
91+
->withConsecutive(
92+
[
93+
'web/unsecure/base_url',
94+
'http://example.com/',
95+
ScopeInterface::SCOPE_WEBSITES,
96+
'base'
97+
]
98+
);
11599
$this->object->startTest($this);
116100

117101
$this->object->expects(
@@ -135,26 +119,24 @@ public function testSpecificWebsiteConfig(): void
135119
public function testCurrentWebsiteConfig(): void
136120
{
137121
$this->createResolverMock();
138-
$this->object->expects(
139-
$this->at(0)
140-
)->method(
141-
'getScopeConfigValue'
142-
)->with(
143-
'web/unsecure/base_url',
144-
ScopeInterface::SCOPE_WEBSITES
145-
)->willReturn(
146-
'http://localhost/'
147-
);
148-
$this->object->expects(
149-
$this->at(1)
150-
)->method(
151-
'setScopeConfigValue'
152-
)->with(
153-
'web/unsecure/base_url',
154-
'http://example.com/',
155-
ScopeInterface::SCOPE_WEBSITES,
156-
null
157-
);
122+
$this->object
123+
->method('getScopeConfigValue')
124+
->withConsecutive(
125+
[
126+
'web/unsecure/base_url',
127+
ScopeInterface::SCOPE_WEBSITES
128+
]
129+
)->willReturnOnConsecutiveCalls('http://localhost/');
130+
$this->object
131+
->method('setScopeConfigValue')
132+
->withConsecutive(
133+
[
134+
'web/unsecure/base_url',
135+
'http://example.com/',
136+
ScopeInterface::SCOPE_WEBSITES,
137+
null
138+
]
139+
);
158140
$this->object->startTest($this);
159141

160142
$this->object->expects(
@@ -178,25 +160,13 @@ public function testCurrentWebsiteConfig(): void
178160
public function testCurrentStoreConfig(): void
179161
{
180162
$this->createResolverMock();
181-
$this->object->expects(
182-
$this->at(0)
183-
)->method(
184-
'_getConfigValue'
185-
)->with(
186-
'dev/restrict/allow_ips',
187-
''
188-
)->willReturn(
189-
'127.0.0.1'
190-
);
191-
$this->object->expects(
192-
$this->at(1)
193-
)->method(
194-
'_setConfigValue'
195-
)->with(
196-
'dev/restrict/allow_ips',
197-
'192.168.0.1',
198-
''
199-
);
163+
$this->object
164+
->method('_getConfigValue')
165+
->withConsecutive(['dev/restrict/allow_ips', ''])
166+
->willReturnOnConsecutiveCalls('127.0.0.1');
167+
$this->object
168+
->method('_setConfigValue')
169+
->withConsecutive(['dev/restrict/allow_ips', '192.168.0.1', '']);
200170
$this->object->startTest($this);
201171

202172
$this->object->expects(
@@ -220,25 +190,13 @@ public function testCurrentStoreConfig(): void
220190
public function testSpecificStoreConfig(): void
221191
{
222192
$this->createResolverMock();
223-
$this->object->expects(
224-
$this->at(0)
225-
)->method(
226-
'_getConfigValue'
227-
)->with(
228-
'dev/restrict/allow_ips',
229-
'admin'
230-
)->willReturn(
231-
'192.168.0.1'
232-
);
233-
$this->object->expects(
234-
$this->at(1)
235-
)->method(
236-
'_setConfigValue'
237-
)->with(
238-
'dev/restrict/allow_ips',
239-
'192.168.0.2',
240-
'admin'
241-
);
193+
$this->object
194+
->method('_getConfigValue')
195+
->withConsecutive(['dev/restrict/allow_ips', 'admin'])
196+
->willReturnOnConsecutiveCalls('192.168.0.1');
197+
$this->object
198+
->method('_setConfigValue')
199+
->withConsecutive(['dev/restrict/allow_ips', '192.168.0.2', 'admin']);
242200
$this->object->startTest($this);
243201

244202
$this->object->expects(
@@ -273,23 +231,13 @@ public function testInitStoreAfter(): void
273231
{
274232
$this->createResolverMock();
275233
$this->object->startTest($this);
276-
$this->object->expects(
277-
$this->at(0)
278-
)->method(
279-
'_getConfigValue'
280-
)->with(
281-
'web/unsecure/base_url'
282-
)->willReturn(
283-
'http://localhost/'
284-
);
285-
$this->object->expects(
286-
$this->at(1)
287-
)->method(
288-
'_setConfigValue'
289-
)->with(
290-
'web/unsecure/base_url',
291-
'http://example.com/'
292-
);
234+
$this->object
235+
->method('_getConfigValue')
236+
->withConsecutive(['web/unsecure/base_url'])
237+
->willReturnOnConsecutiveCalls('http://localhost/');
238+
$this->object
239+
->method('_setConfigValue')
240+
->withConsecutive(['web/unsecure/base_url', 'http://example.com/']);
293241
$this->object->initStoreAfter();
294242
}
295243

@@ -302,7 +250,7 @@ private function createResolverMock(): void
302250
{
303251
$mock = $this->getMockBuilder(Resolver::class)
304252
->disableOriginalConstructor()
305-
->setMethods(['applyConfigFixtures'])
253+
->onlyMethods(['applyConfigFixtures'])
306254
->getMock();
307255
$mock->method('applyConfigFixtures')
308256
->willReturn($this->getAnnotations()['method'][$this->object::ANNOTATION]);

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ class DataFixtureTest extends TestCase
3838
protected function setUp(): void
3939
{
4040
$this->object = $this->getMockBuilder(DataFixture::class)
41-
->setMethods(['_applyOneFixture', 'getComponentRegistrar', 'getTestKey'])
41+
->onlyMethods(['_applyOneFixture', 'getTestKey'])
42+
->addMethods(['getComponentRegistrar'])
4243
->getMock();
4344
$this->testsIsolationMock = $this->getMockBuilder(TestsIsolation::class)
44-
->setMethods(['createDbSnapshot', 'checkTestIsolation'])
45+
->onlyMethods(['createDbSnapshot', 'checkTestIsolation'])
4546
->getMock();
4647
/** @var ObjectManagerInterface|\PHPUnit\Framework\MockObject\MockObject $objectManager */
4748
$objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
48-
->setMethods(['get'])
49+
->onlyMethods(['get'])
4950
->disableOriginalConstructor()
5051
->getMockForAbstractClass();
5152
$objectManager->expects($this->atLeastOnce())->method('get')->with(TestsIsolation::class)
@@ -187,16 +188,13 @@ public function testStartTransactionClassAnnotation(): void
187188
public function testStartTransactionMethodAnnotation(): void
188189
{
189190
$this->createResolverMock();
190-
$this->object->expects($this->at(0))
191+
$this->object
191192
->method('_applyOneFixture')
192-
->with([__CLASS__, 'sampleFixtureTwo']);
193-
$this->object->expects(
194-
$this->at(1)
195-
)->method(
196-
'_applyOneFixture'
197-
)->with(
198-
$this->stringEndsWith('path/to/fixture/script.php')
199-
);
193+
->withConsecutive(
194+
[[__CLASS__, 'sampleFixtureTwo']],
195+
[$this->stringEndsWith('path/to/fixture/script.php')]
196+
);
197+
200198
$this->object->startTransaction($this);
201199
}
202200

@@ -269,7 +267,7 @@ private function createResolverMock(): void
269267
{
270268
$mock = $this->getMockBuilder(Resolver::class)
271269
->disableOriginalConstructor()
272-
->setMethods(['applyDataFixtures', 'getComponentRegistrar'])
270+
->onlyMethods(['applyDataFixtures', 'getComponentRegistrar'])
273271
->getMock();
274272
$mock->expects($this->any())->method('getComponentRegistrar')
275273
->willReturn(new ComponentRegistrar());

0 commit comments

Comments
 (0)