Skip to content

Commit b8bb664

Browse files
committed
MAGETWO-65420: Update reports definitions for the Advanced Reporting service
1 parent 53384ce commit b8bb664

File tree

1 file changed

+33
-44
lines changed

1 file changed

+33
-44
lines changed

app/code/Magento/Analytics/Test/Unit/ReportXml/SelectHydratorTest.php

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Magento\Framework\ObjectManagerInterface;
1414
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1515

16+
/**
17+
* Class SelectHydratorTest
18+
*/
1619
class SelectHydratorTest extends \PHPUnit_Framework_TestCase
1720
{
1821
/**
@@ -40,11 +43,6 @@ class SelectHydratorTest extends \PHPUnit_Framework_TestCase
4043
*/
4144
private $objectManagerMock;
4245

43-
/**
44-
* @var JsonSerializableExpression|\PHPUnit_Framework_MockObject_MockObject
45-
*/
46-
private $expressionMock;
47-
4846
/**
4947
* @var ObjectManagerHelper
5048
*/
@@ -173,30 +171,19 @@ public function recreateWithoutExpressionDataProvider()
173171
/**
174172
* @dataProvider recreateWithExpressionDataProvider
175173
* @param array $selectParts
176-
* @param array $parts
177-
* @param array $partValues
178-
* @param array $mocks
174+
* @param array $expectedParts
175+
* @param \PHPUnit_Framework_MockObject_MockObject[] $expressionMocks
179176
*/
180-
public function testRecreateWithExpression($selectParts, $parts, $partValues, $mocks = [])
181-
{
182-
/** data provider executes in isolation so all mocks have to be set in the test */
183-
foreach ($mocks as $mockName => $mockObject) {
184-
$this->{$mockName} = $mockObject;
185-
}
186-
187-
$checkClassName = function ($value) {
188-
return is_string($value);
189-
};
190-
191-
$checkArguments = function ($value) {
192-
return is_array($value);
193-
};
194-
177+
public function testRecreateWithExpression(
178+
array $selectParts,
179+
array $expectedParts,
180+
array $expressionMocks
181+
) {
195182
$this->objectManagerMock
196-
->expects($this->once())
183+
->expects($this->exactly(count($expressionMocks)))
197184
->method('create')
198-
->with($this->callback($checkClassName), $this->callback($checkArguments))
199-
->willReturn($this->expressionMock);
185+
->with($this->isType('string'), $this->isType('array'))
186+
->willReturnOnConsecutiveCalls(...$expressionMocks);
200187
$this->resourceConnectionMock
201188
->expects($this->once())
202189
->method('getConnection')
@@ -207,10 +194,11 @@ public function testRecreateWithExpression($selectParts, $parts, $partValues, $m
207194
->method('select')
208195
->with()
209196
->willReturn($this->selectMock);
210-
foreach ($parts as $key => $part) {
211-
$this->selectMock->expects($this->at($key))
197+
foreach (array_keys($selectParts) as $key => $partName) {
198+
$this->selectMock
199+
->expects($this->at($key))
212200
->method('setPart')
213-
->with($part, $partValues[$key]);
201+
->with($partName, $expectedParts[$partName]);
214202
}
215203

216204
$this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts));
@@ -246,21 +234,22 @@ public function recreateWithExpressionDataProvider()
246234
],
247235
]
248236
],
249-
'Parts names' => [Select::COLUMNS],
250-
'Assembled parts' => [[
251-
[
252-
'table_name',
253-
'field_name',
254-
'alias',
255-
],
256-
[
257-
'table_name',
258-
$expressionMock,
259-
'alias_2',
260-
],
261-
]],
262-
'Mocks' => [
263-
'expressionMock' => $expressionMock
237+
'expectedParts' => [
238+
Select::COLUMNS => [
239+
[
240+
'table_name',
241+
'field_name',
242+
'alias',
243+
],
244+
[
245+
'table_name',
246+
$expressionMock,
247+
'alias_2',
248+
],
249+
]
250+
],
251+
'expectedExpressions' => [
252+
$expressionMock
264253
]
265254
],
266255
];

0 commit comments

Comments
 (0)