12 use Magento\Framework\DB\Sql\JsonSerializableExpression;
21 private $selectHydrator;
26 private $resourceConnectionMock;
31 private $connectionMock;
41 private $objectManagerMock;
46 private $objectManagerHelper;
53 $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
54 ->disableOriginalConstructor()
57 $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
58 ->disableOriginalConstructor()
61 $this->selectMock = $this->getMockBuilder(Select::class)
62 ->disableOriginalConstructor()
65 $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
66 ->disableOriginalConstructor()
69 $this->objectManagerHelper =
new ObjectManagerHelper($this);
71 $this->selectHydrator = $this->objectManagerHelper->getObject(
72 SelectHydrator::class,
74 'resourceConnection' => $this->resourceConnectionMock,
75 'objectManager' => $this->objectManagerMock,
98 foreach ($selectParts as $part) {
101 $this->selectMock->expects($this->any())
103 ->willReturn(
"Part");
104 $this->assertEquals($this->selectHydrator->extract($this->selectMock),
$result);
115 $this->resourceConnectionMock->expects($this->once())
116 ->method(
'getConnection')
117 ->willReturn($this->connectionMock);
118 $this->connectionMock->expects($this->once())
120 ->willReturn($this->selectMock);
121 foreach ($parts as $key => $part) {
122 $this->selectMock->expects($this->at($key))
124 ->with($part, $partValues[$key]);
127 $this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts));
136 'Select without expressions' => [
176 array $expectedParts,
177 array $expressionMocks
179 $this->objectManagerMock
180 ->expects($this->exactly(count($expressionMocks)))
182 ->with($this->isType(
'string'), $this->isType(
'array'))
183 ->willReturnOnConsecutiveCalls(...$expressionMocks);
184 $this->resourceConnectionMock
185 ->expects($this->once())
186 ->method(
'getConnection')
188 ->willReturn($this->connectionMock);
189 $this->connectionMock
190 ->expects($this->once())
193 ->willReturn($this->selectMock);
194 foreach (array_keys($selectParts) as $key => $partName) {
196 ->expects($this->at($key))
198 ->with($partName, $expectedParts[$partName]);
201 $this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts));
209 $expressionMock = $this->getMockBuilder(JsonSerializableExpression::class)
210 ->disableOriginalConstructor()
214 'Select without expressions' => [
225 'class' =>
'Some_class',
227 'expression' => [
'some(expression)']
248 'expectedExpressions' => [
testRecreateWithExpression(array $selectParts, array $expectedParts, array $expressionMocks)
recreateWithExpressionDataProvider()
recreateWithoutExpressionDataProvider()
testRecreateWithoutExpression($selectParts, $parts, $partValues)