7
7
namespace Magento \TestFramework \Annotation ;
8
8
9
9
use Magento \Catalog \Model \Indexer \Product \Price \ModeSwitcher ;
10
+ use Magento \Framework \App \Cache \TypeListInterface ;
10
11
use Magento \Framework \App \Config \ConfigResource \ConfigInterface ;
12
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11
13
use Magento \TestFramework \Application ;
12
14
use Magento \TestFramework \App \Config ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
19
21
*/
20
22
class IndexerDimensionMode
21
23
{
22
- private $ modeSwithcer ;
24
+ protected $ cacheTypeList ;
25
+ private $ configReader ;
26
+
27
+ private $ modeSwitcher ;
23
28
24
29
private $ configWriter ;
25
30
@@ -36,28 +41,53 @@ public function __construct(Application $application)
36
41
37
42
private function restoreDb ()
38
43
{
44
+ $ this ->db = Bootstrap::getInstance ()->getBootstrap ()
45
+ ->getApplication ()
46
+ ->getDbInstance ();
39
47
$ this ->db ->restoreFromDbDump ();
48
+ $ this ->cacheTypeList ->cleanType ('config ' );
49
+ $ this ->objectManager ->get (Config::class)->clean ();
40
50
}
41
51
42
52
private function initSwicher ()
43
53
{
44
- if (!$ this ->modeSwithcer ) {
54
+ if (!$ this ->modeSwitcher ) {
45
55
$ this ->objectManager = Bootstrap::getObjectManager ();
46
- $ this ->modeSwithcer = $ this ->objectManager ->get (ModeSwitcher::class);
56
+ $ this ->modeSwitcher = $ this ->objectManager ->get (ModeSwitcher::class);
47
57
$ this ->configWriter = $ this ->objectManager ->get (ConfigInterface::class);
58
+ $ this ->configReader = $ this ->objectManager ->get (ScopeConfigInterface::class);
59
+ $ this ->cacheTypeList = $ this ->objectManager ->get (TypeListInterface::class);
48
60
}
49
61
}
50
62
51
63
/**
52
64
* @param string $mode
53
65
*/
54
- private function setDimensionMode ($ mode = DimensionModeConfiguration:: DIMENSION_WEBSITE_AND_CUSTOMER_GROUP )
66
+ private function setDimensionMode ($ mode, $ test )
55
67
{
56
68
$ this ->initSwicher ();
57
- $ this ->modeSwithcer ->createTables ($ mode );
58
- $ this ->modeSwithcer ->moveData ($ mode , DimensionModeConfiguration::DIMENSION_NONE );
59
- $ this ->configWriter ->saveConfig (ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE , $ mode );
60
- $ this ->objectManager ->get (Config::class)->clean ();
69
+
70
+ $ this ->configReader ->clean ();
71
+ $ previousMode = $ this ->configReader ->getValue (ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE ) ?:
72
+ DimensionModeConfiguration::DIMENSION_NONE ;
73
+
74
+ if ($ previousMode !== $ mode ) {
75
+ //Create new tables and move data
76
+ $ this ->modeSwitcher ->createTables ($ mode );
77
+ $ this ->modeSwitcher ->moveData ($ mode , $ previousMode );
78
+
79
+ //Change config options
80
+ $ this ->configWriter ->saveConfig (ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE , $ mode );
81
+ $ this ->cacheTypeList ->cleanType ('config ' );
82
+ $ this ->objectManager ->get (Config::class)->clean ();
83
+
84
+ //Delete old tables
85
+ $ this ->modeSwitcher ->dropTables ($ previousMode );
86
+
87
+ } else {
88
+ $ this ->fail ('Dimensions mode for indexer has not been changed ' , $ test );
89
+ }
90
+
61
91
}
62
92
63
93
/**
@@ -85,7 +115,7 @@ public function startTest(TestCase $test)
85
115
86
116
if ($ annotations [0 ] == 'price ' ) {
87
117
$ this ->isDimensionMode = true ;
88
- $ this ->setDimensionMode ();
118
+ $ this ->setDimensionMode (DimensionModeConfiguration:: DIMENSION_WEBSITE_AND_CUSTOMER_GROUP , $ test );
89
119
}
90
120
}
91
121
@@ -99,7 +129,6 @@ public function endTest(TestCase $test)
99
129
{
100
130
if ($ this ->isDimensionMode ) {
101
131
$ this ->restoreDb ();
102
- $ this ->objectManager ->get (Config::class)->clean ();
103
132
$ this ->isDimensionMode = false ;
104
133
}
105
134
}
0 commit comments