Skip to content

Commit 36752e2

Browse files
Raj MohanRaj Mohan
authored andcommitted
AC-12092_PHPUnit10: PHP Unit 10 Deprecation Fixes For Framework DB, Data, Encryption, Profiler, Validator Modules
1 parent a6d7473 commit 36752e2

File tree

6 files changed

+153
-147
lines changed

6 files changed

+153
-147
lines changed

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlFactoryTest.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818

1919
class MysqlFactoryTest extends TestCase
2020
{
21-
/**
22-
* @var SelectFactory|MockObject
23-
*/
24-
private $selectFactoryMock;
25-
26-
/**
27-
* @var LoggerInterface|MockObject
28-
*/
29-
private $loggerMock;
30-
3121
/**
3222
* @var ObjectManagerInterface|MockObject
3323
*/
@@ -53,16 +43,24 @@ protected function setUp(): void
5343
/**
5444
* @param array $objectManagerArguments
5545
* @param array $config
56-
* @param LoggerInterface|null $logger
57-
* @param SelectFactory|null $selectFactory
46+
* @param string|null $loggerMockPlaceholder
47+
* @param string|null $selectFactoryMockPlaceholder
5848
* @dataProvider createDataProvider
5949
*/
6050
public function testCreate(
6151
array $objectManagerArguments,
6252
array $config,
63-
LoggerInterface $logger = null,
64-
SelectFactory $selectFactory = null
53+
?string $loggerMockPlaceholder = null,
54+
?string $selectFactoryMockPlaceholder = null
6555
) {
56+
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
57+
$selectFactoryMock = $this->createMock(SelectFactory::class);
58+
if ($loggerMockPlaceholder === 'loggerMock') {
59+
$objectManagerArguments['logger'] = $loggerMock;
60+
}
61+
if ($selectFactoryMockPlaceholder === 'selectFactoryMock') {
62+
$objectManagerArguments['selectFactory'] = $selectFactoryMock;
63+
}
6664
$this->objectManagerMock->expects($this->once())
6765
->method('create')
6866
->with(
@@ -72,46 +70,44 @@ public function testCreate(
7270
$this->mysqlFactory->create(
7371
Mysql::class,
7472
$config,
75-
$logger,
76-
$selectFactory
73+
$loggerMockPlaceholder === 'loggerMock' ? $loggerMock : null,
74+
$selectFactoryMockPlaceholder === 'selectFactoryMock' ? $selectFactoryMock : null
7775
);
7876
}
7977

8078
/**
8179
* @return array
8280
*/
83-
public function createDataProvider()
81+
public static function createDataProvider()
8482
{
85-
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
86-
$this->selectFactoryMock = $this->createMock(SelectFactory::class);
8783
return [
8884
[
8985
[
9086
'config' => ['foo' => 'bar'],
91-
'logger' => $this->loggerMock,
92-
'selectFactory' => $this->selectFactoryMock
87+
'logger' => 'loggerMock',
88+
'selectFactory' => 'selectFactoryMock'
9389
],
9490
['foo' => 'bar'],
95-
$this->loggerMock,
96-
$this->selectFactoryMock
91+
'loggerMock',
92+
'selectFactoryMock'
9793
],
9894
[
9995
[
10096
'config' => ['foo' => 'bar'],
101-
'logger' => $this->loggerMock
97+
'logger' => 'loggerMock'
10298
],
10399
['foo' => 'bar'],
104-
$this->loggerMock,
100+
'loggerMock',
105101
null
106102
],
107103
[
108104
[
109105
'config' => ['foo' => 'bar'],
110-
'selectFactory' => $this->selectFactoryMock
106+
'selectFactory' => 'selectFactoryMock'
111107
],
112108
['foo' => 'bar'],
113109
null,
114-
$this->selectFactoryMock
110+
'selectFactoryMock'
115111
],
116112
];
117113
}

lib/internal/Magento/Framework/Data/Test/Unit/AbstractCriteriaTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public function testAddField($field, $alias, array $result)
6161
*/
6262
public function testAddFilter($name, $field, $condition, $type, array $result)
6363
{
64+
$objectManager = new ObjectManager($this);
65+
$result = [
66+
'test-filter-name' => $objectManager->getObject(
67+
DataObject::class,
68+
['data' => $result]
69+
),
70+
];
6471
$this->criteria->addFilter($name, $field, $condition, $type);
6572
$this->assertEquals($result, $this->criteria->toArray()[CriteriaInterface::PART_FILTERS]['list']);
6673
}
@@ -368,27 +375,19 @@ public static function dataProviderAddOrder()
368375
*
369376
* @return array
370377
*/
371-
public function dataProviderAddFilter()
378+
public static function dataProviderAddFilter()
372379
{
373-
$objectManager = new ObjectManager($this);
374380
return [
375381
[
376382
'name' => 'test-filter-name',
377383
'field' => 'test-field-name',
378384
'condition' => 'test-condition',
379385
'type' => 'test-type',
380386
'result' => [
381-
'test-filter-name' => $objectManager->getObject(
382-
DataObject::class,
383-
[
384-
'data' => [
385-
'name' => 'test-filter-name',
386-
'field' => 'test-field-name',
387-
'condition' => 'test-condition',
388-
'type' => 'test-type',
389-
]
390-
]
391-
),
387+
'name' => 'test-filter-name',
388+
'field' => 'test-field-name',
389+
'condition' => 'test-condition',
390+
'type' => 'test-type',
392391
],
393392
]
394393
];

lib/internal/Magento/Framework/Encryption/Test/Unit/Adapter/McryptTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function getRandomString(int $length): string
4747
return substr($result, -$length);
4848
}
4949

50-
private function requireCipherInfo()
50+
private static function requireCipherInfo()
5151
{
5252
$filename = __DIR__ . '/../Crypt/_files/_cipher_info.php';
5353

@@ -62,9 +62,9 @@ private function requireCipherInfo()
6262
*
6363
* @return int
6464
*/
65-
private function getKeySize(string $cipherName, string $modeName): int
65+
private static function getKeySize(string $cipherName, string $modeName): int
6666
{
67-
$this->requireCipherInfo();
67+
self::requireCipherInfo();
6868
return self::$cipherInfo[$cipherName][$modeName]['key_size'];
6969
}
7070

@@ -74,9 +74,9 @@ private function getKeySize(string $cipherName, string $modeName): int
7474
*
7575
* @return int
7676
*/
77-
private function getInitVectorSize(string $cipherName, string $modeName): int
77+
private static function getInitVectorSize(string $cipherName, string $modeName): int
7878
{
79-
$this->requireCipherInfo();
79+
self::requireCipherInfo();
8080
return self::$cipherInfo[$cipherName][$modeName]['iv_size'];
8181
}
8282

@@ -113,16 +113,16 @@ public function testConstructor(string $cipher, string $mode)
113113
/**
114114
* @return array
115115
*/
116-
public function getConstructorExceptionData(): array
116+
public static function getConstructorExceptionData(): array
117117
{
118118
$key = substr(__CLASS__, -32, 32);
119119
$result = [];
120120
foreach (self::SUPPORTED_CIPHER_MODE_COMBINATIONS as $cipher => $modes) {
121121
/** @var array $modes */
122122
foreach ($modes as $mode) {
123-
$tooLongKey = str_repeat('-', $this->getKeySize($cipher, $mode) + 1);
124-
$tooShortInitVector = str_repeat('-', $this->getInitVectorSize($cipher, $mode) - 1);
125-
$tooLongInitVector = str_repeat('-', $this->getInitVectorSize($cipher, $mode) + 1);
123+
$tooLongKey = str_repeat('-', self::getKeySize($cipher, $mode) + 1);
124+
$tooShortInitVector = str_repeat('-', self::getInitVectorSize($cipher, $mode) - 1);
125+
$tooLongInitVector = str_repeat('-', self::getInitVectorSize($cipher, $mode) + 1);
126126
$result['tooLongKey-' . $cipher . '-' . $mode . '-false'] = [$tooLongKey, $cipher, $mode, null];
127127
$keyPrefix = 'key-' . $cipher . '-' . $mode;
128128
$result[$keyPrefix . '-tooShortInitVector'] = [$key, $cipher, $mode, $tooShortInitVector];

lib/internal/Magento/Framework/Encryption/Test/Unit/CryptTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function _getRandomString($length)
4343
return substr($result, -$length);
4444
}
4545

46-
protected function _requireCipherInfo()
46+
protected static function _requireCipherInfo()
4747
{
4848
$filename = __DIR__ . '/Crypt/_files/_cipher_info.php';
4949

@@ -57,9 +57,9 @@ protected function _requireCipherInfo()
5757
* @param $modeName
5858
* @return mixed
5959
*/
60-
protected function _getKeySize($cipherName, $modeName)
60+
protected static function _getKeySize($cipherName, $modeName)
6161
{
62-
$this->_requireCipherInfo();
62+
self::_requireCipherInfo();
6363
return self::$_cipherInfo[$cipherName][$modeName]['key_size'];
6464
}
6565

@@ -68,9 +68,9 @@ protected function _getKeySize($cipherName, $modeName)
6868
* @param $modeName
6969
* @return mixed
7070
*/
71-
protected function _getInitVectorSize($cipherName, $modeName)
71+
protected static function _getInitVectorSize($cipherName, $modeName)
7272
{
73-
$this->_requireCipherInfo();
73+
self::_requireCipherInfo();
7474
return self::$_cipherInfo[$cipherName][$modeName]['iv_size'];
7575
}
7676

@@ -107,16 +107,16 @@ public function testConstructor($cipher, $mode)
107107
/**
108108
* @return array
109109
*/
110-
public function getConstructorExceptionData()
110+
public static function getConstructorExceptionData()
111111
{
112112
$key = substr(__CLASS__, -32, 32);
113113
$result = [];
114114
foreach (self::SUPPORTED_CIPHER_MODE_COMBINATIONS as $cipher => $modes) {
115115
/** @var array $modes */
116116
foreach ($modes as $mode) {
117-
$tooLongKey = str_repeat('-', $this->_getKeySize($cipher, $mode) + 1);
118-
$tooShortInitVector = str_repeat('-', $this->_getInitVectorSize($cipher, $mode) - 1);
119-
$tooLongInitVector = str_repeat('-', $this->_getInitVectorSize($cipher, $mode) + 1);
117+
$tooLongKey = str_repeat('-', self::_getKeySize($cipher, $mode) + 1);
118+
$tooShortInitVector = str_repeat('-', self::_getInitVectorSize($cipher, $mode) - 1);
119+
$tooLongInitVector = str_repeat('-', self::_getInitVectorSize($cipher, $mode) + 1);
120120
$result['tooLongKey-' . $cipher . '-' . $mode . '-false'] = [$tooLongKey, $cipher, $mode, false];
121121
$keyPrefix = 'key-' . $cipher . '-' . $mode;
122122
$result[$keyPrefix . '-tooShortInitVector'] = [$key, $cipher, $mode, $tooShortInitVector];
@@ -148,7 +148,7 @@ public function testConstructorDefaults()
148148
/**
149149
* @return mixed
150150
*/
151-
public function getCryptData()
151+
public static function getCryptData()
152152
{
153153
$fixturesFilename = __DIR__ . '/Crypt/_files/_crypt_fixtures.php';
154154

lib/internal/Magento/Framework/Profiler/Test/Unit/Driver/FactoryTest.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php declare(strict_types=1);
22
/**
3-
* Test class for \Magento\Framework\Profiler\Driver\Factory
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
5+
*
6+
* Test class for \Magento\Framework\Profiler\Driver\Factory
77
*/
88
namespace Magento\Framework\Profiler\Test\Unit\Driver;
99

@@ -60,6 +60,12 @@ public function testDefaultConstructor()
6060
*/
6161
public function testCreate($config, $expectedClass)
6262
{
63+
if (isset($config['type']) && is_callable($config['type'])) {
64+
$config['type'] = $config['type']($this);
65+
}
66+
if (is_callable($expectedClass)) {
67+
$expectedClass = $expectedClass($this);
68+
}
6369
$driver = $this->_factory->create($config);
6470
$this->assertInstanceOf($expectedClass, $driver);
6571
$this->assertInstanceOf(DriverInterface::class, $driver);
@@ -68,7 +74,25 @@ public function testCreate($config, $expectedClass)
6874
/**
6975
* @return array
7076
*/
71-
public function createDataProvider()
77+
public static function createDataProvider()
78+
{
79+
return [
80+
'Prefix and concrete type' => [
81+
['type' => 'test'],
82+
static fn (self $testCase) => $testCase->getMockForDriverClass()['testDriverClass']
83+
],
84+
'Prefix and default type' => [
85+
[],
86+
static fn (self $testCase) => $testCase->getMockForDriverClass()['defaultDriverClass']
87+
],
88+
'Concrete class' => [
89+
['type' => static fn (self $testCase) => $testCase->getMockForDriverClass()['testDriverClass']],
90+
static fn (self $testCase) => $testCase->getMockForDriverClass()['testDriverClass']
91+
]
92+
];
93+
}
94+
95+
public function getMockForDriverClass()
7296
{
7397
$defaultDriverClassMock = $this->getMockForAbstractClass(
7498
DriverInterface::class,
@@ -95,9 +119,8 @@ public function createDataProvider()
95119
$testDriverClass = get_class($testDriverClassMock);
96120

97121
return [
98-
'Prefix and concrete type' => [['type' => 'test'], $testDriverClass],
99-
'Prefix and default type' => [[], $defaultDriverClass],
100-
'Concrete class' => [['type' => $testDriverClass], $testDriverClass]
122+
'defaultDriverClass' => $defaultDriverClass,
123+
'testDriverClass' => $testDriverClass
101124
];
102125
}
103126

0 commit comments

Comments
 (0)