9
9
10
10
use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
11
use Magento \Catalog \Model \Category ;
12
+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
12
13
use Magento \CatalogSearch \Model \Indexer \Fulltext \Processor ;
14
+ use Magento \Framework \Indexer \StateInterface ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
16
+ use PHPUnit \Framework \TestCase ;
14
17
15
- class CategoryTest extends \PHPUnit \Framework \TestCase
18
+ /**
19
+ * Test for category repository plugin
20
+ */
21
+ class CategoryTest extends TestCase
16
22
{
17
23
/**
18
24
* @var Processor
@@ -24,10 +30,19 @@ class CategoryTest extends \PHPUnit\Framework\TestCase
24
30
*/
25
31
private $ categoryRepository ;
26
32
33
+ /**
34
+ * @var CategoryCollectionFactory
35
+ */
36
+ private $ categoryCollectionFactory ;
37
+
38
+ /**
39
+ * @inheritDoc
40
+ */
27
41
protected function setUp (): void
28
42
{
29
43
$ this ->indexerProcessor = Bootstrap::getObjectManager ()->create (Processor::class);
30
44
$ this ->categoryRepository = Bootstrap::getObjectManager ()->create (CategoryRepositoryInterface::class);
45
+ $ this ->categoryCollectionFactory = Bootstrap::getObjectManager ()->create (CategoryCollectionFactory::class);
31
46
}
32
47
33
48
/**
@@ -47,22 +62,22 @@ public function testIndexerInvalidatedAfterCategoryDelete()
47
62
$ status = $ state ->getStatus ();
48
63
49
64
$ this ->assertTrue ($ isIndexerValid );
50
- $ this ->assertEquals (\ Magento \ Framework \ Indexer \ StateInterface::STATUS_INVALID , $ status );
65
+ $ this ->assertEquals (StateInterface::STATUS_INVALID , $ status );
51
66
}
52
67
53
68
/**
69
+ * Returns categories
70
+ *
54
71
* @param int $count
55
72
* @return Category[]
56
73
*/
57
- private function getCategories ($ count )
74
+ private function getCategories (int $ count ): array
58
75
{
59
- /** @var Category $category */
60
- $ category = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
61
- \Magento \Catalog \Model \Category::class
62
- );
63
-
64
- $ result = $ category ->getCollection ()->addAttributeToSelect ('name ' )->getItems ();
65
- $ result = array_slice ($ result , 2 );
76
+ $ collection = $ this ->categoryCollectionFactory ->create ()
77
+ ->addAttributeToSelect ('name ' )
78
+ ->addAttributeToSelect ('is_active ' )
79
+ ->getItems ();
80
+ $ result = array_slice ($ collection , 2 );
66
81
67
82
return array_slice ($ result , 0 , $ count );
68
83
}
0 commit comments