Skip to content

Commit

Permalink
#8647: [GitHub] Order of how arguments are merged in multiple di.xml-…
Browse files Browse the repository at this point in the history
…files causes unexpected results
  • Loading branch information
serhii-balko committed Dec 11, 2017
1 parent d865ef1 commit 3620313
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ protected function _getRendererClass()
if (!is_array($acceptTypes)) {
$acceptTypes = [$acceptTypes];
}
// If Accept type = '*/*' then return default renderer.
$defaultRenderer = isset($this->_renders['default']) ? $this->_renders['default'] : null;
foreach ($acceptTypes as $acceptType) {
if ($acceptType == '*/*' && $defaultRenderer) {
return $defaultRenderer['model'];
}
foreach ($this->_renders as $rendererConfig) {
$rendererType = $rendererConfig['type'];
if ($acceptType == $rendererType || $acceptType == current(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ protected function setUp()
)->disableOriginalConstructor()->getMock();

$renders = [
'default' => ['type' => '*/*', 'model' => \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class],
'application_xml' => [
'type' => 'application/xml',
'model' => \Magento\Framework\Webapi\Rest\Response\Renderer\Xml::class,
],
'application_json' => [
'type' => 'application/json',
'model' => \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class,
],
'default' => [
'type' => '*/*',
'model' => \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class
],
];

$this->_factory = new \Magento\Framework\Webapi\Rest\Response\RendererFactory(
Expand All @@ -42,29 +49,43 @@ protected function setUp()

/**
* Test GET method.
*
* @param array $acceptTypes
* @param string $model
* @dataProvider getTestDataProvider
*/
public function testGet()
public function testGet($acceptTypes, $model)
{
$acceptTypes = ['application/json'];

/** Mock request getAcceptTypes method to return specified value. */
$this->_requestMock->expects($this->once())->method('getAcceptTypes')->will($this->returnValue($acceptTypes));
/** Mock renderer. */
$rendererMock = $this->getMockBuilder(
\Magento\Framework\Webapi\Rest\Response\Renderer\Json::class
)->disableOriginalConstructor()->getMock();
$rendererMock = $this->getMockBuilder($model)->disableOriginalConstructor()->getMock();
/** Mock object to return mocked renderer. */
$this->_objectManagerMock->expects(
$this->once()
)->method(
'get'
)->with(
\Magento\Framework\Webapi\Rest\Response\Renderer\Json::class
$model
)->will(
$this->returnValue($rendererMock)
);
$this->_factory->get();
}

/**
* Data provider for method testGet
*
* @return array
*/
public function getTestDataProvider()
{
return [
[['*/*'], \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class],
[['application/json'], \Magento\Framework\Webapi\Rest\Response\Renderer\Json::class],
[['application/xml'], \Magento\Framework\Webapi\Rest\Response\Renderer\Xml::class],
];
}

/**
* Test GET method with wrong Accept HTTP Header.
Expand Down

0 comments on commit 3620313

Please sign in to comment.