Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundleProductsAssert.php
Go to the documentation of this file.
1 <?php
7 
9 
17 {
21  private $productRepository;
22 
26  private $optionList;
27 
31  private $productAssert;
32 
38  public function __construct(
39  \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
40  \Magento\Bundle\Model\Product\OptionList $optionList,
41  \Magento\Setup\Fixtures\FixturesAsserts\ProductAssert $productAssert
42  ) {
43  $this->productRepository = $productRepository;
44  $this->optionList = $optionList;
45  $this->productAssert = $productAssert;
46  }
47 
55  public function assert()
56  {
57  $bundleSkuSuffix = '2-2';
58  $product = $this->productRepository->get(
59  sprintf(BundleProductsFixture::SKU_PATTERN, 1, $bundleSkuSuffix)
60  );
61 
62  $this->productAssert->assertProductsCount(
63  sprintf(BundleProductsFixture::SKU_PATTERN, '%s', $bundleSkuSuffix),
64  2
65  );
66  $this->productAssert->assertProductType('bundle', $product);
67 
68  if (2 !== count($this->optionList->getItems($product))) {
69  throw new \AssertionError('Bundle options amount is wrong');
70  }
71 
72  foreach ($this->optionList->getItems($product) as $option) {
73  if (2 !== count($option->getProductLinks())) {
74  throw new \AssertionError('Bundle option product links amount is wrong');
75  }
76  }
77 
78  return true;
79  }
80 }
__construct(\Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Bundle\Model\Product\OptionList $optionList, \Magento\Setup\Fixtures\FixturesAsserts\ProductAssert $productAssert)