Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OnUpdateTest.php
Go to the documentation of this file.
1 <?php
7 
14 
15 class OnUpdateTest extends \PHPUnit\Framework\TestCase
16 {
20  private $objectManager;
21 
25  private $onUpdate;
26 
27  protected function setUp()
28  {
29  $this->objectManager = new ObjectManager($this);
30  $this->onUpdate = $this->objectManager->getObject(
31  OnUpdate::class
32  );
33  }
34 
38  public function testToDefinition()
39  {
41  $column = $this->getMockBuilder(Timestamp::class)
42  ->disableOriginalConstructor()
43  ->setMethods(['getOnUpdate'])
44  ->getMock();
45  $column->expects($this->any())
46  ->method('getOnUpdate')
47  ->willReturn('on update');
48  $this->assertEquals(
49  'ON UPDATE CURRENT_TIMESTAMP',
50  $this->onUpdate->toDefinition($column)
51  );
52  }
53 
57  public function testToDefinitionNonUpdate()
58  {
60  $column = $this->getMockBuilder(Timestamp::class)
61  ->disableOriginalConstructor()
62  ->setMethods(['getOnUpdate'])
63  ->getMock();
64  $column->expects($this->any())
65  ->method('getOnUpdate')
66  ->willReturn(null);
67  $this->assertEquals(
68  '',
69  $this->onUpdate->toDefinition($column)
70  );
71  }
72 
76  public function testToDefinitionNonTimestamp()
77  {
79  $column = $this->getMockBuilder(BooleanColumnDto::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82  $this->assertEquals(
83  '',
84  $this->onUpdate->toDefinition($column)
85  );
86  }
87 }