Skip to content

Commit 8034a6e

Browse files
committed
test has been updated.
1 parent 44ec111 commit 8034a6e

File tree

2 files changed

+211
-65
lines changed

2 files changed

+211
-65
lines changed

app/code/Magento/MessageQueue/Test/Integration/PoisonPillApplyDuringSetupUpgradeTest.php

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MessageQueue\Test\Unit\Console;
9+
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
13+
use Magento\Framework\Module\ModuleListInterface;
14+
use Magento\Framework\Mview\TriggerCleaner;
15+
use Magento\Framework\Registry;
16+
use Magento\Framework\Setup\ModuleContextInterface;
17+
use Magento\Framework\Setup\Patch\PatchApplier;
18+
use Magento\Framework\Setup\Patch\PatchApplierFactory;
19+
use Magento\Framework\Setup\SchemaListener;
20+
use Magento\Framework\Setup\SchemaPersistor;
21+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
22+
use Magento\MessageQueue\Setup\Recurring;
23+
use Magento\Setup\Model\DeclarationInstaller;
24+
use Magento\Setup\Model\Installer;
25+
use Magento\Setup\Model\ObjectManagerProvider;
26+
use Magento\Setup\Module\SetupFactory;
27+
use PHPUnit\Framework\MockObject\MockObject;
28+
use PHPUnit\Framework\TestCase;
29+
30+
/**
31+
* Class PoisonPillApplyDuringSetupUpgradeTest
32+
* @package Magento\MessageQueue\Test\Unit\Console
33+
*/
34+
class PoisonPillApplyDuringSetupUpgradeTest extends TestCase
35+
{
36+
/**
37+
* @var Installer
38+
*/
39+
private $installer;
40+
/**
41+
* @var object
42+
*/
43+
private $objectManagerProvider;
44+
/**
45+
* @var \Magento\Framework\ObjectManager\ObjectManager|MockObject
46+
*/
47+
private $objectManagerMock;
48+
/**
49+
* @var object
50+
*/
51+
private $registry;
52+
/**
53+
* @var MockObject
54+
*/
55+
private $deploymentConfig;
56+
/**
57+
* @var ModuleContextInterface|mixed|MockObject
58+
*/
59+
private $schemaSetupInterface;
60+
/**
61+
* @var SetupFactory|mixed|MockObject
62+
*/
63+
private $setupFactory;
64+
/**
65+
* @var AdapterInterface|mixed|MockObject
66+
*/
67+
private $adapterInterface;
68+
/**
69+
* @var object
70+
*/
71+
private $resourceConnection;
72+
/**
73+
* @var object
74+
*/
75+
private $declarationInstaller;
76+
/**
77+
* @var object
78+
*/
79+
private $schemaPersistor;
80+
/**
81+
* @var object
82+
*/
83+
private $triggerCleaner;
84+
/**
85+
* @var object
86+
*/
87+
private $moduleListInterface;
88+
/**
89+
* @var object
90+
*/
91+
private $schemaListener;
92+
/**
93+
* @var object
94+
*/
95+
private $patchApplierFactory;
96+
/**
97+
* @var object
98+
*/
99+
private $patchApplier;
100+
/**
101+
* @var object
102+
*/
103+
private $recurring;
104+
/**
105+
* @var PoisonPillPutInterface|MockObject
106+
*/
107+
private $poisonPillPut;
108+
109+
/**
110+
* @inheritdoc
111+
*/
112+
protected function setUp(): void
113+
{
114+
$objectManager = new ObjectManager($this);
115+
$this->registry = $objectManager->getObject(Registry::class);
116+
$this->moduleListInterface = $this->createMock(ModuleListInterface::class);
117+
$this->moduleListInterface->method('getNames')->willReturn(['Magento_MessageQueue']);
118+
$this->declarationInstaller = $this->createMock(DeclarationInstaller::class);
119+
$this->declarationInstaller->method('installSchema')->willReturn(true);
120+
$this->schemaListener = $this->createMock(SchemaListener::class);
121+
$this->schemaPersistor = $objectManager->getObject(SchemaPersistor::class);
122+
$this->triggerCleaner = $objectManager->getObject(TriggerCleaner::class);
123+
$this->patchApplierFactory = $this->createMock(PatchApplierFactory::class);
124+
$this->patchApplier = $this->createMock(PatchApplier::class);
125+
$this->patchApplier->method('applySchemaPatch')->willReturn(true);
126+
127+
$this->patchApplierFactory->method('create')->willReturn($this->patchApplier);
128+
$this->objectManagerProvider = $this->createMock(ObjectManagerProvider::class);
129+
$this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManager\ObjectManager::class);
130+
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
131+
$this->deploymentConfig->method('get')->willReturn(['host'=>'localhost', 'dbname' => 'magento']);
132+
$this->objectManagerMock->method('get')->withConsecutive(
133+
[SchemaPersistor::class],
134+
[TriggerCleaner::class],
135+
[Registry::class],
136+
[DeclarationInstaller::class],
137+
)->willReturnOnConsecutiveCalls(
138+
$this->schemaPersistor,
139+
$this->triggerCleaner,
140+
$this->registry,
141+
$this->declarationInstaller,
142+
);
143+
$this->poisonPillPut = $this->createMock(\Magento\MessageQueue\Model\ResourceModel\PoisonPill::class);
144+
$this->recurring = new Recurring($this->poisonPillPut);
145+
146+
$this->objectManagerMock->method('create')->withConsecutive(
147+
[PatchApplierFactory::class],
148+
[Recurring::class],
149+
)->willReturnOnConsecutiveCalls(
150+
$this->patchApplierFactory,
151+
$this->recurring,
152+
);
153+
$this->objectManagerProvider->method('get')->willReturn($this->objectManagerMock);
154+
$this->adapterInterface = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
155+
$this->adapterInterface->method('isTableExists')->willReturn(true);
156+
$this->adapterInterface->method('getTables')->willReturn([]);
157+
$this->adapterInterface->method('getSchemaListener')->willReturn($this->schemaListener);
158+
$this->resourceConnection = $objectManager->getObject(\Magento\Framework\App\ResourceConnection::class);
159+
$this->schemaSetupInterface = $this->createMock(\Magento\Framework\Setup\SchemaSetupInterface::class);
160+
$this->schemaSetupInterface->method('getConnection')->willReturn($this->adapterInterface);
161+
$this->schemaSetupInterface
162+
->method('getTable')
163+
->withConsecutive(
164+
['setup_module'],
165+
['session'],
166+
['cache'],
167+
['cache_tag'],
168+
['flag']
169+
)->willReturnOnConsecutiveCalls(
170+
'setup_module',
171+
'session',
172+
'cache',
173+
'cache_tag',
174+
'flag'
175+
);
176+
177+
$this->setupFactory = $this->createMock(SetupFactory::class);
178+
$this->setupFactory->method('create')->willReturn($this->schemaSetupInterface);
179+
180+
$this->installer = $objectManager->getObject(
181+
Installer::class,
182+
[
183+
'objectManagerProvider' => $this->objectManagerProvider,
184+
'deploymentConfig'=>$this->deploymentConfig,
185+
'setupFactory'=>$this->setupFactory,
186+
'moduleList'=>$this->moduleListInterface,
187+
]
188+
);
189+
}
190+
191+
/**
192+
* @covers \Magento\MessageQueue\Setup\Recurring
193+
*/
194+
public function testChangeVersion(): void
195+
{
196+
$this->poisonPillPut->expects(self::once())->method('put');
197+
$this->installer->installSchema(
198+
[
199+
'keep-generated'=>false,
200+
'convert-old-scripts'=>false,
201+
'help'=>false,
202+
'quiet'=>false,
203+
'verbose'=>false,
204+
'version'=>false,
205+
'ansi'=>false,
206+
'no-ansi'=>false,
207+
'no-interaction'=>false,
208+
]
209+
);
210+
}
211+
}

0 commit comments

Comments
 (0)