moduleManagerMock = $this->getMockBuilder(Manager::class) ->disableOriginalConstructor() ->getMock(); $this->groupRepositoryMock = $this->getMockBuilder(GroupRepositoryInterface::class) ->setMethods(['getList']) ->getMockForAbstractClass(); $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class) ->disableOriginalConstructor() ->getMock(); $this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class) ->disableOriginalConstructor() ->getMock(); $this->searchResultMock = $this->getMockBuilder(GroupSearchResultsInterface::class) ->getMockForAbstractClass(); $this->model = new Group( $this->moduleManagerMock, $this->groupRepositoryMock, $this->searchCriteriaBuilderMock ); } public function testToOptionArray() { $customerGroups = [ ['label' => __('ALL GROUPS'), 'value' => '32000'], ['label' => __('NOT LOGGED IN'), 'value' => '0'], ]; $this->moduleManagerMock->expects($this->any()) ->method('isEnabled') ->willReturn(true); $this->searchCriteriaBuilderMock->expects($this->any()) ->method('create') ->willReturn($this->searchCriteriaMock); $this->groupRepositoryMock->expects($this->any()) ->method('getList') ->with($this->searchCriteriaMock) ->willReturn($this->searchResultMock); $this->groupRepositoryMock->expects($this->any()) ->method('getList') ->with($this->searchCriteriaMock) ->willReturn($this->searchResultMock); $groupTest = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class) ->disableOriginalConstructor() ->setMethods(['getCode', 'getId']) ->getMockForAbstractClass(); $groupTest->expects($this->any())->method('getCode')->willReturn(__('NOT LOGGED IN')); $groupTest->expects($this->any())->method('getId')->willReturn('0'); $groups = [$groupTest]; $this->searchResultMock->expects($this->any())->method('getItems')->willReturn($groups); $actualCustomerGroups = $this->model->toOptionArray(); $this->assertEquals($customerGroups, $actualCustomerGroups); foreach ($actualCustomerGroups as $actualCustomerGroup) { $this->assertInternalType('string', $actualCustomerGroup['value']); } } }