@@ -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,9 +27,6 @@ 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
/**
@@ -43,7 +35,7 @@ protected function setUp()
43
35
public function testGetProductsIfOneOfChildIsDisabled ()
44
36
{
45
37
$ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
46
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
38
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
47
39
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
48
40
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
49
41
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -62,7 +54,8 @@ public function testGetProductsIfOneOfChildIsDisabled()
62
54
$ this ->productRepository ->save ($ lowestPriceChildProduct );
63
55
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
64
56
65
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
57
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
58
+
66
59
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
67
60
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
68
61
$ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -74,7 +67,7 @@ public function testGetProductsIfOneOfChildIsDisabled()
74
67
public function testGetProductsIfOneOfChildIsDisabledPerStore ()
75
68
{
76
69
$ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
77
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
70
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
78
71
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
79
72
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
80
73
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -94,7 +87,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
94
87
$ this ->productRepository ->save ($ lowestPriceChildProduct );
95
88
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
96
89
97
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
90
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
98
91
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
99
92
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
100
93
$ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -106,7 +99,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
106
99
public function testGetProductsIfOneOfChildIsOutOfStock ()
107
100
{
108
101
$ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
109
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
102
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
110
103
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
111
104
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
112
105
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -121,10 +114,21 @@ public function testGetProductsIfOneOfChildIsOutOfStock()
121
114
$ stockItem = $ lowestPriceChildProduct ->getExtensionAttributes ()->getStockItem ();
122
115
$ stockItem ->setIsInStock (0 );
123
116
$ this ->productRepository ->save ($ lowestPriceChildProduct );
124
-
125
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
117
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
126
118
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
127
119
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
128
120
$ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
129
121
}
122
+
123
+ /**
124
+ * As LowestPriceOptionsProviderInterface used multiple times in scope
125
+ * of one test we need to always recreate it and prevent internal caching in property
126
+ * @return LowestPriceOptionsProviderInterface
127
+ */
128
+ private function createLowestPriceOptionsProvider ()
129
+ {
130
+ return Bootstrap::getObjectManager ()->create (
131
+ LowestPriceOptionsProviderInterface::class
132
+ );
133
+ }
130
134
}
0 commit comments