63 $this->resourceMock = $this->getMockForAbstractClass(
72 $this->connectionMock = $this->getMockForAbstractClass(
73 \
Magento\Framework\DB\Adapter\AdapterInterface::class,
81 $this->selectMock = $this->createMock(\
Magento\Framework\DB\Select::class);
82 $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
83 $this->fetchStrategyMock = $this->getMockForAbstractClass(
84 \
Magento\Framework\Data\Collection\Db\FetchStrategyInterface::class,
92 $this->objectFactoryMock = $this->createMock(\
Magento\Framework\Data\ObjectFactory::class);
93 $this->mapperFactoryMock = $this->createMock(\
Magento\Framework\DB\MapperFactory::class);
105 public function testMap(array $mapperMethods, array $criteriaParts)
108 $mapper = $this->getMockForAbstractClass(
109 \
Magento\Framework\DB\AbstractMapper::class,
111 'logger' => $this->loggerMock,
112 'fetchStrategy' => $this->fetchStrategyMock,
113 'objectFactory' => $this->objectFactoryMock,
114 'mapperFactory' => $this->mapperFactoryMock,
115 'select' => $this->selectMock
123 $criteriaMock = $this->getMockForAbstractClass(
124 \
Magento\Framework\Api\CriteriaInterface::class,
132 $criteriaMock->expects($this->once())
134 ->will($this->returnValue($criteriaParts));
136 $mapper->expects($this->once())
141 $this->assertEquals($this->selectMock,
$mapper->map($criteriaMock));
144 public function testMapException()
147 'my-test-value1' =>
'mapMyMapperMethodOne' 151 'my_mapper_method_one' =>
'my-test-value1' 154 $mapper = $this->getMockForAbstractClass(
155 \
Magento\Framework\DB\AbstractMapper::class,
157 'logger' => $this->loggerMock,
158 'fetchStrategy' => $this->fetchStrategyMock,
159 'objectFactory' => $this->objectFactoryMock,
160 'mapperFactory' => $this->mapperFactoryMock,
161 'select' => $this->selectMock
169 $criteriaMock = $this->getMockForAbstractClass(
170 \
Magento\Framework\Api\CriteriaInterface::class,
178 $criteriaMock->expects($this->once())
180 ->will($this->returnValue($criteriaParts));
181 $this->expectException(\InvalidArgumentException::class);
190 public function testAddExpressionFieldToSelect()
193 'key-attribute' =>
'value-attribute',
196 $mapper = $this->getMockForAbstractClass(
197 \
Magento\Framework\DB\AbstractMapper::class,
199 'logger' => $this->loggerMock,
200 'fetchStrategy' => $this->fetchStrategyMock,
201 'objectFactory' => $this->objectFactoryMock,
202 'mapperFactory' => $this->mapperFactoryMock,
203 'select' => $this->selectMock
212 $this->selectMock->expects($this->once())
214 ->with([
'my-alias' =>
"('sub_total', 'SUM(value-attribute)', 'revenue')"]);
216 $mapper->addExpressionFieldToSelect(
'my-alias',
"('sub_total', 'SUM({{key-attribute}})', 'revenue')",
$fields);
228 public function testAddFieldToFilter($field, $condition)
230 $resultCondition =
'sql-condition-value';
233 $mapper = $this->getMockForAbstractClass(
234 \
Magento\Framework\DB\AbstractMapper::class,
236 'logger' => $this->loggerMock,
237 'fetchStrategy' => $this->fetchStrategyMock,
238 'objectFactory' => $this->objectFactoryMock,
239 'mapperFactory' => $this->mapperFactoryMock,
240 'select' => $this->selectMock
249 \
Magento\Framework\DB\Adapter\AdapterInterface::class,
255 [
'quoteIdentifier',
'prepareSqlCondition']
259 ->method(
'getConnection')
262 ->method(
'quoteIdentifier')
264 ->will($this->returnValue(
'quote-field'));
266 ->method(
'prepareSqlCondition')
267 ->with(
'quote-field', $condition)
268 ->will($this->returnValue($resultCondition));
270 if (is_array($field)) {
271 $resultCondition =
'(' . implode(
273 array_fill(0, count($field), $resultCondition)
277 $this->selectMock->expects($this->once())
281 $mapper->addFieldToFilter($field, $condition);
294 'my-test-value1' =>
'mapMyMapperMethodOne',
295 'my-test-value2' =>
'mapMyMapperMethodTwo',
298 'my_mapper_method_one' => [
'my-test-value1'],
299 'my_mapper_method_two' => [
'my-test-value2'],
314 'field' =>
'my-field',
315 'condition' => [
'condition'],
318 'field' => [
'my-field',
'my-field'],
dataProviderAddFieldToFilter()