Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAGETWO-81245: All arguments for mapping methods must be compatible with call_user_func_array #11503

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StockItemCriteria extends AbstractCriteria implements \Magento\CatalogInve
public function __construct($mapper = '')
{
$this->mapperInterfaceName = $mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\Item\StockItemCriteriaMapper::class;
$this->data['initial_condition'] = true;
$this->data['initial_condition'] = [true];
}

/**
Expand All @@ -38,7 +38,7 @@ public function setStockStatus($storeId = null)
*/
public function setStockFilter($stock)
{
$this->data['stock_filter'] = $stock;
$this->data['stock_filter'] = [$stock];
return true;
}

Expand All @@ -47,7 +47,7 @@ public function setStockFilter($stock)
*/
public function setScopeFilter($scope)
{
$this->data['website_filter'] = $scope;
$this->data['website_filter'] = [$scope];
return true;
}

Expand All @@ -56,7 +56,7 @@ public function setScopeFilter($scope)
*/
public function setProductsFilter($products)
{
$this->data['products_filter'] = $products;
$this->data['products_filter'] = [$products];
return true;
}

Expand All @@ -65,7 +65,7 @@ public function setProductsFilter($products)
*/
public function setManagedFilter($isStockManagedInConfig)
{
$this->data['managed_filter'] = $isStockManagedInConfig;
$this->data['managed_filter'] = [$isStockManagedInConfig];
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ class StockStatusCriteria extends AbstractCriteria implements \Magento\CatalogIn
public function __construct($mapper = '')
{
$this->mapperInterfaceName = $mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\Status\StockStatusCriteriaMapper::class;
$this->data['initial_condition'] = true;
$this->data['initial_condition'] = [true];
}

/**
* @inheritdoc
*/
public function setScopeFilter($scope)
{
$this->data['website_filter'] = $scope;
$this->data['website_filter'] = [$scope];
}

/**
* @inheritdoc
*/
public function setProductsFilter($products)
{
$this->data['products_filter'] = $products;
$this->data['products_filter'] = [$products];
}

/**
* @inheritdoc
*/
public function setQtyFilter($qty)
{
$this->data['qty_filter'] = $qty;
$this->data['qty_filter'] = [$qty];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function __construct($mapper = '')
{
$this->mapperInterfaceName =
$mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\StockCriteriaMapper::class;
$this->data['initial_condition'] = true;
$this->data['initial_condition'] = [true];
}

/**
* @inheritdoc
*/
public function setScopeFilter($scope)
{
$this->data['website_filter'] = $scope;
$this->data['website_filter'] = [$scope];
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/DB/AbstractMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function map(CriteriaInterface $criteria)
$mapperMethod = 'map' . $camelCaseKey;
if (method_exists($this, $mapperMethod)) {
if (!is_array($value)) {
$value = [$value];
throw new \InvalidArgumentException('Wrong type of argument, expecting array for '. $mapperMethod);
}
call_user_func_array([$this, $mapperMethod], $value);
}
Expand Down
47 changes: 45 additions & 2 deletions lib/internal/Magento/Framework/DB/Test/Unit/AbstractMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,49 @@ public function testMap(array $mapperMethods, array $criteriaParts)
$this->assertEquals($this->selectMock, $mapper->map($criteriaMock));
}


public function testMapException()
{
$mapperMethods = [
'my-test-value1' => 'mapMyMapperMethodOne'
];

$criteriaParts = [
'my_mapper_method_one' => 'my-test-value1'
];
/** @var \Magento\Framework\DB\AbstractMapper|\PHPUnit_Framework_MockObject_MockObject $mapper */
$mapper = $this->getMockForAbstractClass(
\Magento\Framework\DB\AbstractMapper::class,
[
'logger' => $this->loggerMock,
'fetchStrategy' => $this->fetchStrategyMock,
'objectFactory' => $this->objectFactoryMock,
'mapperFactory' => $this->mapperFactoryMock,
'select' => $this->selectMock
],
'',
true,
true,
true,
$mapperMethods
);
$criteriaMock = $this->getMockForAbstractClass(
\Magento\Framework\Api\CriteriaInterface::class,
[],
'',
false,
true,
true,
['toArray']
);
$criteriaMock->expects($this->once())
->method('toArray')
->will($this->returnValue($criteriaParts));
$this->expectException(\InvalidArgumentException::class);
$mapper->map($criteriaMock);

}

/**
* Run test addExpressionFieldToSelect method
*
Expand Down Expand Up @@ -254,8 +297,8 @@ public function dataProviderMap()
'my-test-value2' => 'mapMyMapperMethodTwo',
],
'criteriaParts' => [
'my_mapper_method_one' => 'my-test-value1',
'my_mapper_method_two' => 'my-test-value2',
'my_mapper_method_one' => ['my-test-value1'],
'my_mapper_method_two' => ['my-test-value2'],
],
]
];
Expand Down