As far as I know, Magento 2 has a test to set Base, Small and Thumbnail image dev/tests/integration/testsuite/Magento/Sitemap/_files/sitemap_products.php.
We can follow the logic of this and create your own. An simple example:
$obj = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Framework\Filesystem $filesystem */
$filesystem = $obj->create('Magento\Framework\Filesystem');
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
$mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
$mediaPath = $mediaDirectory->getAbsolutePath();
//Sample product id
$productId = 1;
$model = $obj->create('Magento\Catalog\Model\Product');
$product = $model->load($productId);
$product->setImage(
$mediaPath . '/magento_image.png'
)
->setSmallImage(
$mediaPath . '/magento_image_small.png'
)
->setThumbnail(
$mediaPath . '/magento_image_thumb.png'
)
->addImageToMediaGallery(
$mediaPath . '/first_magento_image.png',
null,
false,
false
)->addImageToMediaGallery(
$mediaPath . '/second_image.png',
null,
false,
false
)
->save();
We can try to test my code with playground and here.