Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IdentityTest.php
Go to the documentation of this file.
1 <?php
7 
10 
16 class IdentityTest extends \PHPUnit\Framework\TestCase
17 {
21  private $objectManager;
22 
26  private $identity;
27 
31  private $columnMock;
32 
33  protected function setUp()
34  {
35  $this->objectManager = new ObjectManager($this);
36  $this->columnMock = $this->getMockBuilder(\Magento\Framework\Setup\Declaration\Schema\Dto\Column::class)
37  ->disableOriginalConstructor()
38  ->setMethods(['isIdentity'])
39  ->getMock();
40  $this->identity = $this->objectManager->getObject(
41  Identity::class
42  );
43  }
44 
48  public function testToDefinition()
49  {
50  $this->columnMock->expects($this->any())
51  ->method('isIdentity')
52  ->willReturn(true);
53  $this->assertEquals(
54  'AUTO_INCREMENT',
55  $this->identity->toDefinition($this->columnMock)
56  );
57  }
58 
62  public function testToDefinitionFalse()
63  {
64  $this->columnMock->expects($this->any())
65  ->method('isIdentity')
66  ->willReturn(false);
67  $this->assertEquals(
68  '',
69  $this->identity->toDefinition($this->columnMock)
70  );
71  }
72 
76  public function testFromDefinition()
77  {
78  $data = [
79  'extra' => 'NOT NULL AUTO_INCREMENT'
80  ];
81  $expectedData = $data;
82  $expectedData['identity'] = true;
83  $this->assertEquals(
84  $expectedData,
85  $this->identity->fromDefinition($data)
86  );
87  }
88 }