Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UnsignedTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class UnsignedTest extends \PHPUnit\Framework\TestCase
13 {
17  private $objectManager;
18 
22  private $unsigned;
23 
24  protected function setUp()
25  {
26  $this->objectManager = new ObjectManager($this);
27  $this->unsigned = $this->objectManager->getObject(
28  Unsigned::class
29  );
30  }
31 
35  public function testToDefinition()
36  {
38  $column = $this->getMockBuilder(IntegerColumnDto::class)
39  ->disableOriginalConstructor()
40  ->setMethods(['isUnsigned'])
41  ->getMock();
42  $column->expects($this->any())
43  ->method('isUnsigned')
44  ->willReturn(true);
45  $this->assertEquals(
46  'UNSIGNED',
47  $this->unsigned->toDefinition($column)
48  );
49  }
50 
54  public function testToDefinitionNotUnsigned()
55  {
57  $column = $this->getMockBuilder(IntegerColumnDto::class)
58  ->disableOriginalConstructor()
59  ->setMethods(['isUnsigned'])
60  ->getMock();
61  $column->expects($this->any())
62  ->method('isUnsigned')
63  ->willReturn(false);
64  $this->assertEquals(
65  '',
66  $this->unsigned->toDefinition($column)
67  );
68  }
69 
70  public function testFromDefinition()
71  {
72  $data = [
73  'definition' => 'NOT NULL UNSIGNED'
74  ];
75  $expectedData = $data;
76  $expectedData['unsigned'] = true;
77  $this->assertEquals(
78  $expectedData,
79  $this->unsigned->fromDefinition($data)
80  );
81  }
82 
83  public function testFromDefinitionSigned()
84  {
85  $data = [
86  'definition' => 'NOT NULL'
87  ];
88  $expectedData = $data;
89  $expectedData['unsigned'] = false;
90  $this->assertEquals(
91  $expectedData,
92  $this->unsigned->fromDefinition($data)
93  );
94  }
95 }