Skip to content

Commit eee2621

Browse files
Merge remote-tracking branch 'origin/Arrows-AC-15048' into AC-15049-Security_Authentication
2 parents ec1164c + 1f235a0 commit eee2621

File tree

119 files changed

+1109
-1473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1109
-1473
lines changed

app/code/Magento/Elasticsearch/Test/Unit/ElasticAdapter/Model/Adapter/FieldMapper/Product/FieldProvider/FieldIndex/IndexResolverTest.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
as FieldTypeResolver;
1717
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1818
use PHPUnit\Framework\TestCase;
19+
use PHPUnit\Framework\Attributes\DataProvider;
1920

2021
/**
2122
* @SuppressWarnings(PHPMD)
@@ -49,18 +50,9 @@ class IndexResolverTest extends TestCase
4950
*/
5051
protected function setUp(): void
5152
{
52-
$this->converter = $this->getMockBuilder(ConverterInterface::class)
53-
->disableOriginalConstructor()
54-
->onlyMethods(['convert'])
55-
->getMockForAbstractClass();
56-
$this->fieldTypeConverter = $this->getMockBuilder(FieldTypeConverterInterface::class)
57-
->disableOriginalConstructor()
58-
->onlyMethods(['convert'])
59-
->getMockForAbstractClass();
60-
$this->fieldTypeResolver = $this->getMockBuilder(FieldTypeResolver::class)
61-
->disableOriginalConstructor()
62-
->onlyMethods(['getFieldType'])
63-
->getMockForAbstractClass();
53+
$this->converter = $this->createPartialMock(ConverterInterface::class, ['convert']);
54+
$this->fieldTypeConverter = $this->createPartialMock(FieldTypeConverterInterface::class, ['convert']);
55+
$this->fieldTypeResolver = $this->createPartialMock(FieldTypeResolver::class, ['getFieldType']);
6456
$objectManager = new ObjectManagerHelper($this);
6557

6658
$this->resolver = $objectManager->getObject(
@@ -74,7 +66,6 @@ protected function setUp(): void
7466
}
7567

7668
/**
77-
* @dataProvider getFieldIndexProvider
7869
* @param $isSearchable
7970
* @param $isAlwaysIndexable
8071
* @param $isComplexType
@@ -86,6 +77,7 @@ protected function setUp(): void
8677
* @param $expected
8778
* @return void
8879
*/
80+
#[DataProvider('getFieldIndexProvider')]
8981
public function testGetFieldName(
9082
$isSearchable,
9183
$isAlwaysIndexable,

app/code/Magento/Elasticsearch/Test/Unit/ElasticAdapter/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Resolver/IntegerTypeTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
as FieldTypeConverterInterface;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1616
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718

1819
/**
1920
* @SuppressWarnings(PHPMD)
@@ -37,10 +38,7 @@ class IntegerTypeTest extends TestCase
3738
*/
3839
protected function setUp(): void
3940
{
40-
$this->fieldTypeConverter = $this->getMockBuilder(FieldTypeConverterInterface::class)
41-
->disableOriginalConstructor()
42-
->onlyMethods(['convert'])
43-
->getMockForAbstractClass();
41+
$this->fieldTypeConverter = $this->createPartialMock(FieldTypeConverterInterface::class, ['convert']);
4442

4543
$objectManager = new ObjectManagerHelper($this);
4644

@@ -53,13 +51,13 @@ protected function setUp(): void
5351
}
5452

5553
/**
56-
* @dataProvider getFieldTypeProvider
5754
* @param string $attributeCode
5855
* @param bool $isIntegerType
5956
* @param bool $isBooleanType
6057
* @param string $expected
6158
* @return void
6259
*/
60+
#[DataProvider('getFieldTypeProvider')]
6361
public function testGetFieldType(
6462
string $attributeCode,
6563
bool $isIntegerType,

app/code/Magento/Elasticsearch/Test/Unit/ElasticAdapter/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Resolver/KeywordTypeTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
as FieldTypeConverterInterface;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1616
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718

1819
/**
1920
* @SuppressWarnings(PHPMD)
@@ -37,10 +38,7 @@ class KeywordTypeTest extends TestCase
3738
*/
3839
protected function setUp(): void
3940
{
40-
$this->fieldTypeConverter = $this->getMockBuilder(FieldTypeConverterInterface::class)
41-
->disableOriginalConstructor()
42-
->onlyMethods(['convert'])
43-
->getMockForAbstractClass();
41+
$this->fieldTypeConverter = $this->createPartialMock(FieldTypeConverterInterface::class, ['convert']);
4442

4543
$objectManager = new ObjectManagerHelper($this);
4644

@@ -53,7 +51,6 @@ protected function setUp(): void
5351
}
5452

5553
/**
56-
* @dataProvider getFieldTypeProvider
5754
* @param bool $isComplexType
5855
* @param bool $isSearchable
5956
* @param bool $isAlwaysIndexable
@@ -62,6 +59,7 @@ protected function setUp(): void
6259
* @param string $expected
6360
* @return void
6461
*/
62+
#[DataProvider('getFieldTypeProvider')]
6563
public function testGetFieldType(
6664
bool $isComplexType,
6765
bool $isSearchable,

app/code/Magento/Elasticsearch/Test/Unit/ElasticAdapter/SearchAdapter/Query/BuilderTest.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,9 @@ protected function setUp(): void
9090
->onlyMethods(['build'])
9191
->disableOriginalConstructor()
9292
->getMock();
93-
$this->request = $this->getMockBuilder(RequestInterface::class)
94-
->disableOriginalConstructor()
95-
->getMockForAbstractClass();
96-
$this->scopeResolver = $this->getMockForAbstractClass(
97-
ScopeResolverInterface::class,
98-
[],
99-
'',
100-
false
101-
);
102-
$this->scopeInterface = $this->getMockForAbstractClass(
103-
ScopeInterface::class,
104-
[],
105-
'',
106-
false
107-
);
93+
$this->request = $this->createMock(RequestInterface::class);
94+
$this->scopeResolver = $this->createMock(ScopeResolverInterface::class);
95+
$this->scopeInterface = $this->createMock(ScopeInterface::class);
10896

10997
$this->model = new Builder(
11098
$this->clientConfig,

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/BatchDataMapper/DataMapperFactoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ class DataMapperFactoryTest extends TestCase
4040
*/
4141
protected function setUp(): void
4242
{
43-
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
44-
->disableOriginalConstructor()
45-
->getMockForAbstractClass();
43+
$this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
4644
$this->dataMappers = [
4745
'product' => 'productDataMapper',
4846
];
@@ -96,7 +94,7 @@ public function testCreate()
9694
{
9795
$this->objectManagerMock->expects($this->once())
9896
->method('create')
99-
->willReturn($this->getMockForAbstractClass(BatchDataMapperInterface::class));
97+
->willReturn($this->createMock(BatchDataMapperInterface::class));
10098
$this->assertInstanceOf(BatchDataMapperInterface::class, $this->model->create('product'));
10199
}
102100
}

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/BatchDataMapper/DataMapperResolverTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ protected function setUp(): void
3939
$this->dataMapperFactoryMock = $this->getMockBuilder(DataMapperFactory::class)
4040
->disableOriginalConstructor()
4141
->getMock();
42-
$this->dataMapperEntity = $this->getMockBuilder(BatchDataMapperInterface::class)
43-
->disableOriginalConstructor()
44-
->getMockForAbstractClass();
42+
$this->dataMapperEntity = $this->createMock(BatchDataMapperInterface::class);
4543
$this->model = (new ObjectManagerHelper($this))->getObject(
4644
DataMapperResolver::class,
4745
[

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/BatchDataMapper/ProductDataMapperTest.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2020
use PHPUnit\Framework\MockObject\MockObject;
2121
use PHPUnit\Framework\TestCase;
22+
use PHPUnit\Framework\Attributes\DataProvider as DataProviderAttribute;
2223

2324
/**
2425
* Unit tests for \Magento\Elasticsearch\Model\Adapter\BatchDataMapper\ProductDataMapper class.
@@ -67,19 +68,20 @@ class ProductDataMapperTest extends TestCase
6768
*/
6869
protected function setUp(): void
6970
{
70-
$this->builderMock = $this->createTestProxy(Builder::class);
71-
$this->fieldMapperMock = $this->getMockForAbstractClass(FieldMapperInterface::class);
71+
$objectManager = new ObjectManagerHelper($this);
72+
$this->builderMock = $objectManager->getObject(Builder::class);
73+
74+
$this->fieldMapperMock = $this->createMock(FieldMapperInterface::class);
7275
$this->dataProvider = $this->createMock(DataProvider::class);
7376
$this->attribute = $this->createMock(Attribute::class);
74-
$this->additionalFieldsProvider = $this->getMockForAbstractClass(AdditionalFieldsProviderInterface::class);
77+
$this->additionalFieldsProvider = $this->createMock(AdditionalFieldsProviderInterface::class);
7578
$this->dateFieldTypeMock = $this->createMock(Date::class);
7679
$filterableAttributeTypes = [
7780
'boolean' => 'boolean',
7881
'multiselect' => 'multiselect',
7982
'select' => 'select',
8083
];
8184

82-
$objectManager = new ObjectManagerHelper($this);
8385
$this->model = $objectManager->getObject(
8486
ProductDataMapper::class,
8587
[
@@ -101,19 +103,7 @@ public function testGetMapAdditionalFieldsOnly()
101103
$storeId = 1;
102104
$productId = 42;
103105
$additionalFields = ['some data'];
104-
$this->builderMock->expects($this->once())
105-
->method('addField')
106-
->with('store_id', $storeId);
107-
108-
$this->builderMock->expects($this->any())
109-
->method('addFields')
110-
->willReturnCallback(fn($param) => match ([$param]) {
111-
[$additionalFields] => $this->builderMock,
112-
});
113106

114-
$this->builderMock->expects($this->any())
115-
->method('build')
116-
->willReturn([]);
117107
$this->additionalFieldsProvider->expects($this->once())
118108
->method('getFields')
119109
->with([$productId], $storeId)
@@ -130,8 +120,6 @@ public function testGetMapEmptyData()
130120
{
131121
$storeId = 1;
132122

133-
$this->builderMock->expects($this->never())->method('addField');
134-
$this->builderMock->expects($this->never())->method('build');
135123
$this->additionalFieldsProvider->expects($this->once())
136124
->method('getFields')
137125
->with([], $storeId)
@@ -146,8 +134,8 @@ public function testGetMapEmptyData()
146134
* @param array $attributeData
147135
* @param array|string $attributeValue
148136
* @param array $returnAttributeData
149-
* @dataProvider mapProvider
150137
*/
138+
#[DataProviderAttribute('mapProvider')]
151139
public function testGetMap(int $productId, array $attributeData, $attributeValue, array $returnAttributeData)
152140
{
153141
$storeId = 1;
@@ -175,7 +163,6 @@ public function testGetMap(int $productId, array $attributeData, $attributeValue
175163

176164
/**
177165
* @return void
178-
*/
179166
public function testGetMapWithOptions()
180167
{
181168
$storeId = 1;
@@ -223,7 +210,7 @@ private function getAttribute(array $attributeData): MockObject
223210
$sourceMock->method('getAllOptions')->willReturn($attributeData['options'] ?? []);
224211
$options = [];
225212
foreach ($attributeData['options'] as $option) {
226-
$optionMock = $this->getMockForAbstractClass(AttributeOptionInterface::class);
213+
$optionMock = $this->createMock(AttributeOptionInterface::class);
227214
$optionMock->method('getValue')->willReturn($option['value']);
228215
$optionMock->method('getLabel')->willReturn($option['label']);
229216
$options[] = $optionMock;

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/ElasticsearchTest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
use Elasticsearch\Client;
1111
use Elasticsearch\Namespaces\IndicesNamespace;
12+
use Elasticsearch\ClientBuilder;
1213
use Exception;
1314
use Magento\AdvancedSearch\Model\Client\ClientInterface as ElasticsearchClient;
1415
use Magento\AdvancedSearch\Model\Client\ClientOptionsInterface;
16+
use Magento\Elasticsearch8\Model\Client\Elasticsearch;
1517
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1618
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
17-
use Magento\Elasticsearch7\Model\Client\Elasticsearch;
1819
use Magento\Elasticsearch\Model\Adapter\BatchDataMapperInterface;
1920
use Magento\Elasticsearch\Model\Adapter\Elasticsearch as ElasticsearchAdapter;
2021
use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface;
@@ -76,7 +77,7 @@ class ElasticsearchTest extends TestCase
7677
protected $logger;
7778

7879
/**
79-
* @var ElasticsearchClient|MockObject
80+
* @var Elasticsearch|MockObject
8081
*/
8182
protected $client;
8283

@@ -111,7 +112,7 @@ class ElasticsearchTest extends TestCase
111112
*/
112113
protected function setUp(): void
113114
{
114-
if (!class_exists(\Elasticsearch\ClientBuilder::class)) { /** @phpstan-ignore-line */
115+
if (!class_exists(ClientBuilder::class)) {
115116
$this->markTestSkipped('AC-6597: Skipped as Elasticsearch 8 is configured');
116117
}
117118

@@ -122,21 +123,21 @@ protected function setUp(): void
122123
->getMock();
123124
$this->fieldMapper = $this->getMockBuilder(FieldMapperInterface::class)
124125
->disableOriginalConstructor()
125-
->getMockForAbstractClass();
126+
->getMock();
126127
$this->clientConfig = $this->getMockBuilder(Config::class)
127128
->disableOriginalConstructor()
128129
->onlyMethods(['getIndexPrefix', 'getEntityType'])->getMock();
129130
$this->indexBuilder = $this->getMockBuilder(BuilderInterface::class)
130131
->disableOriginalConstructor()
131-
->getMockForAbstractClass();
132+
->getMock();
132133
$this->logger = $this->getMockBuilder(LoggerInterface::class)
133134
->disableOriginalConstructor()
134-
->getMockForAbstractClass();
135-
$elasticsearchClientMock = $this->getMockBuilder(Client::class)
135+
->getMock();
136+
$elasticsearchClientMock = $this->getMockBuilder(Client::class) // @phpstan-ignore-line
136137
->onlyMethods(['indices', 'ping', 'bulk', 'search'])
137138
->disableOriginalConstructor()
138139
->getMock();
139-
$indicesMock = $this->getMockBuilder(IndicesNamespace::class)
140+
$indicesMock = $this->getMockBuilder(IndicesNamespace::class) // @phpstan-ignore-line
140141
->onlyMethods(
141142
[
142143
'exists',
@@ -198,10 +199,10 @@ protected function setUp(): void
198199
->getMock();
199200
$this->batchDocumentDataMapper = $this->getMockBuilder(BatchDataMapperInterface::class)
200201
->disableOriginalConstructor()
201-
->getMockForAbstractClass();
202+
->getMock();
202203
$this->productAttributeRepository = $this->getMockBuilder(ProductAttributeRepositoryInterface::class)
203204
->disableOriginalConstructor()
204-
->getMockForAbstractClass();
205+
->getMock();
205206
$this->staticFieldProvider = $this->getMockBuilder(StaticField::class)
206207
->disableOriginalConstructor()
207208
->getMock();
@@ -629,7 +630,7 @@ public function testUpdateIndexMappingWithAliasDefinition(): void
629630

630631
$attribute = $this->getMockBuilder(AbstractAttribute::class)
631632
->disableOriginalConstructor()
632-
->getMockForAbstractClass();
633+
->getMock();
633634

634635
$this->productAttributeRepository->expects($this->once())
635636
->method('get')

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/AddDefaultSearchFieldTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Elasticsearch\Model\Adapter\FieldMapper\AddDefaultSearchField;
1111
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1212
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
/**
1516
* Test mapping preprocessor AddDefaultSearchField
@@ -19,10 +20,10 @@ class AddDefaultSearchFieldTest extends TestCase
1920
/**
2021
* Test default search field "_search" should be prepended and overwrite if exist.
2122
*
22-
* @dataProvider processDataProvider
2323
* @param array $mappingBefore
2424
* @param array $mappingAfter
2525
*/
26+
#[DataProvider('processDataProvider')]
2627
public function testProcess(array $mappingBefore, array $mappingAfter)
2728
{
2829
$objectManager = new ObjectManager($this);

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/CopySearchableFieldsToSearchFieldTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Elasticsearch\Model\Adapter\FieldMapper\CopySearchableFieldsToSearchField;
1111
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1212
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
/**
1516
* Test mapping preprocessor CopySearchableFieldsToSearchField
@@ -19,10 +20,10 @@ class CopySearchableFieldsToSearchFieldTest extends TestCase
1920
/**
2021
* Test "copy_to" parameter should be added to searchable fields.
2122
*
22-
* @dataProvider processDataProvider
2323
* @param array $mappingBefore
2424
* @param array $mappingAfter
2525
*/
26+
#[DataProvider('processDataProvider')]
2627
public function testProcess(array $mappingBefore, array $mappingAfter)
2728
{
2829
$objectManager = new ObjectManager($this);

0 commit comments

Comments
 (0)