Skip to content

Commit 38740f3

Browse files
authored
Merge branch '2.4-develop' into MCP-1010
2 parents 8552357 + 1c8d02b commit 38740f3

File tree

5 files changed

+124
-45
lines changed

5 files changed

+124
-45
lines changed

dev/tests/static/testsuite/Magento/Test/Legacy/LegacyFixtureTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testNew(): void
3434
|| (
3535
strpos($file, 'dev/tests/') === false
3636
&& preg_match('/app\/code\/.*\/Test.*\/(_files|Fixtures)/', $file)
37+
&& !preg_match('/app\/code\/.*\/Tests?\/Performance\/(_files|Fixtures)/', $file)
3738
)
3839
)
3940
) {

setup/performance-toolkit/profiles/ce/small.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<websites>1</websites> <!-- Number of websites to generate -->
1212
<store_groups>1</store_groups> <!--Number of stores-->
1313
<store_views>1</store_views> <!-- Number of store views -->
14+
<sources>1</sources> <!-- Number of sources to generate -->
15+
<stocks>1</stocks> <!-- Number of stocks to generate -->
1416
<assign_entities_to_all_websites>0</assign_entities_to_all_websites> <!-- Whether to assign all products per each website -->
1517
<simple_products>800</simple_products> <!-- Simple products count -->
1618
<configurable_products> <!-- Configurable product -->

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

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
*/
2020
class FixtureModel
2121
{
22-
/**
23-
* Area code
24-
*/
25-
const AREA_CODE = 'adminhtml';
22+
public const AREA_CODE = 'adminhtml';
2623

2724
/**
2825
* Fixtures file name pattern
2926
*/
30-
const FIXTURE_PATTERN = '?*Fixture.php';
27+
private const FIXTURE_PATTERN = '?*Fixture.php';
3128

3229
/**
3330
* Application object
@@ -44,14 +41,14 @@ class FixtureModel
4441
/**
4542
* List of fixtures applied to the application
4643
*
47-
* @var \Magento\Setup\Fixtures\Fixture[]
44+
* @var Fixture[]
4845
*/
4946
protected $fixtures = [];
5047

5148
/**
5249
* List of fixtures indexed by class names
5350
*
54-
* @var \Magento\Setup\Fixtures\Fixture[]
51+
* @var Fixture[]
5552
*/
5653
private $fixturesByNames = [];
5754

@@ -109,35 +106,63 @@ public function reindex(OutputInterface $output)
109106
public function loadFixtures()
110107
{
111108
$files = glob(__DIR__ . DIRECTORY_SEPARATOR . self::FIXTURE_PATTERN, GLOB_NOSORT);
112-
113109
foreach ($files as $file) {
114110
$file = basename($file, '.php');
115-
/** @var \Magento\Setup\Fixtures\Fixture $fixture */
111+
/** @var Fixture $fixture */
116112
$type = 'Magento\Setup\Fixtures' . '\\' . $file;
117113
$fixture = $this->getObjectManager()->create(
118114
$type,
119115
[
120116
'fixtureModel' => $this,
121117
]
122118
);
123-
124-
if (isset($this->fixtures[$fixture->getPriority()])) {
125-
throw new \InvalidArgumentException(
126-
sprintf('Duplicate priority %d in fixture %s', $fixture->getPriority(), $type)
127-
);
128-
}
129-
130-
if ($fixture->getPriority() >= 0) {
131-
$this->fixtures[$fixture->getPriority()] = $fixture;
132-
}
133-
134-
$this->fixturesByNames[get_class($fixture)] = $fixture;
119+
$this->loadFixture($fixture);
120+
}
121+
foreach ($this->getFixturesFromRegistry() as $fixture) {
122+
$this->loadFixture($fixture);
135123
}
136-
137124
ksort($this->fixtures);
138125
return $this;
139126
}
140127

128+
/**
129+
* Gets Fixtures from FixtureRegistry and gets instances of them from ObjectManager
130+
*
131+
* @return array
132+
*/
133+
private function getFixturesFromRegistry() : array
134+
{
135+
$fixtureRegistry = $this->getObjectManager()->create(FixtureRegistry::class);
136+
$fixtures = [];
137+
foreach ($fixtureRegistry->getFixtures() as $fixtureClassName) {
138+
$fixtures[] = $this->getObjectManager()->create(
139+
$fixtureClassName,
140+
['fixtureModel' => $this]
141+
);
142+
}
143+
return $fixtures;
144+
}
145+
146+
/**
147+
* Loads fixture into $this->fixturesByName and $this->fixtures
148+
*
149+
* @param Fixture $fixture
150+
* @return void
151+
*/
152+
private function loadFixture(Fixture $fixture)
153+
{
154+
$fixtureClassName = get_class($fixture);
155+
if (isset($this->fixtures[$fixture->getPriority()])) {
156+
throw new \InvalidArgumentException(
157+
sprintf('Duplicate priority %d in fixture %s', $fixture->getPriority(), $fixtureClassName)
158+
);
159+
}
160+
if ($fixture->getPriority() >= 0) {
161+
$this->fixtures[$fixture->getPriority()] = $fixture;
162+
}
163+
$this->fixturesByNames[$fixtureClassName] = $fixture;
164+
}
165+
141166
/**
142167
* Get param labels
143168
*
@@ -161,8 +186,9 @@ public function getFixtures()
161186

162187
/**
163188
* Returns fixture by name
164-
* @param $name string
165-
* @return \Magento\Setup\Fixtures\Fixture
189+
*
190+
* @param string $name
191+
* @return Fixture
166192
* @throws \Magento\Setup\Exception
167193
*/
168194
public function getFixtureByName($name)
@@ -236,14 +262,15 @@ public function resetObjectManager()
236262
}
237263

238264
/**
265+
* Gets instance of FixtureConfig from ObjectManager
266+
*
239267
* @return FixtureConfig
240268
*/
241269
private function getConfig()
242270
{
243271
if (null === $this->config) {
244272
$this->config = $this->getObjectManager()->get(FixtureConfig::class);
245273
}
246-
247274
return $this->config;
248275
}
249276

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
/**
10+
* Registry for fixtures
11+
*/
12+
namespace Magento\Setup\Fixtures;
13+
14+
class FixtureRegistry
15+
{
16+
17+
/**
18+
* List of fixtures applied to the application
19+
*
20+
* @var string[]
21+
*/
22+
private $fixtures = [];
23+
24+
/**
25+
* @param string[] $fixtures
26+
*/
27+
public function __construct(array $fixtures = [])
28+
{
29+
$this->fixtures = $fixtures;
30+
}
31+
32+
/**
33+
* Get fixtures
34+
*
35+
* @return string[]
36+
*/
37+
public function getFixtures() :array
38+
{
39+
return $this->fixtures;
40+
}
41+
}

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
*/
4242
class StoresFixture extends Fixture
4343
{
44-
const DEFAULT_WEBSITE_COUNT = 1;
44+
private const DEFAULT_WEBSITE_COUNT = 1;
4545

46-
const DEFAULT_STORE_COUNT = 1;
46+
private const DEFAULT_STORE_COUNT = 1;
4747

48-
const DEFAULT_STORE_VIEW_COUNT = 1;
48+
private const DEFAULT_STORE_VIEW_COUNT = 1;
4949

5050
/**
5151
* @var int
@@ -132,6 +132,11 @@ class StoresFixture extends Fixture
132132
*/
133133
private $storeViewIds;
134134

135+
/**
136+
* @var string[]
137+
*/
138+
private $websiteCodes = [];
139+
135140
/**
136141
* @var ManagerInterface
137142
*/
@@ -173,7 +178,8 @@ public function __construct(
173178
}
174179

175180
/**
176-
* {@inheritdoc}
181+
* @inheritdoc
182+
*
177183
* @SuppressWarnings(PHPMD)
178184
*/
179185
public function execute()
@@ -183,44 +189,38 @@ public function execute()
183189
$this->storeGroupsCount = $this->fixtureModel->getValue('store_groups', self::DEFAULT_STORE_COUNT);
184190
$this->storesCount = $this->fixtureModel->getValue('store_views', self::DEFAULT_STORE_VIEW_COUNT);
185191
$this->singleRootCategory = (bool)$this->fixtureModel->getValue('assign_entities_to_all_websites', false);
186-
187192
if ($this->websitesCount <= self::DEFAULT_WEBSITE_COUNT
188193
&& $this->storeGroupsCount <= self::DEFAULT_STORE_COUNT
189194
&& $this->storesCount <= self::DEFAULT_STORE_VIEW_COUNT
190195
) {
191196
return;
192197
}
193-
194198
//Get existing entities counts
195199
$storeGroups = $this->storeManager->getGroups();
196200
$this->storeGroupsIds= array_keys($storeGroups);
197-
198201
foreach ($storeGroups as $storeGroupId => $storeGroup) {
199202
$this->storeGroupsToWebsites[$storeGroupId] = $storeGroup->getWebsiteId();
200203
}
201-
202204
$this->websiteIds = array_values(array_unique($this->storeGroupsToWebsites));
203-
204205
$this->defaultWebsite = $this->storeManager->getWebsite();
205206
$this->defaultStoreGroup = $this->storeManager->getGroup();
206207
$this->defaultWebsiteId = $this->defaultWebsite->getId();
207208
$this->defaultStoreGroupId = $this->defaultStoreGroup->getId();
208209
$this->defaultStoreView = $this->storeManager->getDefaultStoreView();
209210
$this->storeViewIds = array_keys($this->storeManager->getStores());
210-
211211
$this->generateWebsites();
212212
$this->generateStoreGroups();
213213
$this->generateStoreViews();
214214
}
215215

216216
/**
217217
* Generating web sites
218+
*
218219
* @return void
219220
*/
220221
private function generateWebsites()
221222
{
222223
$existedWebsitesCount = count($this->websiteIds) + self::DEFAULT_WEBSITE_COUNT;
223-
224224
while ($existedWebsitesCount <= $this->websitesCount) {
225225
$website = clone $this->defaultWebsite;
226226
$websiteCode = sprintf('website_%d', $existedWebsitesCount);
@@ -236,23 +236,23 @@ private function generateWebsites()
236236
$website->save();
237237
$this->websiteIds[] = $website->getId();
238238
$existedWebsitesCount++;
239+
$this->websiteCodes[] = $websiteCode;
239240
}
240241
}
241242

242243
/**
243244
* Generating store groups ('stores' on frontend)
245+
*
244246
* @return void
245247
*/
246248
private function generateStoreGroups()
247249
{
248250
$existedStoreGroupCount = count($this->storeGroupsIds);
249251
$existedWebsitesCount = count($this->websiteIds);
250-
251252
while ($existedStoreGroupCount < $this->storeGroupsCount) {
252253
$websiteId = $this->websiteIds[$existedStoreGroupCount % $existedWebsitesCount];
253254
$storeGroupName = sprintf('Store Group %d - website_id_%d', ++$existedStoreGroupCount, $websiteId);
254255
$storeGroupCode = sprintf('store_group_%d', $existedStoreGroupCount);
255-
256256
$storeGroup = clone $this->defaultStoreGroup;
257257
$storeGroup->addData(
258258
[
@@ -271,16 +271,15 @@ private function generateStoreGroups()
271271

272272
/**
273273
* Generating store views
274+
*
274275
* @return void
275276
*/
276277
private function generateStoreViews()
277278
{
278279
$localesList = $this->localeConfig->getAllowedLocales();
279280
$localesListCount = count($localesList);
280-
281281
$existedStoreViewsCount = count($this->storeViewIds);
282282
$existedStoreGroupCount = count($this->storeGroupsIds);
283-
284283
while ($existedStoreViewsCount < $this->storesCount) {
285284
$groupId = $this->storeGroupsIds[$existedStoreViewsCount % $existedStoreGroupCount];
286285
$websiteId = $this->storeGroupsToWebsites[$groupId];
@@ -292,7 +291,6 @@ private function generateStoreViews()
292291
$websiteId,
293292
$groupId
294293
);
295-
296294
$store->addData(
297295
[
298296
'store_id' => null,
@@ -302,12 +300,13 @@ private function generateStoreViews()
302300
'code' => $storeCode
303301
]
304302
)->save();
305-
306303
$this->saveStoreLocale($store->getId(), $localesList[$existedStoreViewsCount % $localesListCount]);
307304
}
308305
}
309306

310307
/**
308+
* Saves store into locale
309+
*
311310
* @param int $storeId
312311
* @param string $localeCode
313312
* @return void
@@ -343,21 +342,20 @@ private function getStoreCategoryId($storeGroupName)
343342
->setDefaultSortBy('name')
344343
->setIsActive(true)
345344
->save();
346-
347345
return $category->getId();
348346
}
349347
}
350348

351349
/**
352-
* {@inheritdoc}
350+
* @inheritdoc
353351
*/
354352
public function getActionTitle()
355353
{
356354
return 'Generating websites, stores and store views';
357355
}
358356

359357
/**
360-
* {@inheritdoc}
358+
* @inheritdoc
361359
*/
362360
public function introduceParamLabels()
363361
{
@@ -380,4 +378,14 @@ private function getDefaultCategoryId()
380378
}
381379
return $this->defaultParentCategoryId;
382380
}
381+
382+
/**
383+
* Gets the website codes that were created by this object
384+
*
385+
* @return string[]
386+
*/
387+
public function getWebsiteCodes()
388+
{
389+
return $this->websiteCodes;
390+
}
383391
}

0 commit comments

Comments
 (0)