Skip to content

Commit deb30e5

Browse files
committed
MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline
1 parent 688f715 commit deb30e5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface GeneratorInterface
2020
public function getFilterData(Attribute $attribute, $filterName);
2121

2222
/**
23-
* Get aggregations data for specific attribute
23+
* Get aggregation data for specific attribute
2424
* @param Attribute $attribute
2525
* @param string $bucketName
2626
* @return array

app/code/Magento/CatalogSearch/Model/Search/RequestGenerator/GeneratorResolver.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ public function __construct(GeneratorInterface $defaultGenerator, array $generat
3131
/**
3232
* @param string $type
3333
* @return GeneratorInterface
34+
* @throws \InvalidArgumentException
3435
*/
3536
public function getGeneratorForType($type)
3637
{
37-
return isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator;
38+
$generator = isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator;
39+
if (!($generator instanceof GeneratorInterface)) {
40+
throw new \InvalidArgumentException(
41+
'Generator must implement ' . GeneratorInterface::class
42+
);
43+
}
44+
return $generator;
3845
}
3946
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/RequestGenerator/GeneratorResolverTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ protected function setUp()
3737
$this->rangeGenerator = $this->getMockBuilder(GeneratorInterface::class)
3838
->setMethods([])
3939
->getMockForAbstractClass();
40+
41+
$invalidTypeGenerator = $this->getMockBuilder(\stdClass::class)
42+
->setMethods([]);
43+
4044
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4145
$this->resolver = $objectManager->getObject(
4246
GeneratorResolver::class,
@@ -45,6 +49,7 @@ protected function setUp()
4549
'generators' => [
4650
'datetime' => $this->datetimeGenerator,
4751
'range' => $this->datetimeGenerator,
52+
'invalid_type' => $invalidTypeGenerator,
4853
],
4954
]
5055
);
@@ -60,4 +65,12 @@ public function testGetFallbackGenerator()
6065
{
6166
$this->assertEquals($this->defaultGenerator, $this->resolver->getGeneratorForType('unknown_type'));
6267
}
68+
69+
/**
70+
* @expectedException InvalidArgumentException
71+
*/
72+
public function testGetInvalidGeneratorType()
73+
{
74+
$this->resolver->getGeneratorForType('invalid_type');
75+
}
6376
}

0 commit comments

Comments
 (0)