Skip to content

Commit 3334660

Browse files
committed
MAGETWO-87613: Set auto increment to 3 for Performance test plan
1 parent 3aa0a16 commit 3334660

File tree

4 files changed

+163
-4
lines changed

4 files changed

+163
-4
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ce

setup/src/Magento/Setup/Fixtures/OrdersFixture.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ public function execute()
232232
return;
233233
}
234234

235+
$ruleId = $this->getMaxEntityId(
236+
'salesrule',
237+
\Magento\SalesRule\Model\ResourceModel\Rule::class,
238+
'rule_id'
239+
);
240+
235241
$maxItemId = $this->getMaxEntityId(
236242
'sales_order_item',
237243
\Magento\Sales\Model\ResourceModel\Order\Item::class,
@@ -330,6 +336,7 @@ public function execute()
330336
'%productStoreId%' => $productStoreId($entityId),
331337
'%productStoreName%' => $productStoreName($entityId),
332338
'%entityId%' => $entityId,
339+
'%ruleId%' => $ruleId,
333340
];
334341
$shippingAddress = ['%orderAddressId%' => $entityId * 2 - 1, '%addressType%' => 'shipping'];
335342
$billingAddress = ['%orderAddressId%' => $entityId * 2, '%addressType%' => 'billing'];

setup/src/Magento/Setup/Fixtures/_files/orders_fixture_data.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"weight": 2.0000,
103103
"customer_dob": "NULL",
104104
"increment_id": "'%orderNumber%'",
105-
"applied_rule_ids": 1,
105+
"applied_rule_ids": "%ruleId%",
106106
"base_currency_code": "'USD'",
107107
"customer_email": "'%email%'",
108108
"customer_firstname": "NULL",
@@ -208,7 +208,7 @@
208208
"sku": "'%sku%'",
209209
"name": "'%name%'",
210210
"description": "NULL",
211-
"applied_rule_ids": "'1'",
211+
"applied_rule_ids": "'%ruleId%'",
212212
"additional_data": "NULL",
213213
"is_qty_decimal": "'0'",
214214
"no_discount": "'0'",
@@ -374,7 +374,7 @@
374374
"customer_note_notify": 1,
375375
"customer_is_guest": 1,
376376
"remote_ip": "'127.0.0.1'",
377-
"applied_rule_ids": "'1'",
377+
"applied_rule_ids": "'%ruleId%'",
378378
"reserved_order_id": "NULL",
379379
"password_hash": "NULL",
380380
"coupon_code": "NULL",
@@ -512,7 +512,7 @@
512512
"sku": "'%sku%'",
513513
"name": "'%name%'",
514514
"description": "NULL",
515-
"applied_rule_ids": "'1'",
515+
"applied_rule_ids": "'%ruleId%'",
516516
"additional_data": "NULL",
517517
"is_qty_decimal": "0",
518518
"no_discount": "0",

0 commit comments

Comments
 (0)