@@ -18,11 +18,6 @@ class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
1818 */
1919 private $ storeManager ;
2020
21- /**
22- * @var LowestPriceOptionsProviderInterface
23- */
24- private $ lowestPriceOptionsProvider ;
25-
2621 /**
2722 * @var ProductRepositoryInterface
2823 */
@@ -32,10 +27,6 @@ protected function setUp()
3227 {
3328 $ this ->storeManager = Bootstrap::getObjectManager ()->get (StoreManagerInterface::class);
3429 $ 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- );
3930 }
4031
4132 /**
@@ -44,7 +35,7 @@ protected function setUp()
4435 public function testGetProductsIfOneOfChildIsDisabled ()
4536 {
4637 $ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
47- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
38+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
4839 $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
4940 $ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
5041 $ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -63,8 +54,7 @@ public function testGetProductsIfOneOfChildIsDisabled()
6354 $ this ->productRepository ->save ($ lowestPriceChildProduct );
6455 $ this ->storeManager ->setCurrentStore ($ currentStoreId );
6556
66- $ lowestPriceOptionsProvider = $ this ->recreateLowestPriceOptionsProvider ();
67- $ lowestPriceChildrenProducts = $ lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
57+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
6858
6959 $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
7060 $ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
@@ -77,7 +67,7 @@ public function testGetProductsIfOneOfChildIsDisabled()
7767 public function testGetProductsIfOneOfChildIsDisabledPerStore ()
7868 {
7969 $ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
80- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
70+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
8171 $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
8272 $ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
8373 $ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -97,9 +87,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
9787 $ this ->productRepository ->save ($ lowestPriceChildProduct );
9888 $ this ->storeManager ->setCurrentStore ($ currentStoreId );
9989
100- $ lowestPriceOptionsProvider = $ this ->recreateLowestPriceOptionsProvider ();
101- $ lowestPriceChildrenProducts = $ lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
102-
90+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
10391 $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
10492 $ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
10593 $ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -111,7 +99,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
11199 public function testGetProductsIfOneOfChildIsOutOfStock ()
112100 {
113101 $ configurableProduct = $ this ->productRepository ->get ('configurable ' , false , null , true );
114- $ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
102+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider () ->getProducts ($ configurableProduct );
115103 $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
116104 $ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
117105 $ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
@@ -126,19 +114,18 @@ public function testGetProductsIfOneOfChildIsOutOfStock()
126114 $ stockItem = $ lowestPriceChildProduct ->getExtensionAttributes ()->getStockItem ();
127115 $ stockItem ->setIsInStock (0 );
128116 $ this ->productRepository ->save ($ lowestPriceChildProduct );
129-
130- $ lowestPriceOptionsProvider = $ this ->recreateLowestPriceOptionsProvider ();
131- $ lowestPriceChildrenProducts = $ lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
132-
117+ $ lowestPriceChildrenProducts = $ this ->createLowestPriceOptionsProvider ()->getProducts ($ configurableProduct );
133118 $ this ->assertCount (1 , $ lowestPriceChildrenProducts );
134119 $ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
135120 $ this ->assertEquals (20 , $ lowestPriceChildrenProduct ->getPrice ());
136121 }
137122
138123 /**
124+ * As LowestPriceOptionsProviderInterface used multiple times in scope
125+ * of one test we need to always recreate it and prevent internal caching in property
139126 * @return LowestPriceOptionsProviderInterface
140127 */
141- private function recreateLowestPriceOptionsProvider ()
128+ private function createLowestPriceOptionsProvider ()
142129 {
143130 return Bootstrap::getObjectManager ()->create (
144131 LowestPriceOptionsProviderInterface::class
0 commit comments