Skip to content

Commit d35749c

Browse files
author
Oleksii Korshenko
committed
MAGETWO-82007: MAGETWO-81245: All arguments for mapping methods must be compatible with call_user_func_array #11503
- Merge Pull Request #11503 from kirmorozov/magento2:MAGETWO-81245-develop - Merged commits: 1. 4122d76
2 parents 2321610 + 4122d76 commit d35749c

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-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: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,49 @@ public function testMap(array $mapperMethods, array $criteriaParts)
141141
$this->assertEquals($this->selectMock, $mapper->map($criteriaMock));
142142
}
143143

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

0 commit comments

Comments
 (0)