8 use Magento\Catalog\Model\ResourceModel\CategoryFactory;
23 private $categoryRepository;
26 private $categoryResourceFactory;
29 private $categoryResource;
36 $this->categoryRepository = $this->createMock(CategoryRepository::class);
37 $this->categoryResourceFactory = $this->createPartialMock(CategoryFactory::class, [
'create']);
38 $this->categoryResource = $this->createPartialMock(Category::class, [
'getConnection',
'getEntityTable']);
40 $this->categoryResourceFactory->expects($this->any())
42 ->willReturn($this->categoryResource);
45 DataCategoryHashMap::class,
47 'categoryRepository' => $this->categoryRepository,
48 'categoryResourceFactory' => $this->categoryResourceFactory
58 $categoryIds = [
'1' => [1, 2, 3],
'2' => [2, 3],
'3' => 3];
59 $categoryIdsOther = [
'2' => [2, 3, 4]];
61 $categoryMock = $this->getMockBuilder(CategoryInterface::class)
62 ->setMethods([
'getResource'])
63 ->getMockForAbstractClass();
64 $connectionAdapterMock = $this->createMock(AdapterInterface::class);
65 $selectMock = $this->createMock(Select::class);
67 $this->categoryRepository->expects($this->any())
69 ->willReturn($categoryMock);
70 $categoryMock->expects($this->any())
71 ->method(
'getResource')
72 ->willReturn($this->categoryResource);
73 $this->categoryResource->expects($this->any())
74 ->method(
'getConnection')
75 ->willReturn($connectionAdapterMock);
76 $this->categoryResource->expects($this->any())
77 ->method(
'getEntityTable')
78 ->willReturn(
'category_entity');
79 $connectionAdapterMock->expects($this->any())
81 ->willReturn($selectMock);
82 $selectMock->expects($this->any())
85 $selectMock->expects($this->any())
88 $connectionAdapterMock->expects($this->any())
90 ->willReturnOnConsecutiveCalls($categoryIds, $categoryIdsOther, $categoryIds);
92 $this->assertEquals($categoryIds, $this->model->getAllData(1));
93 $this->assertEquals($categoryIds[2], $this->model->getData(1, 2));
94 $this->assertEquals($categoryIdsOther, $this->model->getAllData(2));
95 $this->assertEquals($categoryIdsOther[2], $this->model->getData(2, 2));
96 $this->model->resetData(1);
97 $this->assertEquals($categoryIds[2], $this->model->getData(1, 2));
98 $this->assertEquals($categoryIds, $this->model->getAllData(1));