@@ -18,11 +18,6 @@ class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
18
18
*/
19
19
private $ storeManager ;
20
20
21
- /**
22
- * @var LowestPriceOptionsProviderInterface
23
- */
24
- private $ lowestPriceOptionsProvider ;
25
-
26
21
/**
27
22
* @var ProductRepositoryInterface
28
23
*/
@@ -32,21 +27,18 @@ protected function setUp()
32
27
{
33
28
$ this ->storeManager = Bootstrap::getObjectManager ()->get (StoreManagerInterface::class);
34
29
$ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
35
- $ this ->lowestPriceOptionsProvider = Bootstrap::getObjectManager ()->get (
36
- LowestPriceOptionsProviderInterface::class
37
- );
38
30
}
39
31
40
32
/**
41
33
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
42
34
*/
43
35
public function testGetProductsIfOneOfChildIsDisabled ()
44
36
{
45
- $ configurableProduct = $ this ->productRepository ->getById ( 1 , false , null , true );
46
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
47
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
37
+ $ configurableProduct = $ this ->productRepository ->get ( ' configurable ' , false , null , true );
38
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
39
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
48
40
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
49
- $ this -> assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
41
+ self :: assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
50
42
51
43
// load full aggregation root
52
44
$ lowestPriceChildProduct = $ this ->productRepository ->get (
@@ -62,22 +54,22 @@ public function testGetProductsIfOneOfChildIsDisabled()
62
54
$ this ->productRepository ->save ($ lowestPriceChildProduct );
63
55
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
64
56
65
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
66
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
57
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
58
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
67
59
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
68
- $ this -> assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
60
+ self :: assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
69
61
}
70
62
71
63
/**
72
64
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
73
65
*/
74
66
public function testGetProductsIfOneOfChildIsDisabledPerStore ()
75
67
{
76
- $ configurableProduct = $ this ->productRepository ->getById ( 1 , false , null , true );
77
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
78
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
68
+ $ configurableProduct = $ this ->productRepository ->get ( ' configurable ' , false , null , true );
69
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
70
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
79
71
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
80
- $ this -> assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
72
+ self :: assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
81
73
82
74
// load full aggregation root
83
75
$ lowestPriceChildProduct = $ this ->productRepository ->get (
@@ -94,22 +86,22 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
94
86
$ this ->productRepository ->save ($ lowestPriceChildProduct );
95
87
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
96
88
97
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
98
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
89
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
90
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
99
91
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
100
- $ this -> assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
92
+ self :: assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
101
93
}
102
94
103
95
/**
104
96
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
105
97
*/
106
98
public function testGetProductsIfOneOfChildIsOutOfStock ()
107
99
{
108
- $ configurableProduct = $ this ->productRepository ->getById ( 1 , false , null , true );
109
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
110
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
100
+ $ configurableProduct = $ this ->productRepository ->get ( ' configurable ' , false , null , true );
101
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
102
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
111
103
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
112
- $ this -> assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
104
+ self :: assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
113
105
114
106
// load full aggregation root
115
107
$ lowestPriceChildProduct = $ this ->productRepository ->get (
@@ -121,11 +113,10 @@ public function testGetProductsIfOneOfChildIsOutOfStock()
121
113
$ stockItem = $ lowestPriceChildProduct ->getExtensionAttributes ()->getStockItem ();
122
114
$ stockItem ->setIsInStock (0 );
123
115
$ this ->productRepository ->save ($ lowestPriceChildProduct );
124
-
125
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
126
- $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
116
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
117
+ self ::assertCount (1 , $ lowestPriceChildrenProducts );
127
118
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
128
- $ this -> assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
119
+ self :: assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
129
120
}
130
121
131
122
/**
@@ -135,10 +126,10 @@ public function testGetProductsIfOneOfChildIsOutOfStock()
135
126
public function testGetProductsIfOneOfChildrenIsAssignedToOtherWebsite ()
136
127
{
137
128
$ configurableProduct = $ this ->productRepository ->getById (1 , false , null , true );
138
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
139
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
129
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
130
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
140
131
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
141
- $ this -> assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
132
+ self :: assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
142
133
143
134
/** @var \Magento\Store\Api\WebsiteRepositoryInterface $webSiteRepository */
144
135
$ webSiteRepository = Bootstrap::getObjectManager ()->get (\Magento \Store \Api \WebsiteRepositoryInterface::class);
@@ -150,9 +141,21 @@ public function testGetProductsIfOneOfChildrenIsAssignedToOtherWebsite()
150
141
$ lowestPriceChildrenProduct ->setExtensionAttributes ($ attributes );
151
142
$ this ->productRepository ->save ($ lowestPriceChildrenProduct );
152
143
153
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
154
- $ this -> assertCount (1 , $ lowestPriceChildrenProducts );
144
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
145
+ self :: assertCount (1 , $ lowestPriceChildrenProducts );
155
146
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
156
- $ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
147
+ self ::assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
148
+ }
149
+
150
+ /**
151
+ * As LowestPriceOptionsProviderInterface used multiple times in scope
152
+ * of one test we need to always recreate it and prevent internal caching in property
153
+ * @return LowestPriceOptionsProviderInterface
154
+ */
155
+ private function createLowestPriceOptionsProvider ()
156
+ {
157
+ return Bootstrap::getObjectManager ()->create (
158
+ LowestPriceOptionsProviderInterface::class
159
+ );
157
160
}
158
161
}
0 commit comments