Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateFlatCatalogProduct.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Mtf\TestCase\Injectable;
14 
29 class CreateFlatCatalogProduct extends Injectable
30 {
31  /* tags */
32  const MVP = 'yes';
33  /* end tags */
34 
40  private $configData;
41 
47  private $fixtureFactory;
48 
54  private $category;
55 
61  private $catalogCategoryView;
62 
69  public function __prepare(Category $category)
70  {
71  $category->persist();
72  return [
73  'category' => $category
74  ];
75  }
76 
85  public function __inject(
86  Category $category,
87  FixtureFactory $fixtureFactory,
88  CatalogCategoryView $catalogCategoryView
89  ) {
90  $this->category = $category;
91  $this->fixtureFactory = $fixtureFactory;
92  $this->catalogCategoryView = $catalogCategoryView;
93  }
94 
102  public function test($configData, $productsCount)
103  {
104  $this->objectManager->create(SetupConfigurationStep::class, ['configData' => $this->configData])->run();
105  $this->createBulkOfProducts($productsCount);
106  $this->configData = $configData;
107  return ['category' => $this->category, 'catalogCategoryView' => $this->catalogCategoryView];
108  }
109 
115  public function tearDown()
116  {
117  $this->objectManager->create(
118  SetupConfigurationStep::class,
119  ['configData' => $this->configData, 'rollback' => true]
120  )->run();
121  }
122 
129  private function createBulkOfProducts($productsCount)
130  {
131  for ($counter = 1; $counter <= $productsCount; $counter++) {
132  $product = $this->fixtureFactory->createByCode(
133  'catalogProductSimple',
134  [
135  'dataset' => 'default',
136  'data' => [
137  'category_ids' => [
138  'category' => $this->category
139  ]
140  ]
141  ]
142  );
143  $product->persist();
144  }
145  }
146 }
__inject(Category $category, FixtureFactory $fixtureFactory, CatalogCategoryView $catalogCategoryView)