Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PatchRegirtryTest.php
Go to the documentation of this file.
1 <?php
8 
13 
18 class PatchRegirtryTest extends \PHPUnit\Framework\TestCase
19 {
23  private $patchRegistry;
24 
28  private $patchFactoryMock;
29 
33  private $patchHistoryMock;
34 
35  protected function setUp()
36  {
37  $objectManager = new ObjectManager($this);
38  $this->patchFactoryMock = $this->getMockBuilder(PatchFactory::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $this->patchHistoryMock = $this->getMockBuilder(PatchHistory::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45 
46  $this->patchRegistry = $objectManager->getObject(
47  PatchRegistry::class,
48  [
49  'patchHistory' => $this->patchHistoryMock,
50  'patchFactory' => $this->patchFactoryMock,
51  ]
52  );
53  require_once __DIR__ . '/../_files/data_patch_classes.php';
54  }
55 
56  public function testRegisterAppliedPatch()
57  {
58  $this->patchHistoryMock->expects($this->once())
59  ->method('isApplied')
60  ->with(\SomeDataPatch::class)
61  ->willReturn(false);
62 
63  $this->assertEquals(\SomeDataPatch::class, $this->patchRegistry->registerPatch(\SomeDataPatch::class));
64  }
65 
66  public function testRegisterNonAplliedPatch()
67  {
68  $this->patchHistoryMock->expects($this->once())
69  ->method('isApplied')
70  ->with(\SomeDataPatch::class)
71  ->willReturn(true);
72 
73  $this->assertEquals(false, $this->patchRegistry->registerPatch(\SomeDataPatch::class));
74  }
75 
76  public function testGetIterator()
77  {
78  $this->patchHistoryMock->expects($this->any())
79  ->method('isApplied')
80  ->willReturnMap(
81  [
82  [\SomeDataPatch::class, false],
83  [\OtherDataPatch::class, false]
84  ]
85  );
86 
87  $this->assertEquals(\SomeDataPatch::class, $this->patchRegistry->registerPatch(\SomeDataPatch::class));
88 
89  $actualPatches = [];
90  foreach ($this->patchRegistry->getIterator() as $patch) {
91  $actualPatches[] = $patch;
92  }
93  // assert that all dependencies are present and placed in valid sequence
94  $this->assertEquals(
95  [\OtherDataPatch::class, \SomeDataPatch::class],
96  $actualPatches,
97  'Failed to assert that actual non-apllied patches sequence is valid.'
98  );
99  }
100 }
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60