Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PatchHistoryTest.php
Go to the documentation of this file.
1 <?php
8 
14 
19 class PatchHistoryTest extends \PHPUnit\Framework\TestCase
20 {
24  private $patchHistory;
25 
29  private $resourceConnectionMock;
30 
31  protected function setUp()
32  {
33  $objectManager = new ObjectManager($this);
34  $this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
35  $this->patchHistory = $objectManager->getObject(
36  PatchHistory::class,
37  [
38  'resourceConnection' => $this->resourceConnectionMock,
39  ]
40  );
41  }
42 
46  public function testFixPatch()
47  {
49  $patch1 = $this->createMock(PatchInterface::class);
51  $adapterMock = $this->createMock(AdapterInterface::class);
52  $this->resourceConnectionMock->expects($this->any())->method('getConnection')->willReturn($adapterMock);
53  $selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
54  $selectMock->expects($this->once())->method('from');
55  $adapterMock->expects($this->any())->method('select')->willReturn($selectMock);
56  $adapterMock->expects($this->once())->method('fetchCol')->willReturn([]);
57  $this->resourceConnectionMock->expects($this->any())
58  ->method('getTableName')
59  ->willReturn(PatchHistory::TABLE_NAME);
60  $adapterMock->expects($this->once())->method('insert')
61  ->with(PatchHistory::TABLE_NAME, [PatchHistory::CLASS_NAME => get_class($patch1)]);
62  $this->patchHistory->fixPatch(get_class($patch1));
63  }
64 
69  public function testFixAppliedPatch()
70  {
72  $patch1 = $this->createMock(PatchInterface::class);
74  $adapterMock = $this->createMock(AdapterInterface::class);
75  $this->resourceConnectionMock->expects($this->any())->method('getConnection')->willReturn($adapterMock);
76  $selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
77  $selectMock->expects($this->once())->method('from');
78  $adapterMock->expects($this->any())->method('select')->willReturn($selectMock);
79  $adapterMock->expects($this->once())->method('fetchCol')->willReturn([get_class($patch1)]);
80  $this->resourceConnectionMock->expects($this->any())
81  ->method('getTableName')
82  ->willReturn(PatchHistory::TABLE_NAME);
83  $adapterMock->expects($this->never())->method('insert');
84  $this->patchHistory->fixPatch(get_class($patch1));
85  }
86 }
$objectManager
Definition: bootstrap.php:17