X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrush%2Fdrush%2Ftests%2FCommands%2FTestFixtureCommands.php;fp=vendor%2Fdrush%2Fdrush%2Ftests%2FCommands%2FTestFixtureCommands.php;h=2880a6ad1b86f200a8d26326dfc5fa211232572d;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/vendor/drush/drush/tests/Commands/TestFixtureCommands.php b/vendor/drush/drush/tests/Commands/TestFixtureCommands.php new file mode 100644 index 000000000..2880a6ad1 --- /dev/null +++ b/vendor/drush/drush/tests/Commands/TestFixtureCommands.php @@ -0,0 +1,163 @@ + [ + [[$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; + } +}