Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HashMapPoolTest.php
Go to the documentation of this file.
1 <?php
7 
14 
18 class HashMapPoolTest extends \PHPUnit\Framework\TestCase
19 {
21  private $objectManagerMock;
22 
24  private $model;
25 
26  protected function setUp()
27  {
28  $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
29 
30  $this->model = (new ObjectManager($this))->getObject(
31  HashMapPool::class,
32  [
33  'objectManager' => $this->objectManagerMock,
34  ]
35  );
36  }
37 
41  public function testGetDataMap()
42  {
43  $dataCategoryMapMock = $this->createMock(DataCategoryHashMap::class);
44  $dataProductMapMock = $this->createMock(DataProductHashMap::class);
45  $dataProductMapMockOtherCategory = $this->createMock(DataCategoryUsedInProductsHashMap::class);
46 
47  $this->objectManagerMock->expects($this->any())
48  ->method('create')
49  ->willReturnMap(
50  [
51  [
52  DataCategoryHashMap::class,
53  ['category' => 1],
54  $dataCategoryMapMock
55  ],
56  [
57  DataProductHashMap::class,
58  ['category' => 1],
59  $dataProductMapMock
60  ],
61  [
62  DataCategoryUsedInProductsHashMap::class,
63  ['category' => 2],
64  $dataProductMapMockOtherCategory
65  ]
66  ]
67  );
68  $this->assertSame($dataCategoryMapMock, $this->model->getDataMap(DataCategoryHashMap::class, 1));
69  $this->assertSame($dataProductMapMock, $this->model->getDataMap(DataProductHashMap::class, 1));
70  $this->assertSame(
71  $dataProductMapMockOtherCategory,
72  $this->model->getDataMap(DataCategoryUsedInProductsHashMap::class, 2)
73  );
74  }
75 
79  public function testGetDataMapException()
80  {
81  $nonInterface = $this->createMock(HashMapPool::class);
82 
83  $this->objectManagerMock->expects($this->any())
84  ->method('create')
85  ->willReturn($nonInterface);
86  $this->expectException(\InvalidArgumentException::class);
87  $this->model->getDataMap(HashMapPool::class, 1);
88  }
89 }