|
| 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 | + * @SuppressWarnings(PHPMD.TooManyFields) |
| 32 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 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->moduleListInterface->method('getOne')->with('Magento_MessageQueue')->willReturn(['setup_version'=>'']); |
| 119 | + $this->declarationInstaller = $this->createMock(DeclarationInstaller::class); |
| 120 | + $this->declarationInstaller->method('installSchema')->willReturn(true); |
| 121 | + $this->schemaListener = $this->createMock(SchemaListener::class); |
| 122 | + $this->schemaPersistor = $objectManager->getObject(SchemaPersistor::class); |
| 123 | + $this->triggerCleaner = $objectManager->getObject(TriggerCleaner::class); |
| 124 | + $this->patchApplierFactory = $this->createMock(PatchApplierFactory::class); |
| 125 | + $this->patchApplier = $this->createMock(PatchApplier::class); |
| 126 | + $this->patchApplier->method('applySchemaPatch')->willReturn(true); |
| 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->adapterInterface->method('describeTable')->willReturn(['flag_data'=>['DATA_TYPE'=>'mediumtext']]); |
| 159 | + $this->resourceConnection = $objectManager->getObject(\Magento\Framework\App\ResourceConnection::class); |
| 160 | + $this->schemaSetupInterface = $this->createMock(\Magento\Framework\Setup\SchemaSetupInterface::class); |
| 161 | + $this->schemaSetupInterface->method('getConnection')->willReturn($this->adapterInterface); |
| 162 | + $this->schemaSetupInterface |
| 163 | + ->method('getTable') |
| 164 | + ->withConsecutive( |
| 165 | + ['setup_module'], |
| 166 | + ['session'], |
| 167 | + ['cache'], |
| 168 | + ['cache_tag'], |
| 169 | + ['flag'] |
| 170 | + )->willReturnOnConsecutiveCalls( |
| 171 | + 'setup_module', |
| 172 | + 'session', |
| 173 | + 'cache', |
| 174 | + 'cache_tag', |
| 175 | + 'flag' |
| 176 | + ); |
| 177 | + $this->setupFactory = $this->createMock(SetupFactory::class); |
| 178 | + $this->setupFactory->method('create')->willReturn($this->schemaSetupInterface); |
| 179 | + $this->installer = $objectManager->getObject( |
| 180 | + Installer::class, |
| 181 | + [ |
| 182 | + 'objectManagerProvider' => $this->objectManagerProvider, |
| 183 | + 'deploymentConfig'=>$this->deploymentConfig, |
| 184 | + 'setupFactory'=>$this->setupFactory, |
| 185 | + 'moduleList'=>$this->moduleListInterface, |
| 186 | + ] |
| 187 | + ); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * @covers \Magento\MessageQueue\Setup\Recurring |
| 192 | + */ |
| 193 | + public function testChangeVersion(): void |
| 194 | + { |
| 195 | + $this->poisonPillPut->expects(self::once())->method('put'); |
| 196 | + $this->installer->installSchema( |
| 197 | + [ |
| 198 | + 'keep-generated'=>false, |
| 199 | + 'convert-old-scripts'=>false, |
| 200 | + 'help'=>false, |
| 201 | + 'quiet'=>false, |
| 202 | + 'verbose'=>false, |
| 203 | + 'version'=>false, |
| 204 | + 'ansi'=>false, |
| 205 | + 'no-ansi'=>false, |
| 206 | + 'no-interaction'=>false, |
| 207 | + ] |
| 208 | + ); |
| 209 | + } |
| 210 | +} |
0 commit comments