List of all categories with sub-categories as an option array (with opt-group):
If you want to get the category tree, just use the method toOptionArray of the \Magento\Catalog\Ui\Component\Product\Form\Categories\Options class located in vendor/magento/module-catalog/Ui/Component/Product/Form/Categories/Options.php like this:
/**
* @var \Magento\Catalog\Ui\Component\Product\Form\Categories\Options
*/
protected $categoriesOptions;
/**
* @param \Magento\Catalog\Ui\Component\Product\Form\Categories\Options $categoriesOptions
*/
public function __construct(
\Magento\Catalog\Ui\Component\Product\Form\Categories\Options $categoriesOptions
) {
$this->categoriesOptions = $categoriesOptions;
}
public function getCategories()
{
$values = $this->categoriesOptions->toOptionArray();
return $values;
}
Result in this case should look like this (options with opt-groups):

List of all categories as an option array:
Try this:
/**
* @var \Magento\Catalog\Model\CategoryFactory
*/
protected $categoryFactory;
/**
* @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
*/
public function __construct(
\Magento\Catalog\Model\CategoryFactory $categoryFactory
) {
$this->categoryFactory = $categoryFactory;
}
public function getCategories()
{
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
$collection = $this->categoryFactory->create()->getCollection()->addAttributeToSelect('name');
$values = $collection->toOptionArray(); // or use method toArray
return $values;
}
Result should look like this:

List of all categories with data as an array:
To get all the category data just replace toOptionArray() to toArray():
$values = $collection->toArray();
