Skip to content

Commit d7a69b9

Browse files
committed
MC-33069: Stabilize Unit tests
1 parent 431a535 commit d7a69b9

File tree

10 files changed

+55
-23
lines changed

10 files changed

+55
-23
lines changed

app/code/Magento/PageCache/Controller/Block/Render.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ public function execute()
2727
$currentRequestUri = $this->getRequest()->getRequestUri();
2828

2929
$origRequest = $this->getRequest()->getParam('originalRequest');
30-
if ($origRequest && is_string($origRequest)) {
31-
$origRequest = json_decode($origRequest, true);
30+
if ($origRequest !== null) {
31+
if ($origRequest && is_string($origRequest)) {
32+
$origRequest = json_decode($origRequest, true);
33+
}
34+
$this->getRequest()->setRouteName($origRequest['route']);
35+
$this->getRequest()->setControllerName($origRequest['controller']);
36+
$this->getRequest()->setActionName($origRequest['action']);
37+
$this->getRequest()->setRequestUri($origRequest['uri']);
3238
}
33-
$this->getRequest()->setRouteName($origRequest['route']);
34-
$this->getRequest()->setControllerName($origRequest['controller']);
35-
$this->getRequest()->setActionName($origRequest['action']);
36-
$this->getRequest()->setRequestUri($origRequest['uri']);
3739

3840
/** @var \Magento\Framework\View\Element\BlockInterface[] $blocks */
3941
$blocks = $this->_getBlocks();

app/code/Magento/PageCache/Test/Unit/Controller/Block/RenderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ public function testExecuteNotAjax()
140140
public function testExecuteNoParams()
141141
{
142142
$this->requestMock->expects($this->once())->method('isAjax')->willReturn(true);
143-
$this->requestMock->expects($this->at(10))
143+
$this->requestMock->expects($this->at(6))
144144
->method('getParam')
145145
->with('blocks', '')
146146
->willReturn('');
147-
$this->requestMock->expects($this->at(11))
147+
$this->requestMock->expects($this->at(7))
148148
->method('getParam')
149149
->with('handles', '')
150150
->willReturn('');

lib/internal/Magento/Framework/Archive/Tar.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ protected function _extractFileHeader()
447447

448448
$header = unpack(self::_getFormatParseHeader(), $headerBlock);
449449

450-
$header['mode'] = octdec($header['mode']);
451-
$header['uid'] = octdec($header['uid']);
452-
$header['gid'] = octdec($header['gid']);
453-
$header['size'] = octdec($header['size']);
454-
$header['mtime'] = octdec($header['mtime']);
455-
$header['checksum'] = octdec($header['checksum']);
450+
$header['mode'] = octdec((int)$header['mode']);
451+
$header['uid'] = octdec((int)$header['uid']);
452+
$header['gid'] = octdec((int)$header['gid']);
453+
$header['size'] = octdec((int)$header['size']);
454+
$header['mtime'] = octdec((int)$header['mtime']);
455+
$header['checksum'] = octdec((int)$header['checksum']);
456456

457457
if ($header['type'] == "5") {
458458
$header['size'] = 0;

lib/internal/Magento/Framework/Cache/Test/Unit/CoreTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public function testSave()
112112
->method('save')
113113
->with($data, $this->anything(), $prefixedTags)
114114
->willReturn(true);
115+
$backendMock->expects($this->once())
116+
->method('getCapabilities')
117+
->willReturn(['priority' => null]);
115118
$frontend = new Core([
116119
'disable_save' => false,
117120
'caching' => true,

lib/internal/Magento/Framework/EntityManager/Sequence/SequenceApplier.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function apply($entity)
7171
$entityType = $this->typeResolver->resolve($entity);
7272

7373
/** @var \Magento\Framework\DB\Sequence\SequenceInterface|null $sequence */
74-
$sequence = $this->sequenceRegistry->retrieve($entityType)['sequence'];
74+
$sequence = $this->sequenceRegistry->retrieve($entityType) ?
75+
$this->sequenceRegistry->retrieve($entityType)['sequence'] : null;
7576

7677
if ($sequence) {
7778
$metadata = $this->metadataPool->getMetadata($entityType);

lib/internal/Magento/Framework/EntityManager/Test/Unit/Sequence/SequenceApplierTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testApplyEntityHasIdentifier()
138138
->method('resolve')
139139
->with($this->entityMock)
140140
->willReturn($entityType);
141-
$this->sequenceRegistryMock->expects($this->once())
141+
$this->sequenceRegistryMock->expects($this->exactly(2))
142142
->method('retrieve')
143143
->with($entityType)
144144
->willReturn($sequenceInfo);
@@ -176,7 +176,7 @@ public function testApplyEntityDoesNotHaveIdentifier()
176176
->method('resolve')
177177
->with($this->entityMock)
178178
->willReturn($entityType);
179-
$this->sequenceRegistryMock->expects($this->once())
179+
$this->sequenceRegistryMock->expects($this->exactly(2))
180180
->method('retrieve')
181181
->with($entityType)
182182
->willReturn($sequenceInfo);

lib/internal/Magento/Framework/View/Helper/PathPattern.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function translateCharacterGroupsFromGlob($pattern)
6767
preg_match_all('~\\\\\\[(\\\\\\!)?[^\\]]+\\\\\\]~i', $pattern, $matches, PREG_OFFSET_CAPTURE);
6868
for ($index = count($matches[0]) - 1; $index >= 0; $index -= 1) {
6969
list($match, $offset) = $matches[0][$index];
70-
$exclude = !empty($matches[1][$index]);
70+
$exclude = !empty($matches[1][$index][0]);
7171
$replacement = substr_replace($match, '[' . ($exclude ? '^' : ''), 0, $exclude ? 4 : 2);
7272
$replacement = substr_replace($replacement, ']', -2);
7373
$replacement = str_replace('\\-', '-', $replacement);

setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ public function testStartAction()
9999
{
100100
$this->webLogger->expects($this->once())->method('clear');
101101
$this->installer->expects($this->once())->method('install');
102-
$this->installer->expects($this->exactly(2))->method('getInstallInfo');
102+
$this->installer->expects($this->exactly(2))
103+
->method('getInstallInfo')
104+
->willReturn(
105+
[
106+
'key' => null,
107+
'message' => null,
108+
]
109+
);
103110
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
104111
$jsonModel = $this->controller->startAction();
105112
$this->assertInstanceOf(JsonModel::class, $jsonModel);
@@ -140,6 +147,14 @@ public function testStartActionWithSampleDataError()
140147
$this->webLogger->expects($this->never())->method('logError');
141148
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
142149
$this->installer->method('install');
150+
$this->installer->expects($this->exactly(2))
151+
->method('getInstallInfo')
152+
->willReturn(
153+
[
154+
'key' => null,
155+
'message' => null,
156+
]
157+
);
143158
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
144159
$jsonModel = $this->controller->startAction();
145160
$this->assertInstanceOf(JsonModel::class, $jsonModel);

setup/src/Magento/Setup/Test/Unit/Fixtures/Quote/QuoteGeneratorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ private function prepareProducts()
234234
->disableOriginalConstructor()
235235
->getMockForAbstractClass();
236236
$option = $this->getMockBuilder(Attribute::class)
237+
->setConstructorArgs(
238+
[
239+
'data' => [
240+
'options' => [
241+
['label' => null],
242+
],
243+
],
244+
],
245+
)
237246
->disableOriginalConstructor()
238247
->getMock();
239248
$optionValue = $this->getMockBuilder(OptionValueInterface::class)

setup/src/Magento/Setup/Test/Unit/Model/Customer/CustomerDataGeneratorTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Setup\Model\Customer\CustomerDataGenerator;
1212
use PHPUnit\Framework\MockObject\MockObject;
1313
use PHPUnit\Framework\TestCase;
14+
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
1415

1516
class CustomerDataGeneratorTest extends TestCase
1617
{
@@ -41,12 +42,13 @@ class CustomerDataGeneratorTest extends TestCase
4142

4243
protected function setUp(): void
4344
{
44-
$this->groupCollectionFactoryMock =
45-
$this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Group\CollectionFactory::class)->addMethods(
45+
$this->groupCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
46+
->disableOriginalConstructor()
47+
->addMethods(
4648
['getAllIds']
4749
)
48-
->onlyMethods(['create'])
49-
->getMock();
50+
->onlyMethods(['create'])
51+
->getMock();
5052

5153
$this->groupCollectionFactoryMock
5254
->expects($this->once())

0 commit comments

Comments
 (0)