44
55use Magento \Catalog \Api \CategoryLinkRepositoryInterface ;
66use Magento \Catalog \Api \CategoryRepositoryInterface ;
7- use Magento \Catalog \Model \Category ;
8- use \Magento \Catalog \Model \ResourceModel \Category as CategoryResource ;
97use Magento \Catalog \Api \Data \CategoryInterface ;
108use Magento \Catalog \Api \Data \CategoryProductLinkInterface ;
119use Magento \Catalog \Api \Data \CategoryProductLinkInterfaceFactory ;
10+ use Magento \Catalog \Model \Category ;
11+ use Magento \Catalog \Model \ResourceModel \Category as CategoryResource ;
1212use Magento \Framework \ObjectManagerInterface ;
13+ use Magento \TestFramework \Helper \Bootstrap ;
1314
1415class CategoryBuilder
1516{
16- /**
17- * @var CategoryInterface
18- */
19- private $ category ;
20-
2117 /**
2218 * @var CategoryRepositoryInterface
2319 */
@@ -38,10 +34,15 @@ class CategoryBuilder
3834 */
3935 private $ productLinkFactory ;
4036
37+ /**
38+ * @var CategoryInterface|Category
39+ */
40+ private $ category ;
41+
4142 /**
4243 * @var int[]
4344 */
44- private $ skus = [] ;
45+ private $ skus ;
4546
4647 public function __construct (
4748 CategoryRepositoryInterface $ categoryRepository ,
@@ -54,15 +55,15 @@ public function __construct(
5455 $ this ->categoryRepository = $ categoryRepository ;
5556 $ this ->categoryResource = $ categoryResource ;
5657 $ this ->categoryLinkRepository = $ categoryLinkRepository ;
58+ $ this ->productLinkFactory = $ productLinkFactory ;
5759 $ this ->category = $ category ;
5860 $ this ->skus = $ skus ;
59- $ this ->productLinkFactory = $ productLinkFactory ;
6061 }
6162
62- public static function topLevelCategory (ObjectManagerInterface $ objectManager = null ) : CategoryBuilder
63+ public static function topLevelCategory (ObjectManagerInterface $ objectManager = null ): CategoryBuilder
6364 {
6465 if ($ objectManager === null ) {
65- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
66+ $ objectManager = Bootstrap::getObjectManager ();
6667 }
6768 /** @var CategoryInterface $category */
6869 $ category = $ objectManager ->create (CategoryInterface::class);
@@ -84,10 +85,9 @@ public static function topLevelCategory(ObjectManagerInterface $objectManager =
8485 public static function childCategoryOf (
8586 CategoryFixture $ parent ,
8687 ObjectManagerInterface $ objectManager = null
87- ): CategoryBuilder
88- {
88+ ): CategoryBuilder {
8989 if ($ objectManager === null ) {
90- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
90+ $ objectManager = Bootstrap::getObjectManager ();
9191 }
9292 /** @var CategoryInterface $category */
9393 $ category = $ objectManager ->create (CategoryInterface::class);
@@ -112,35 +112,35 @@ public static function childCategoryOf(
112112 * @param string[] $skus
113113 * @return CategoryBuilder
114114 */
115- public function withProducts (array $ skus ) : CategoryBuilder
115+ public function withProducts (array $ skus ): CategoryBuilder
116116 {
117117 $ builder = clone $ this ;
118118 $ builder ->skus = $ skus ;
119119 return $ builder ;
120120 }
121121
122- public function withDescription (string $ description ) : CategoryBuilder
122+ public function withDescription (string $ description ): CategoryBuilder
123123 {
124124 $ builder = clone $ this ;
125125 $ builder ->category ->setCustomAttribute ('description ' , $ description );
126126 return $ builder ;
127127 }
128128
129- public function withName (string $ name ) : CategoryBuilder
129+ public function withName (string $ name ): CategoryBuilder
130130 {
131131 $ builder = clone $ this ;
132132 $ builder ->category ->setName ($ name );
133133 return $ builder ;
134134 }
135135
136- public function withUrlKey (string $ urlKey ) : CategoryBuilder
136+ public function withUrlKey (string $ urlKey ): CategoryBuilder
137137 {
138138 $ builder = clone $ this ;
139139 $ builder ->category ->setData ('url_key ' , $ urlKey );
140140 return $ builder ;
141141 }
142142
143- public function withIsActive (bool $ isActive ) : CategoryBuilder
143+ public function withIsActive (bool $ isActive ): CategoryBuilder
144144 {
145145 $ builder = clone $ this ;
146146 $ builder ->category ->setIsActive ($ isActive );
@@ -152,7 +152,11 @@ public function __clone()
152152 $ this ->category = clone $ this ->category ;
153153 }
154154
155- public function build () : CategoryInterface
155+ /**
156+ * @return CategoryInterface
157+ * @throws \Exception
158+ */
159+ public function build (): CategoryInterface
156160 {
157161 $ builder = clone $ this ;
158162 if (!$ builder ->category ->getData ('url_key ' )) {
@@ -175,4 +179,4 @@ public function build() : CategoryInterface
175179 }
176180 return $ builder ->category ;
177181 }
178- }
182+ }
0 commit comments