We need to create customer model object instance and load the all attributes with that attribute.
Please check this following test code, this will help you .
namespace Custom\Test\Model\Config\Source;
use Magento\Customer\Model;
class Customers implements \Magento\Framework\Option\ArrayInterface
{
protected $customerFactory;
public function __construct(
\Magento\Customer\Model\Customer $customerFactory
) {
$this->customerFactory = $customerFactory;
}
public function toOptionArray( $isMultiselect = false)
{
$customer_attributes = $this->customerFactory->getAttributes();
$attributesArrays = array();
foreach($customer_attributes as $cal=>$val){
$attributesArrays[] = array(
'label' => $cal,
'value' => $val
);
}
return $attributesArrays;
}
}