Skip to content

Commit d39bbb6

Browse files
author
Oleksii Korshenko
authored
MAGETWO-82007: MAGETWO-81245: All arguments for mapping methods must be compatible with call_user_func_array #11503
2 parents cc7b5c2 + 7e36bd7 commit d39bbb6

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteria.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StockItemCriteria extends AbstractCriteria implements \Magento\CatalogInve
2121
public function __construct($mapper = '')
2222
{
2323
$this->mapperInterfaceName = $mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\Item\StockItemCriteriaMapper::class;
24-
$this->data['initial_condition'] = true;
24+
$this->data['initial_condition'] = [true];
2525
}
2626

2727
/**
@@ -38,7 +38,7 @@ public function setStockStatus($storeId = null)
3838
*/
3939
public function setStockFilter($stock)
4040
{
41-
$this->data['stock_filter'] = $stock;
41+
$this->data['stock_filter'] = [$stock];
4242
return true;
4343
}
4444

@@ -47,7 +47,7 @@ public function setStockFilter($stock)
4747
*/
4848
public function setScopeFilter($scope)
4949
{
50-
$this->data['website_filter'] = $scope;
50+
$this->data['website_filter'] = [$scope];
5151
return true;
5252
}
5353

@@ -56,7 +56,7 @@ public function setScopeFilter($scope)
5656
*/
5757
public function setProductsFilter($products)
5858
{
59-
$this->data['products_filter'] = $products;
59+
$this->data['products_filter'] = [$products];
6060
return true;
6161
}
6262

@@ -65,7 +65,7 @@ public function setProductsFilter($products)
6565
*/
6666
public function setManagedFilter($isStockManagedInConfig)
6767
{
68-
$this->data['managed_filter'] = $isStockManagedInConfig;
68+
$this->data['managed_filter'] = [$isStockManagedInConfig];
6969
return true;
7070
}
7171

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status/StockStatusCriteria.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ class StockStatusCriteria extends AbstractCriteria implements \Magento\CatalogIn
2121
public function __construct($mapper = '')
2222
{
2323
$this->mapperInterfaceName = $mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\Status\StockStatusCriteriaMapper::class;
24-
$this->data['initial_condition'] = true;
24+
$this->data['initial_condition'] = [true];
2525
}
2626

2727
/**
2828
* @inheritdoc
2929
*/
3030
public function setScopeFilter($scope)
3131
{
32-
$this->data['website_filter'] = $scope;
32+
$this->data['website_filter'] = [$scope];
3333
}
3434

3535
/**
3636
* @inheritdoc
3737
*/
3838
public function setProductsFilter($products)
3939
{
40-
$this->data['products_filter'] = $products;
40+
$this->data['products_filter'] = [$products];
4141
}
4242

4343
/**
4444
* @inheritdoc
4545
*/
4646
public function setQtyFilter($qty)
4747
{
48-
$this->data['qty_filter'] = $qty;
48+
$this->data['qty_filter'] = [$qty];
4949
}
5050

5151
/**

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/StockCriteria.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public function __construct($mapper = '')
1919
{
2020
$this->mapperInterfaceName =
2121
$mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\StockCriteriaMapper::class;
22-
$this->data['initial_condition'] = true;
22+
$this->data['initial_condition'] = [true];
2323
}
2424

2525
/**
2626
* @inheritdoc
2727
*/
2828
public function setScopeFilter($scope)
2929
{
30-
$this->data['website_filter'] = $scope;
30+
$this->data['website_filter'] = [$scope];
3131
return true;
3232
}
3333

lib/internal/Magento/Framework/DB/AbstractMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function map(CriteriaInterface $criteria)
124124
$mapperMethod = 'map' . $camelCaseKey;
125125
if (method_exists($this, $mapperMethod)) {
126126
if (!is_array($value)) {
127-
$value = [$value];
127+
throw new \InvalidArgumentException('Wrong type of argument, expecting array for '. $mapperMethod);
128128
}
129129
call_user_func_array([$this, $mapperMethod], $value);
130130
}

lib/internal/Magento/Framework/DB/Test/Unit/AbstractMapperTest.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,47 @@ public function testMap(array $mapperMethods, array $criteriaParts)
141141
$this->assertEquals($this->selectMock, $mapper->map($criteriaMock));
142142
}
143143

144+
public function testMapException()
145+
{
146+
$mapperMethods = [
147+
'my-test-value1' => 'mapMyMapperMethodOne'
148+
];
149+
150+
$criteriaParts = [
151+
'my_mapper_method_one' => 'my-test-value1'
152+
];
153+
/** @var \Magento\Framework\DB\AbstractMapper|\PHPUnit_Framework_MockObject_MockObject $mapper */
154+
$mapper = $this->getMockForAbstractClass(
155+
\Magento\Framework\DB\AbstractMapper::class,
156+
[
157+
'logger' => $this->loggerMock,
158+
'fetchStrategy' => $this->fetchStrategyMock,
159+
'objectFactory' => $this->objectFactoryMock,
160+
'mapperFactory' => $this->mapperFactoryMock,
161+
'select' => $this->selectMock
162+
],
163+
'',
164+
true,
165+
true,
166+
true,
167+
$mapperMethods
168+
);
169+
$criteriaMock = $this->getMockForAbstractClass(
170+
\Magento\Framework\Api\CriteriaInterface::class,
171+
[],
172+
'',
173+
false,
174+
true,
175+
true,
176+
['toArray']
177+
);
178+
$criteriaMock->expects($this->once())
179+
->method('toArray')
180+
->will($this->returnValue($criteriaParts));
181+
$this->expectException(\InvalidArgumentException::class);
182+
$mapper->map($criteriaMock);
183+
}
184+
144185
/**
145186
* Run test addExpressionFieldToSelect method
146187
*
@@ -254,8 +295,8 @@ public function dataProviderMap()
254295
'my-test-value2' => 'mapMyMapperMethodTwo',
255296
],
256297
'criteriaParts' => [
257-
'my_mapper_method_one' => 'my-test-value1',
258-
'my_mapper_method_two' => 'my-test-value2',
298+
'my_mapper_method_one' => ['my-test-value1'],
299+
'my_mapper_method_two' => ['my-test-value2'],
259300
],
260301
]
261302
];

0 commit comments

Comments
 (0)