Skip to content

Commit 5f8d1f9

Browse files
committed
Fix Unit tests to be compatible with php8
1 parent 9a72a4f commit 5f8d1f9

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

app/code/Magento/Email/Model/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function getProcessedTemplateSubject(array $variables)
252252
);
253253

254254
try {
255-
$processedResult = $processor->setStoreId($storeId)->filter(__($this->getTemplateSubject()));
255+
$processedResult = $processor->setStoreId($storeId)->filter(__($this->getTemplateSubject())->render());
256256
} catch (\Exception $e) {
257257
$this->cancelDesignConfig();
258258
throw new \Magento\Framework\Exception\MailException(__($e->getMessage()), $e);

app/code/Magento/Theme/Model/Indexer/Design/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function prepareFields()
174174
$this->data['fieldsets'][$fieldsetName]['fields'][$fieldName]['origin'] =
175175
$this->data['fieldsets'][$fieldsetName]['fields'][$fieldName]['origin']
176176
?: $this->data['fieldsets'][$fieldsetName]['fields'][$fieldName]['name'];
177-
if ($fieldsetName != 0) {
177+
if ((int) $fieldsetName !== 0) {
178178
$this->data['fieldsets'][$fieldsetName]['fields'][$fieldName]['name'] =
179179
$this->data['fieldsets'][$fieldsetName]['name'] . '_'
180180
. $this->data['fieldsets'][$fieldsetName]['fields'][$fieldName]['name'];

lib/internal/Magento/Framework/Filesystem/Driver/Http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected function getScheme($scheme = null)
250250
*/
251251
protected function open($hostname, $port)
252252
{
253-
$result = @fsockopen($hostname, $port, $errorNumber, $errorMessage);
253+
$result = @fsockopen($hostname, $port, $errorNumber = null, $errorMessage = null);
254254
if ($result === false) {
255255
throw new FileSystemException(
256256
new \Magento\Framework\Phrase(

lib/internal/Magento/Framework/Filter/Template.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Magento\Framework\Filter;
1111

12+
use Exception;
13+
use InvalidArgumentException;
1214
use Magento\Framework\App\ObjectManager;
1315
use Magento\Framework\Filter\DirectiveProcessor\DependDirective;
1416
use Magento\Framework\Filter\DirectiveProcessor\ForDirective;
@@ -168,29 +170,34 @@ public function getTemplateProcessor()
168170
*
169171
* @param string $value
170172
* @return string
171-
* @throws \Exception
173+
* @throws Exception
172174
*/
173175
public function filter($value)
174176
{
177+
if (!is_string($value)) {
178+
//phpcs:ignore Magento2.Exceptions.DirectThrow
179+
throw new InvalidArgumentException(__(
180+
'Argument \'value\' must be type of string, %1 given.',
181+
gettype($value)
182+
)->render());
183+
}
184+
175185
foreach ($this->directiveProcessors as $directiveProcessor) {
176186
if (!$directiveProcessor instanceof DirectiveProcessorInterface) {
177-
throw new \InvalidArgumentException(
187+
throw new InvalidArgumentException(
178188
'Directive processors must implement ' . DirectiveProcessorInterface::class
179189
);
180190
}
181191

182192
if (preg_match_all($directiveProcessor->getRegularExpression(), $value, $constructions, PREG_SET_ORDER)) {
183193
foreach ($constructions as $construction) {
184194
$replacedValue = $directiveProcessor->process($construction, $this, $this->templateVars);
185-
186195
$value = str_replace($construction[0], $replacedValue, $value);
187196
}
188197
}
189198
}
190199

191-
$value = $this->afterFilter($value);
192-
193-
return $value;
200+
return $this->afterFilter($value);
194201
}
195202

196203
/**

lib/internal/Magento/Framework/Indexer/Test/Unit/MultiDimensionProviderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ private function getDimensionProviderMock($dimensions)
221221
->disableOriginalClone()
222222
->disableArgumentCloning()
223223
->disallowMockingUnknownTypes()
224-
->setMethods(['getIterator'])
224+
->onlyMethods(['getIterator'])
225225
->getMockForAbstractClass();
226226

227227
$dimensionProviderMock->expects($this->any())
228228
->method('getIterator')
229229
->willReturnCallback(
230230
function () use ($dimensions) {
231-
return \SplFixedArray::fromArray($dimensions);
231+
return new \ArrayIterator($dimensions);
232232
}
233233
);
234234

@@ -248,7 +248,7 @@ private function getDimensionMock(string $name, string $value)
248248
->disableOriginalClone()
249249
->disableArgumentCloning()
250250
->disallowMockingUnknownTypes()
251-
->setMethods(['getName', 'getValue'])
251+
->onlyMethods(['getName', 'getValue'])
252252
->getMock();
253253

254254
$dimensionMock->expects($this->any())

0 commit comments

Comments
 (0)