|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Setup\Console\Command; |
| 7 | + |
| 8 | +use Magento\Framework\App\ObjectManagerFactory; |
| 9 | +use Magento\Framework\App\ResourceConnection; |
| 10 | +use Magento\Framework\Console\Cli; |
| 11 | +use Magento\Framework\ObjectManagerInterface; |
| 12 | +use Magento\Indexer\Console\Command\IndexerReindexCommand; |
| 13 | +use Magento\Setup\Fixtures\FixtureModel; |
| 14 | +use Magento\TestFramework\Helper\Bootstrap; |
| 15 | +use Symfony\Component\Console\Tester\CommandTester; |
| 16 | + |
| 17 | +/** |
| 18 | + * Class GenerateFixturesCommandCommandTest |
| 19 | + * @package Magento\Setup\Console\Command |
| 20 | + */ |
| 21 | +class GenerateFixturesCommandTest extends \Magento\TestFramework\Indexer\TestCase |
| 22 | +{ |
| 23 | + /** @var CommandTester */ |
| 24 | + private $indexerCommand; |
| 25 | + |
| 26 | + /** @var FixtureModel */ |
| 27 | + private $fixtureModelMock; |
| 28 | + |
| 29 | + /** @var ObjectManagerInterface */ |
| 30 | + private $objectManager; |
| 31 | + |
| 32 | + /** @var GenerateFixturesCommand */ |
| 33 | + private $command; |
| 34 | + |
| 35 | + /** @var CommandTester */ |
| 36 | + private $commandTester; |
| 37 | + |
| 38 | + /** |
| 39 | + * Setup |
| 40 | + */ |
| 41 | + public function setUp() |
| 42 | + { |
| 43 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 44 | + |
| 45 | + $this->objectManager->get(\Magento\TestFramework\App\Config::class)->clean(); |
| 46 | + |
| 47 | + $this->fixtureModelMock = $this->getMockBuilder(FixtureModel::class) |
| 48 | + ->setMethods(['getObjectManager']) |
| 49 | + ->setConstructorArgs([$this->objectManager->get(IndexerReindexCommand::class)]) |
| 50 | + ->getMock(); |
| 51 | + $this->fixtureModelMock |
| 52 | + ->method('getObjectManager') |
| 53 | + ->willReturn($this->objectManager); |
| 54 | + |
| 55 | + $this->command = $this->objectManager->create( |
| 56 | + GenerateFixturesCommand::class, |
| 57 | + [ |
| 58 | + 'fixtureModel' => $this->fixtureModelMock |
| 59 | + ] |
| 60 | + ); |
| 61 | + |
| 62 | + $objectFactoryMock = $this->getMockBuilder(ObjectManagerFactory::class) |
| 63 | + ->setMethods(['create']) |
| 64 | + ->disableOriginalConstructor() |
| 65 | + ->getMock(); |
| 66 | + $objectFactoryMock |
| 67 | + ->method('create') |
| 68 | + ->willReturn($this->objectManager); |
| 69 | + |
| 70 | + $this->indexerCommand = new CommandTester($this->objectManager->create( |
| 71 | + IndexerReindexCommand::class, |
| 72 | + ['objectManagerFactory' => $objectFactoryMock] |
| 73 | + )); |
| 74 | + |
| 75 | + $this->commandTester = new CommandTester($this->command); |
| 76 | + |
| 77 | + $this->setIncrement(3); |
| 78 | + |
| 79 | + parent::setUp(); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @return string |
| 84 | + */ |
| 85 | + private function getEdition() |
| 86 | + { |
| 87 | + return trim(file_get_contents(__DIR__ . '/_files/edition')); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * teardown |
| 92 | + */ |
| 93 | + public function tearDown() |
| 94 | + { |
| 95 | + $this->setIncrement(1); |
| 96 | + |
| 97 | + parent::tearDown(); |
| 98 | + } |
| 99 | + |
| 100 | + public static function setUpBeforeClass() |
| 101 | + { |
| 102 | + $db = Bootstrap::getInstance()->getBootstrap() |
| 103 | + ->getApplication() |
| 104 | + ->getDbInstance(); |
| 105 | + if (!$db->isDbDumpExists()) { |
| 106 | + throw new \LogicException('DB dump does not exist.'); |
| 107 | + } |
| 108 | + $db->restoreFromDbDump(); |
| 109 | + |
| 110 | + parent::setUpBeforeClass(); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * @magentoAppArea adminhtml |
| 115 | + * @magentoAppIsolation enabled |
| 116 | + */ |
| 117 | + public function testExecute() |
| 118 | + { |
| 119 | + $profile = BP . "/setup/performance-toolkit/profiles/{$this->getEdition()}/small.xml"; |
| 120 | + $this->commandTester->execute( |
| 121 | + [ |
| 122 | + GenerateFixturesCommand::PROFILE_ARGUMENT => $profile, |
| 123 | + '--' . GenerateFixturesCommand::SKIP_REINDEX_OPTION => true |
| 124 | + ] |
| 125 | + ); |
| 126 | + $this->indexerCommand->execute([]); |
| 127 | + |
| 128 | + static::assertEquals( |
| 129 | + Cli::RETURN_SUCCESS, |
| 130 | + $this->indexerCommand->getStatusCode(), |
| 131 | + $this->indexerCommand->getDisplay(true) |
| 132 | + ); |
| 133 | + |
| 134 | + static::assertEquals( |
| 135 | + Cli::RETURN_SUCCESS, |
| 136 | + $this->commandTester->getStatusCode(), |
| 137 | + $this->commandTester->getDisplay(true) |
| 138 | + ); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * @param $value |
| 143 | + */ |
| 144 | + private function setIncrement($value) |
| 145 | + { |
| 146 | + /** @var \Magento\Framework\DB\Adapter\AdapterInterface $db */ |
| 147 | + $db = Bootstrap::getObjectManager()->get(ResourceConnection::class)->getConnection(); |
| 148 | + $db->query("SET @@session.auto_increment_increment=$value"); |
| 149 | + $db->query("SET @@session.auto_increment_offset=$value"); |
| 150 | + } |
| 151 | +} |
0 commit comments