Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegularPriceResolverTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 use PHPUnit\Framework\TestCase;
16 
17 class RegularPriceResolverTest extends TestCase
18 {
22  private $storeManager;
23 
27  private $productRepository;
28 
32  private $storeCodeBefore;
33 
37  private $configurablePriceResolver;
38 
42  protected function setUp()
43  {
44  parent::setUp();
45 
46  $this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
47  $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
48  $this->storeCodeBefore = $this->storeManager->getStore()->getCode();
49  $regularPrice = Bootstrap::getObjectManager()->get(RegularPriceResolver::class);
50 
51  $this->configurablePriceResolver = Bootstrap::getObjectManager()->create(
52  ConfigurablePriceResolver::class,
53  ['priceResolver' => $regularPrice]
54  );
55  }
56 
57  // @codingStandardsIgnoreStart
72  // @codingStandardsIgnoreEnd
74  {
75  $this->storeManager->setCurrentStore('store_for_us_website');
76 
77  $configurableProduct = $this->productRepository->get('configurable', false, null, true);
78  $actualPrice = $this->configurablePriceResolver->resolvePrice($configurableProduct);
79 
80  self::assertEquals(10, $actualPrice);
81  }
82 
84 
99  // @codingStandardsIgnoreEnd
101  {
102  $this->storeManager->setCurrentStore('store_for_us_website');
103 
104  $configurableProduct = $this->productRepository->get('configurable', false, null, true);
105  $actualPrice = $this->configurablePriceResolver->resolvePrice($configurableProduct);
106  self::assertEquals(20, $actualPrice);
107  }
108 
112  protected function tearDown()
113  {
114  parent::tearDown();
115 
116  if (null !== $this->storeCodeBefore) {
117  $this->storeManager->setCurrentStore($this->storeCodeBefore);
118  }
119  }
120 }