Skip to content

Commit f9fb638

Browse files
committed
Merge branch 'ACP2E-1543' of https://github.com/magento-l3/magento2ce into PR-2023-02-07
2 parents ba03d89 + 6f72057 commit f9fb638

File tree

14 files changed

+767
-97
lines changed

14 files changed

+767
-97
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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\Email\Test\Fixture;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\DataObject;
12+
use Magento\Framework\DataObjectFactory;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Serialize\Serializer\Json;
15+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
16+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
17+
18+
class FileTransport implements RevertibleDataFixtureInterface
19+
{
20+
private const DEFAULT_DATA = [
21+
'directory' => DirectoryList::TMP,
22+
'path' => 'mail/%uniqid%',
23+
];
24+
25+
private const CONFIG_FILE = 'mail-transport-config.json';
26+
27+
/**
28+
* @var Filesystem
29+
*/
30+
private Filesystem $filesystem;
31+
32+
/**
33+
* @var Json
34+
*/
35+
private Json $json;
36+
37+
/**
38+
* @var ProcessorInterface
39+
*/
40+
private ProcessorInterface $dataProcessor;
41+
42+
/**
43+
* @var DataObjectFactory
44+
*/
45+
private DataObjectFactory $dataObjectFactory;
46+
47+
/**
48+
* @param Filesystem $filesystem
49+
* @param Json $json
50+
* @param ProcessorInterface $dataProcessor
51+
* @param DataObjectFactory $dataObjectFactory
52+
*/
53+
public function __construct(
54+
Filesystem $filesystem,
55+
Json $json,
56+
ProcessorInterface $dataProcessor,
57+
DataObjectFactory $dataObjectFactory
58+
) {
59+
$this->filesystem = $filesystem;
60+
$this->json = $json;
61+
$this->dataProcessor = $dataProcessor;
62+
$this->dataObjectFactory = $dataObjectFactory;
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
* @param array $data Parameters
68+
* <pre>
69+
* $data = [
70+
* 'directory' => (string) Filesystem directory code. Optional. Default: tmp dir
71+
* 'path' => (string) Relative path to "directory" where to save mails. Optional. Default: autogenerated
72+
* ]
73+
* </pre>
74+
*/
75+
public function apply(array $data = []): ?DataObject
76+
{
77+
$data = $this->dataProcessor->process($this, array_merge(self::DEFAULT_DATA, $data));
78+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
79+
$directory->writeFile(self::CONFIG_FILE, $this->json->serialize($data));
80+
81+
return $this->dataObjectFactory->create(['data' => $data]);
82+
}
83+
84+
/**
85+
* @inheritDoc
86+
*/
87+
public function revert(DataObject $data): void
88+
{
89+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
90+
$config = $this->json->unserialize($directory->readFile(self::CONFIG_FILE));
91+
$directory->delete(self::CONFIG_FILE);
92+
$directory = $this->filesystem->getDirectoryWrite($config['directory']);
93+
$directory->delete($config['path']);
94+
}
95+
}

app/code/Magento/Store/Model/App/Emulation.php

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,44 @@
99
*/
1010
namespace Magento\Store\Model\App;
1111

12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\Locale\ResolverInterface;
15+
use Magento\Framework\Phrase;
16+
use Magento\Framework\Phrase\RendererInterface;
1217
use Magento\Framework\Translate\Inline\ConfigInterface;
18+
use Magento\Framework\Translate\Inline\StateInterface;
19+
use Magento\Framework\TranslateInterface;
20+
use Magento\Framework\View\DesignInterface;
21+
use Magento\Store\Model\StoreManagerInterface;
22+
use Psr\Log\LoggerInterface;
1323

1424
/**
1525
* @api
1626
* @since 100.0.2
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1728
*/
1829
class Emulation extends \Magento\Framework\DataObject
1930
{
2031
/**
21-
* @var \Magento\Store\Model\StoreManagerInterface
32+
* @var StoreManagerInterface
2233
*/
2334
protected $_storeManager;
2435

2536
/**
26-
* @var \Magento\Framework\TranslateInterface
37+
* @var TranslateInterface
2738
*/
2839
protected $_translate;
2940

3041
/**
3142
* Core store config
3243
*
33-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
44+
* @var ScopeConfigInterface
3445
*/
3546
protected $_scopeConfig;
3647

3748
/**
38-
* @var \Magento\Framework\Locale\ResolverInterface
49+
* @var ResolverInterface
3950
*/
4051
protected $_localeResolver;
4152

@@ -50,7 +61,7 @@ class Emulation extends \Magento\Framework\DataObject
5061
protected $inlineConfig;
5162

5263
/**
53-
* @var \Magento\Framework\Translate\Inline\StateInterface
64+
* @var StateInterface
5465
*/
5566
protected $inlineTranslation;
5667

@@ -62,39 +73,46 @@ class Emulation extends \Magento\Framework\DataObject
6273
private $initialEnvironmentInfo;
6374

6475
/**
65-
* @var \Psr\Log\LoggerInterface
76+
* @var LoggerInterface
6677
*/
6778
private $logger;
6879

6980
/**
70-
* @var \Magento\Framework\View\DesignInterface
81+
* @var DesignInterface
7182
*/
7283
private $_viewDesign;
7384

7485
/**
75-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
76-
* @param \Magento\Framework\View\DesignInterface $viewDesign
86+
* @var RendererInterface
87+
*/
88+
private $phraseRenderer;
89+
90+
/**
91+
* @param StoreManagerInterface $storeManager
92+
* @param DesignInterface $viewDesign
7793
* @param \Magento\Framework\App\DesignInterface $design
78-
* @param \Magento\Framework\TranslateInterface $translate
79-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
94+
* @param TranslateInterface $translate
95+
* @param ScopeConfigInterface $scopeConfig
8096
* @param ConfigInterface $inlineConfig
81-
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
82-
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
83-
* @param \Psr\Log\LoggerInterface $logger
97+
* @param StateInterface $inlineTranslation
98+
* @param ResolverInterface $localeResolver
99+
* @param LoggerInterface $logger
84100
* @param array $data
101+
* @param RendererInterface|null $phraseRenderer
85102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
86103
*/
87104
public function __construct(
88-
\Magento\Store\Model\StoreManagerInterface $storeManager,
89-
\Magento\Framework\View\DesignInterface $viewDesign,
105+
StoreManagerInterface $storeManager,
106+
DesignInterface $viewDesign,
90107
\Magento\Framework\App\DesignInterface $design,
91-
\Magento\Framework\TranslateInterface $translate,
92-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
108+
TranslateInterface $translate,
109+
ScopeConfigInterface $scopeConfig,
93110
ConfigInterface $inlineConfig,
94-
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
95-
\Magento\Framework\Locale\ResolverInterface $localeResolver,
96-
\Psr\Log\LoggerInterface $logger,
97-
array $data = []
111+
StateInterface $inlineTranslation,
112+
ResolverInterface $localeResolver,
113+
LoggerInterface $logger,
114+
array $data = [],
115+
?RendererInterface $phraseRenderer = null
98116
) {
99117
$this->_localeResolver = $localeResolver;
100118
parent::__construct($data);
@@ -106,6 +124,8 @@ public function __construct(
106124
$this->inlineConfig = $inlineConfig;
107125
$this->inlineTranslation = $inlineTranslation;
108126
$this->logger = $logger;
127+
$this->phraseRenderer = $phraseRenderer
128+
?? ObjectManager::getInstance()->get(RendererInterface::class);
109129
}
110130

111131
/**
@@ -158,6 +178,7 @@ public function startEnvironmentEmulation(
158178
$this->_localeResolver->setLocale($newLocaleCode);
159179
$this->_translate->setLocale($newLocaleCode);
160180
$this->_translate->loadData($area);
181+
Phrase::setRenderer($this->phraseRenderer);
161182
}
162183

163184
/**
@@ -179,7 +200,7 @@ public function stopEnvironmentEmulation()
179200
// Current store needs to be changed right before locale change and after design change
180201
$this->_storeManager->setCurrentStore($initialDesign['store']);
181202
$this->_restoreInitialLocale($this->initialEnvironmentInfo->getInitialLocaleCode(), $initialDesign['area']);
182-
203+
Phrase::setRenderer($this->initialEnvironmentInfo->getPhraseRenderer());
183204
$this->initialEnvironmentInfo = null;
184205
return $this;
185206
}
@@ -202,6 +223,8 @@ public function storeCurrentEnvironmentInfo()
202223
]
203224
)->setInitialLocaleCode(
204225
$this->_localeResolver->getLocale()
226+
)->setPhraseRenderer(
227+
Phrase::getRenderer()
205228
);
206229
}
207230

app/code/Magento/Store/Test/Fixture/Store.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
1717
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
1818

19+
/**
20+
* Store Fixture
21+
*
22+
* This fixture may result in DDL operations that cannot be executed within a transaction.
23+
* In case DB isolation is enabled, it is recommended to use "DataFixtureBeforeTransaction" instead of "DataFixture"
24+
*/
1925
class Store implements RevertibleDataFixtureInterface
2026
{
2127
private const DEFAULT_DATA = [
@@ -93,7 +99,7 @@ public function apply(array $data = []): ?DataObject
9399
$store->setData($this->prepareData($data));
94100
$this->storeResource->save($store);
95101
$this->storeManager->reinitStores();
96-
$this->regenerateSequenceTables((int)$store->getId());
102+
$this->sequence->generate((int) $store->getId());
97103
return $store;
98104
}
99105

@@ -134,19 +140,4 @@ private function prepareData(array $data): array
134140

135141
return $this->dataProcessor->process($this, $data);
136142
}
137-
138-
/**
139-
* Generate missing sequence tables
140-
*
141-
* @param int $storeId
142-
*
143-
* @return void
144-
*/
145-
private function regenerateSequenceTables(int $storeId): void
146-
{
147-
if ($storeId >= 10) {
148-
$n = $storeId + 1;
149-
$this->sequence->generateSequences($n);
150-
}
151-
}
152143
}

0 commit comments

Comments
 (0)