@@ -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,10 +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
- // create is used for prevent internal caching in property
36
- $ this ->lowestPriceOptionsProvider = Bootstrap::getObjectManager ()->create (
37
- LowestPriceOptionsProviderInterface::class
38
- );
39
30
}
40
31
41
32
/**
@@ -44,7 +35,7 @@ protected function setUp()
44
35
public function testGetProductsIfOneOfChildIsDisabled ()
45
36
{
46
37
$ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
47
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
38
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
48
39
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
49
40
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
50
41
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -63,8 +54,7 @@ public function testGetProductsIfOneOfChildIsDisabled()
63
54
$ this ->productRepository ->save ($ lowestPriceChildProduct );
64
55
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
65
56
66
- $ lowestPriceOptionsProvider = $ this ->recreateLowestPriceOptionsProvider ();
67
- $ lowestPriceChildrenProducts = $ lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
57
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
68
58
69
59
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
70
60
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
@@ -77,7 +67,7 @@ public function testGetProductsIfOneOfChildIsDisabled()
77
67
public function testGetProductsIfOneOfChildIsDisabledPerStore ()
78
68
{
79
69
$ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
80
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
70
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
81
71
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
82
72
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
83
73
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -97,9 +87,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
97
87
$ this ->productRepository ->save ($ lowestPriceChildProduct );
98
88
$ this ->storeManager ->setCurrentStore ($ currentStoreId );
99
89
100
- $ lowestPriceOptionsProvider = $ this ->recreateLowestPriceOptionsProvider ();
101
- $ lowestPriceChildrenProducts = $ lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
102
-
90
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
103
91
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
104
92
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
105
93
$ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -111,7 +99,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
111
99
public function testGetProductsIfOneOfChildIsOutOfStock ()
112
100
{
113
101
$ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
114
- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
102
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
115
103
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
116
104
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
117
105
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -126,19 +114,18 @@ public function testGetProductsIfOneOfChildIsOutOfStock()
126
114
$ stockItem = $ lowestPriceChildProduct ->getExtensionAttributes ()->getStockItem ();
127
115
$ stockItem ->setIsInStock (0 );
128
116
$ this ->productRepository ->save ($ lowestPriceChildProduct );
129
-
130
- $ lowestPriceOptionsProvider = $ this ->recreateLowestPriceOptionsProvider ();
131
- $ lowestPriceChildrenProducts = $ lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
132
-
117
+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
133
118
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
134
119
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
135
120
$ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
136
121
}
137
122
138
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
139
126
* @return LowestPriceOptionsProviderInterface
140
127
*/
141
- private function recreateLowestPriceOptionsProvider ()
128
+ private function createLowestPriceOptionsProvider ()
142
129
{
143
130
return Bootstrap::getObjectManager ()->create (
144
131
LowestPriceOptionsProviderInterface::class
0 commit comments