19 class RealTest extends \PHPUnit\Framework\TestCase
24 private $objectManager;
34 private $nullableMock;
44 private $resourceConnectionMock;
49 private $unsignedMock;
54 $this->nullableMock = $this->getMockBuilder(Nullable::class)
55 ->disableOriginalConstructor()
57 $this->commentMock = $this->getMockBuilder(Comment::class)
58 ->disableOriginalConstructor()
60 $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
61 ->disableOriginalConstructor()
63 $this->unsignedMock = $this->getMockBuilder(Unsigned::class)
64 ->disableOriginalConstructor()
66 $this->real = $this->objectManager->getObject(
69 'nullable' => $this->nullableMock,
70 'unsigned' => $this->unsignedMock,
71 'resourceConnection' => $this->resourceConnectionMock,
72 'comment' => $this->commentMock,
80 public function testToDefinitionNoScale()
83 $column = $this->getMockBuilder(RealColumnDto::class)
84 ->disableOriginalConstructor()
86 $column->expects($this->any())
89 $column->expects($this->any())
91 ->willReturn(
'float');
92 $column->expects($this->any())
93 ->method(
'getPrecision')
95 $column->expects($this->any())
98 $column->expects($this->any())
99 ->method(
'getDefault')
101 $this->unsignedMock->expects($this->any())
102 ->method(
'toDefinition')
104 ->willReturn(
'UNSIGNED');
105 $this->nullableMock->expects($this->any())
106 ->method(
'toDefinition')
108 ->willReturn(
'NOT NULL');
109 $adapterMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
110 ->disableOriginalConstructor()
112 $this->resourceConnectionMock->expects($this->once())->method(
'getConnection')->willReturn($adapterMock);
113 $adapterMock->expects($this->once())
114 ->method(
'quoteIdentifier')
116 ->willReturn(
'`col`');
117 $this->commentMock->expects($this->any())
118 ->method(
'toDefinition')
120 ->willReturn(
'COMMENT "Comment"');
122 '`col` float UNSIGNED NOT NULL DEFAULT 0 COMMENT "Comment"',
123 $this->real->toDefinition($column)
130 public function testToDefinition()
133 $column = $this->getMockBuilder(RealColumnDto::class)
134 ->disableOriginalConstructor()
136 $column->expects($this->any())
139 $column->expects($this->any())
141 ->willReturn(
'float');
142 $column->expects($this->any())
143 ->method(
'getPrecision')
145 $column->expects($this->any())
148 $column->expects($this->any())
149 ->method(
'getDefault')
151 $this->unsignedMock->expects($this->any())
152 ->method(
'toDefinition')
154 ->willReturn(
'UNSIGNED');
155 $this->nullableMock->expects($this->any())
156 ->method(
'toDefinition')
158 ->willReturn(
'NOT NULL');
159 $adapterMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
160 ->disableOriginalConstructor()
162 $this->resourceConnectionMock->expects($this->once())->method(
'getConnection')->willReturn($adapterMock);
163 $adapterMock->expects($this->once())
164 ->method(
'quoteIdentifier')
166 ->willReturn(
'`col`');
167 $this->commentMock->expects($this->any())
168 ->method(
'toDefinition')
170 ->willReturn(
'COMMENT "Comment"');
172 '`col` float(10, 4) UNSIGNED NOT NULL DEFAULT 0 COMMENT "Comment"',
173 $this->real->toDefinition($column)
180 public function testToDefinitionNoDefault()
183 $column = $this->getMockBuilder(RealColumnDto::class)
184 ->disableOriginalConstructor()
186 $column->expects($this->any())
189 $column->expects($this->any())
191 ->willReturn(
'float');
192 $column->expects($this->any())
193 ->method(
'getPrecision')
195 $column->expects($this->any())
198 $column->expects($this->any())
199 ->method(
'getDefault')
201 $this->unsignedMock->expects($this->any())
202 ->method(
'toDefinition')
204 ->willReturn(
'UNSIGNED');
205 $this->nullableMock->expects($this->any())
206 ->method(
'toDefinition')
208 ->willReturn(
'NOT NULL');
209 $adapterMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
210 ->disableOriginalConstructor()
212 $this->resourceConnectionMock->expects($this->once())->method(
'getConnection')->willReturn($adapterMock);
213 $adapterMock->expects($this->once())
214 ->method(
'quoteIdentifier')
216 ->willReturn(
'`col`');
217 $this->commentMock->expects($this->any())
218 ->method(
'toDefinition')
220 ->willReturn(
'COMMENT "Comment"');
222 '`col` float(10, 4) UNSIGNED NOT NULL COMMENT "Comment"',
223 $this->real->toDefinition($column)
237 'definition' => $definition,
239 if ($expectedPrecision) {
240 $expectedData[
'precision'] = $expectedPrecision;
241 $expectedData[
'scale'] = $expectedScale;
243 $this->unsignedMock->expects($this->any())->method(
'fromDefinition')->willReturnArgument(0);
244 $this->nullableMock->expects($this->any())->method(
'fromDefinition')->willReturnArgument(0);
245 $result = $this->real->fromDefinition([
'definition' => $definition]);
246 $this->assertEquals($expectedData,
$result);
256 [
'float(10,4)', 10, 4],
257 [
'float(10)',
false,
false],
258 [
'decimal(10)', 10, 0],
259 [
'decimal(10, 6)', 10, 6],
260 [
'double(10, 6)', 10, 6],
261 [
'double',
false,
false],
262 [
'double(10)',
false,
false],
testFromDefinition($definition, $expectedPrecision=false, $expectedScale=false)