Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlobTest.php
Go to the documentation of this file.
1 <?php
7 
14 
15 class BlobTest extends \PHPUnit\Framework\TestCase
16 {
20  private $objectManager;
21 
25  private $blob;
26 
30  private $nullableMock;
31 
35  private $commentMock;
36 
40  private $resourceConnectionMock;
41 
42  protected function setUp()
43  {
44  $this->objectManager = new ObjectManager($this);
45  $this->nullableMock = $this->getMockBuilder(Nullable::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48  $this->commentMock = $this->getMockBuilder(Comment::class)
49  ->disableOriginalConstructor()
50  ->getMock();
51  $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54  $this->blob = $this->objectManager->getObject(
55  Blob::class,
56  [
57  'nullable' => $this->nullableMock,
58  'comment' => $this->commentMock,
59  'resourceConnection' => $this->resourceConnectionMock
60  ]
61  );
62  }
63 
67  public function testToDefinition()
68  {
70  $column = $this->getMockBuilder(ElementInterface::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73  $column->expects($this->any())
74  ->method('getName')
75  ->willReturn('col');
76  $column->expects($this->any())
77  ->method('getType')
78  ->willReturn('blob');
79  $adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82  $this->resourceConnectionMock->expects($this->once())->method('getConnection')->willReturn($adapterMock);
83  $adapterMock->expects($this->once())
84  ->method('quoteIdentifier')
85  ->with('col')
86  ->willReturn('`col`');
87  $this->nullableMock->expects($this->any())
88  ->method('toDefinition')
89  ->with($column)
90  ->willReturn('NULL');
91  $this->commentMock->expects($this->any())
92  ->method('toDefinition')
93  ->with($column)
94  ->willReturn('COMMENT "Comment"');
95  $this->assertEquals(
96  '`col` blob NULL COMMENT "Comment"',
97  $this->blob->toDefinition($column)
98  );
99  }
100 
108  public function testFromDefinition($definition, $expectedLength = false)
109  {
110  $expectedData = [
111  'definition' => $definition,
112  ];
113  if ($expectedLength) {
114  $expectedData['length'] = $expectedLength;
115  }
116  $result = $this->blob->fromDefinition(['definition' => $definition]);
117  $this->assertEquals($expectedData, $result);
118  }
119 
123  public function definitionDataProvider()
124  {
125  return [
126  ['blob'],
127  ['tinyblob'],
128  ['mediumblob'],
129  ['longblob'],
130  ['text (555)', 555],
131  ['tinytext'],
132  ['mediumtext'],
133  ['longtext'],
134  ];
135  }
136 }