search_api_meilisearch-1.0.x-dev/tests/src/Traits/UpdateHookTrait.php
tests/src/Traits/UpdateHookTrait.php
<?php
namespace Drupal\Tests\search_api_meilisearch\Traits;
/**
* Provides a trait for running update hooks.
*/
trait UpdateHookTrait {
/**
* Runs the specific version update hook of the module.
*
* @param int $version
* The update hook version.
* @param array $sandbox
* Optional sandbox array.
*
* @return mixed
* The update hook return value.
*
* @throws \InvalidArgumentException
* Exception if update hook function cannot be found.
*/
protected function runUpdateHook(int $version, array $sandbox = []) {
$modulePath = \Drupal::getContainer()
->get('extension.list.module')
->getPath('search_api_meilisearch');
require_once $modulePath . '/search_api_meilisearch.install';
$callable = 'search_api_meilisearch_update_' . $version;
if (!is_callable($callable)) {
throw new \InvalidArgumentException("Update hook version $version not found.");
}
return $callable($sandbox);
}
}
