Skip to content

Commit 07a1028

Browse files
ENGCOM-6198: Fix #24019 #24947
- Merge Pull Request #24947 from korostii/magento2:korostii-patch-24019 - Merged commits: 1. 602d6a1 2. 5632f45 3. 025d0de 4. 3d6690a
2 parents 68d2137 + 3d6690a commit 07a1028

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/internal/Magento/Framework/Setup/Patch/PatchHistory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public function __construct(ResourceConnection $resourceConnection)
5656
* Read and cache data patches from db
5757
*
5858
* All patches are store in patch_list table
59-
* @see self::TABLE_NAME
6059
*
61-
* @return array
60+
* @see self::TABLE_NAME
61+
* @return string[]
6262
*/
6363
private function getAppliedPatches()
6464
{
@@ -87,12 +87,14 @@ public function fixPatch($patchName)
8787

8888
$adapter = $this->resourceConnection->getConnection();
8989
$adapter->insert($this->resourceConnection->getTableName(self::TABLE_NAME), [self::CLASS_NAME => $patchName]);
90+
91+
$this->patchesRegistry[] = $patchName;
9092
}
9193

9294
/**
9395
* Revert patch from history
9496
*
95-
* @param $patchName
97+
* @param string $patchName
9698
* @return void
9799
*/
98100
public function revertPatchFromHistory($patchName)

lib/internal/Magento/Framework/Setup/Test/Unit/Patch/PatchHistoryTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,28 @@ public function testFixAppliedPatch()
8383
$adapterMock->expects($this->never())->method('insert');
8484
$this->patchHistory->fixPatch(get_class($patch1));
8585
}
86+
87+
/**
88+
* @expectedException \LogicException
89+
* @expectedExceptionMessageRegExp "Patch [a-zA-Z0-9\_]+ cannot be applied twice"
90+
*/
91+
public function testFixPatchTwice()
92+
{
93+
/** @var PatchInterface|\PHPUnit_Framework_MockObject_MockObject $patch1 */
94+
$patch = $this->createMock(PatchInterface::class);
95+
/** @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject $adapterMock */
96+
$adapterMock = $this->createMock(AdapterInterface::class);
97+
$this->resourceConnectionMock->expects($this->any())->method('getConnection')->willReturn($adapterMock);
98+
$this->resourceConnectionMock->expects($this->any())
99+
->method('getTableName')
100+
->willReturn(PatchHistory::TABLE_NAME);
101+
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
102+
$selectMock->expects($this->once())->method('from');
103+
$adapterMock->expects($this->any())->method('select')->willReturn($selectMock);
104+
$adapterMock->expects($this->once())->method('fetchCol')->willReturn([]);
105+
$adapterMock->expects($this->once())->method('insert');
106+
107+
$this->patchHistory->fixPatch(get_class($patch));
108+
$this->patchHistory->fixPatch(get_class($patch));
109+
}
86110
}

0 commit comments

Comments
 (0)