Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerGroupsOptionsProviderTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CustomerGroupsOptionsProviderTest extends \PHPUnit\Framework\TestCase
9 {
13  private $model;
14 
18  private $groupRepositoryMock;
19 
23  private $searchCriteriaBuilderMock;
24 
28  private $objectConverterMock;
29 
30  protected function setup()
31  {
32  $this->groupRepositoryMock = $this->createMock(\Magento\Customer\Api\GroupRepositoryInterface::class);
33  $this->searchCriteriaBuilderMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaBuilder::class);
34  $this->objectConverterMock = $this->createMock(\Magento\Framework\Convert\DataObject::class);
35  $this->model = new \Magento\CatalogRule\Model\Rule\CustomerGroupsOptionsProvider(
36  $this->groupRepositoryMock,
37  $this->searchCriteriaBuilderMock,
38  $this->objectConverterMock
39  );
40  }
41 
42  public function testToOptionArray()
43  {
44  $customerGroups = ['group1', 'group2'];
45 
46  $options = [
47  ['label' => 'label', 'value' => 'value']
48  ];
49 
50  $searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
51  $searchResultMock = $this->createMock(\Magento\Customer\Api\Data\GroupSearchResultsInterface::class);
52  $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
53 
54  $this->groupRepositoryMock->expects($this->once())
55  ->method('getList')
56  ->with($searchCriteriaMock)
57  ->willReturn($searchResultMock);
58 
59  $searchResultMock->expects($this->once())->method('getItems')->willReturn($customerGroups);
60  $this->objectConverterMock->expects($this->once())
61  ->method('toOptionArray')
62  ->with($customerGroups, 'id', 'code')
63  ->willReturn($options);
64 
65  $this->assertEquals($options, $this->model->toOptionArray());
66  }
67 }