23 private $objectManager;
33 private $nullableMock;
43 private $resourceConnectionMock;
48 private $identityMock;
53 private $unsignedMock;
63 $this->nullableMock = $this->getMockBuilder(Nullable::class)
64 ->disableOriginalConstructor()
66 $this->commentMock = $this->getMockBuilder(Comment::class)
67 ->disableOriginalConstructor()
69 $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
70 ->disableOriginalConstructor()
72 $this->identityMock = $this->getMockBuilder(Identity::class)
73 ->disableOriginalConstructor()
75 $this->unsignedMock = $this->getMockBuilder(Unsigned::class)
76 ->disableOriginalConstructor()
78 $this->booleanMock = $this->getMockBuilder(Boolean::class)
79 ->disableOriginalConstructor()
81 $this->integer = $this->objectManager->getObject(
84 'unsigned' => $this->unsignedMock,
85 'boolean' => $this->booleanMock,
86 'nullable' => $this->nullableMock,
87 'identity' => $this->identityMock,
88 'comment' => $this->commentMock,
89 'resourceConnection' => $this->resourceConnectionMock
97 public function testToDefinition()
100 $column = $this->getMockBuilder(IntegerColumnDto::class)
101 ->disableOriginalConstructor()
103 $column->expects($this->any())
105 ->willReturn(
'int_column');
106 $column->expects($this->any())
109 $column->expects($this->any())
110 ->method(
'getPadding')
112 $column->expects($this->any())
113 ->method(
'getDefault')
115 $this->unsignedMock->expects($this->any())
116 ->method(
'toDefinition')
118 ->willReturn(
'UNSIGNED');
119 $this->nullableMock->expects($this->any())
120 ->method(
'toDefinition')
122 ->willReturn(
'NOT NULL');
123 $this->identityMock->expects($this->any())
124 ->method(
'toDefinition')
125 ->willReturn(
'AUTO_INCREMENT');
126 $adapterMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
127 ->disableOriginalConstructor()
129 $this->resourceConnectionMock->expects($this->once())->method(
'getConnection')->willReturn($adapterMock);
130 $adapterMock->expects($this->once())
131 ->method(
'quoteIdentifier')
133 ->willReturn(
'`int_column`');
134 $this->nullableMock->expects($this->any())
135 ->method(
'toDefinition')
137 ->willReturn(
'NULL');
138 $this->commentMock->expects($this->any())
139 ->method(
'toDefinition')
141 ->willReturn(
'COMMENT "Comment"');
143 '`int_column` int(10) UNSIGNED NOT NULL DEFAULT 0 AUTO_INCREMENT COMMENT "Comment"',
144 $this->integer->toDefinition($column)
158 'definition' => $definition,
160 if ($expectedLength) {
161 $expectedData[
'padding'] = $expectedLength;
163 $this->unsignedMock->expects($this->any())->method(
'fromDefinition')->willReturnArgument(0);
164 $this->identityMock->expects($this->any())->method(
'fromDefinition')->willReturnArgument(0);
165 $this->nullableMock->expects($this->any())->method(
'fromDefinition')->willReturnArgument(0);
166 $this->booleanMock->expects($this->any())->method(
'fromDefinition')->willReturnArgument(0);
167 $result = $this->integer->fromDefinition([
'definition' => $definition]);
168 $this->assertEquals($expectedData,
$result);
testFromDefinition($definition, $expectedLength=false)