attributeResolverMock = $this->getMockBuilder(\Magento\Customer\Model\Metadata\AttributeResolver::class) ->disableOriginalConstructor() ->getMock(); $this->model = new CustomerMetadataManagement( $this->attributeResolverMock ); } public function testCanBeSearchableInGrid() { /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class) ->getMockForAbstractClass(); /** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $modelMock */ $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class) ->disableOriginalConstructor() ->getMock(); $this->attributeResolverMock->expects($this->once()) ->method('getModelByAttribute') ->with(CustomerMetadataManagement::ENTITY_TYPE_CUSTOMER, $attributeMock) ->willReturn($modelMock); $modelMock->expects($this->once()) ->method('canBeSearchableInGrid') ->willReturn(true); $this->assertTrue($this->model->canBeSearchableInGrid($attributeMock)); } public function testCanBeFilterableInGrid() { /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMock */ $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class) ->getMockForAbstractClass(); /** @var Attribute|\PHPUnit_Framework_MockObject_MockObject $modelMock */ $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class) ->disableOriginalConstructor() ->getMock(); $this->attributeResolverMock->expects($this->once()) ->method('getModelByAttribute') ->with(CustomerMetadataManagement::ENTITY_TYPE_CUSTOMER, $attributeMock) ->willReturn($modelMock); $modelMock->expects($this->once()) ->method('canBeFilterableInGrid') ->willReturn(true); $this->assertTrue($this->model->canBeFilterableInGrid($attributeMock)); } }