[ [[$this, '_drushUnitBatchOperation'], []], ], 'finished' => [$this, '_drushUnitBatchFinished'], // 'file' => Doesn't work for us. Drupal 7 enforces this path // to be relative to DRUPAL_ROOT. // @see _batch_process(). ]; \batch_set($batch); \drush_backend_batch_process(); // Print the batch output. \drush_backend_output(); } public function _drushUnitBatchOperation(&$context) { $context['message'] = "!!! ArrayObject does its job."; for ($i = 0; $i < 5; $i++) { \drush_print("Iteration $i"); } $context['finished'] = 1; } public function _drushUnitBatchFinished() { // Restore php limits. // TODO. } /** * Return options as function result. * @command unit-return-options */ public function drushUnitReturnOptions($arg = '', $options = ['x' => 'y', 'data' => [], 'format' => 'yaml']) { unset($options['format']); return $options; } /** * Return original argv as function result. * @command unit-return-argv */ public function drushUnitReturnArgv(array $args) { return $args; } /** * Clears the dependency injection container. * * Intended for testing cases that require the container to be rebuilt from * scratch. * * @command unit-invalidate-container * @bootstrap site */ public function drushUnitInvalidateContainer() { $autoloader = $this->loadDrupalAutoloader(DRUPAL_ROOT); $request = Drush::bootstrap()->getRequest(); $sitePath = DrupalKernel::findSitePath($request); // Perform early bootstrap. This includes dynamic configuration of PHP, // setting the error and exception handlers etc. DrupalKernel::bootEnvironment(); // Initialize database connections and apply configuration from // settings.php. Settings::initialize(DRUPAL_ROOT, $sitePath, $autoloader); $kernel = new DrupalKernel('prod', $autoloader); $kernel->setSitePath($sitePath); // We need to boot the kernel in order to load the service that can // delete the compiled container from the cache backend. $kernel->boot(); $kernel->invalidateContainer(); } /** * Loads the Drupal autoloader and returns the instance. * * @see \Drush\Commands\core\CacheCommands::loadDrupalAutoloader() */ protected function loadDrupalAutoloader($drupal_root) { static $autoloader = false; $autoloadFilePath = $drupal_root .'/autoload.php'; if (!$autoloader && file_exists($autoloadFilePath)) { $autoloader = require $autoloadFilePath; } if ($autoloader === true) { // The autoloader was already required. Assume that Drush and Drupal share an autoloader per // "Point autoload.php to the proper vendor directory" - https://www.drupal.org/node/2404989 $autoloader = $this->autoloader(); } return $autoloader; } }