Skip to content

Commit 70c84e0

Browse files
karyna-txmav
authored andcommitted
34441: fix unit tests failures
1 parent 7b3ae93 commit 70c84e0

File tree

9 files changed

+29
-13
lines changed

9 files changed

+29
-13
lines changed

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/Select/AllowspecificTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public function testGetAfterElementHtml()
8787
$afterHtmlCode = 'after html';
8888
$this->_object->setData('after_element_html', $afterHtmlCode);
8989
$this->_object->setForm($this->_formMock);
90+
$this->_object->setId('test');
91+
$this->_object->setData('html_id', 'spec_element');
9092

9193
$actual = $this->_object->getAfterElementHtml();
9294

app/code/Magento/Customer/Ui/Component/Listing/Column/AccountLock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function prepareDataSource(array $dataSource)
4242
if (isset($dataSource['data']['items'])) {
4343
foreach ($dataSource['data']['items'] as & $item) {
4444
if (array_key_exists('lock_expires', $item)) {
45-
$lockExpires = new \DateTime($item['lock_expires']);
45+
$lockExpires = new \DateTime($item['lock_expires'] ?? 'now');
4646
if ($lockExpires > new \DateTime()) {
4747
$item['lock_expires'] = __('Locked');
4848
} else {

app/code/Magento/Paypal/Test/Unit/Model/PayflowlinkTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\Framework\DataObject;
12+
use Magento\Framework\Math\Random;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1314
use Magento\Payment\Model\Method\ConfigInterfaceFactory;
1415
use Magento\Paypal\Block\Payment\Info;
@@ -51,6 +52,9 @@ class PayflowlinkTest extends TestCase
5152
/** @var ScopeConfigInterface|MockObject */
5253
protected $scopeConfigMock;
5354

55+
/**
56+
* @inheritdoc
57+
*/
5458
protected function setUp(): void
5559
{
5660
$this->store = $this->createMock(Store::class);
@@ -109,6 +113,7 @@ protected function setUp(): void
109113
'configFactory' => $configFactoryMock,
110114
'requestFactory' => $requestFactory,
111115
'gateway' => $this->gatewayMock,
116+
'mathRandom' => new Random()
112117
]
113118
);
114119
$this->model->setInfoInstance($this->infoInstance);

app/code/Magento/Sales/Model/Order.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ public function addRelatedObject(\Magento\Framework\Model\AbstractModel $object)
20742074
public function getCreatedAtFormatted($format)
20752075
{
20762076
return $this->timezone->formatDateTime(
2077-
new \DateTime($this->getCreatedAt()),
2077+
new \DateTime($this->getCreatedAt() ?? 'now'),
20782078
$format,
20792079
$format,
20802080
$this->localeResolver->getDefaultLocale(),

lib/internal/Magento/Framework/Code/Generator/ClassGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ protected function createMethodGenerator()
226226
*/
227227
public function getNamespaceName()
228228
{
229-
return ltrim(parent::getNamespaceName(), '\\') ?: null;
229+
$namespaceName = parent::getNamespaceName();
230+
if ($namespaceName !== null) {
231+
$namespaceName = ltrim(parent::getNamespaceName(), '\\') ?: null;
232+
}
233+
return $namespaceName;
230234
}
231235
}

lib/internal/Magento/Framework/Stdlib/StringUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function strrev($str)
207207
* @param int $offset
208208
* @return int|bool
209209
*/
210-
public function strpos($haystack, $needle, $offset = null)
210+
public function strpos($haystack, $needle, $offset = 0)
211211
{
212212
return mb_strpos($haystack, $needle, $offset, self::ICONV_CHARSET);
213213
}

lib/internal/Magento/Framework/View/Test/Unit/Asset/Bundle/ManagerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public function testAddAssetWithExcludedFile()
118118
$this->asset->expects($this->atLeastOnce())
119119
->method('getFilePath')
120120
->willReturn('source/file.min.js');
121+
$this->asset->method('getPath')
122+
->willReturn(''); // PHP 8.1. compatibility
121123
$this->filesystem->expects($this->once())
122124
->method('getDirectoryRead')
123125
->with(DirectoryList::APP)
@@ -171,6 +173,8 @@ public function testAddAssetWithExcludedDirectory()
171173
$this->asset->expects($this->atLeastOnce())
172174
->method('getContext')
173175
->willReturn($context);
176+
$this->asset->method('getPath')
177+
->willReturn(''); // PHP 8.1. compatibility
174178
$this->bundleConfig->expects($this->atLeastOnce())
175179
->method('getConfig')
176180
->with($context)
@@ -201,6 +205,8 @@ public function testAddAsset()
201205
->method('getDirectoryRead')
202206
->with(DirectoryList::APP)
203207
->willReturn($dirRead);
208+
$dirRead->method('getAbsolutePath')
209+
->willReturn('some/excluded/file');
204210
$this->asset->expects($this->atLeastOnce())
205211
->method('getSourceFile')
206212
->willReturn('/path/to/source/file.min.js');

lib/internal/Magento/Framework/View/Test/Unit/Asset/BundleTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,14 @@ public function testMinSuffix()
109109
$assetMock = $this->getMockBuilder(LocalInterface::class)
110110
->setMethods(['getContentType', 'getContext'])
111111
->getMockForAbstractClass();
112-
$assetMock
113-
->expects($this->any())
114-
->method('getContext')
112+
$assetMock->method('getContext')
115113
->willReturn($contextMock);
116-
$assetMock
117-
->expects($this->any())
118-
->method('getContentType')
114+
$assetMock->method('getContentType')
119115
->willReturn('js');
120-
$assetMock
121-
->expects($this->any())
122-
->method('getFilePath')
116+
$assetMock->method('getFilePath')
123117
->willReturn('onefile.js');
118+
$assetMock->method('getContent')
119+
->willReturn(''); // PHP 8.1 compatibility
124120

125121
$writeMock = $this->getMockBuilder(WriteInterface::class)
126122
->getMockForAbstractClass();

lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/ImageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ public function testUploadPreviewImage(): void
300300
{
301301
$scope = 'test_scope';
302302
$tmpFilePath = '/media_path/tmp/temporary.png';
303+
304+
$this->_imageMock->method('getImageType')
305+
->willReturn(0); // PHP 8.1 compatibility
303306
$this->_themeMock->method('getPreviewImage')->willReturn('test.png');
304307
$this->_uploaderMock->expects($this->once())
305308
->method('uploadPreviewImage')

0 commit comments

Comments
 (0)