Example #1
0
 public function testAddCodeRollbackAndCompletion()
 {
     $collection = new Collection();
     $rollback1 = new CountingTask();
     $rollback2 = new CountingTask();
     $completion1 = new CountingTask();
     $completion2 = new CountingTask();
     $collection->progressMessage("start collection tasks")->rollback($rollback1)->completion($completion1)->rollbackCode(function () use($rollback1) {
         $rollback1->run();
     })->completionCode(function () use($completion1) {
         $completion1->run();
     })->addCode(function () {
         return 42;
     })->progressMessage("not reached")->rollback($rollback2)->completion($completion2)->addCode(function () {
         return 13;
     });
     $collection->setLogger($this->guy->logger());
     $result = $collection->run();
     // Execution stops on the first error.
     // Confirm that status code is converted to a Result object.
     verify($result->getExitCode())->equals(42);
     verify($rollback1->getCount())->equals(2);
     verify($rollback2->getCount())->equals(0);
     verify($completion1->getCount())->equals(2);
     verify($completion2->getCount())->equals(0);
     $this->guy->seeInOutput('start collection tasks');
     $this->guy->doNotSeeInOutput('not reached');
 }
Example #2
0
 /**
  * Return task collection for this task.
  *
  * @return \Robo\Collection\Collection
  *   The task collection.
  */
 public function collection()
 {
     $collection = new Collection();
     // Set up filesystem.
     $collection->add((new SetupFileSystem($this->environment))->collection());
     $collection->add(['Update.cacheRebuild' => new CacheRebuild(), 'Update.drushConfigImport' => new ConfigImport(), 'Update.applyDatabaseUpdates' => new ApplyDatabaseUpdates(), 'Update.drushConfigImportAgain' => new ConfigImport(), 'Update.applyEntitySchemaUpdates' => new ApplyEntitySchemaUpdates(), 'Update.cacheRebuildAgain' => new CacheRebuild(), 'Install.localeUpdate' => new LocaleUpdate()]);
     return $collection;
 }
Example #3
0
 /**
  * Return task collection for this task.
  *
  * @return \Robo\Collection\Collection
  *   The task collection.
  */
 public function collection()
 {
     $collection = new Collection();
     // Build has to be performed?
     if (Environment::needsBuild($this->environment)) {
         $collection->add(['Initialize.composerInstall' => (new ComposerInstall())->dir(PathResolver::root())->option('optimize-autoloader')]);
     }
     $collection->add(['Initialize.initializeEnvironment' => new \Thunder\Robo\Task\Environment\Initialize($this->environment), 'Initialize.ensureSettingsFile' => new EnsureSettingsFile($this->environment)]);
     return $collection;
 }
Example #4
0
 /**
  * Before running this task, register its rollback and completion
  * handlers on its collection. The reason this class exists is to
  * defer registration of rollback and completion tasks until 'run()' time.
  *
  * @return \Robo\Result
  */
 public function run()
 {
     if ($this->rollbackTask) {
         $this->collection->registerRollback($this->rollbackTask);
     }
     if ($this->task instanceof RollbackInterface) {
         $this->collection->registerRollback(new CallableTask([$this->task, 'rollback'], $this->task));
     }
     if ($this->task instanceof CompletionInterface) {
         $this->collection->registerCompletion(new CallableTask([$this->task, 'complete'], $this->task));
     }
     return $this->task->run();
 }
Example #5
0
 public function testBeforeAndAfterFilters()
 {
     $collection = new Collection();
     $taskA = new CollectionTestTask('a', 'value-a');
     $taskB = new CollectionTestTask('b', 'value-b');
     $collection->add('a-name', $taskA)->add('b-name', $taskB);
     // We add methods of our task instances as before and
     // after tasks. These methods have access to the task
     // class' fields, and may modify them as needed.
     $collection->after('a-name', [$taskA, 'parenthesizer'])->after('a-name', [$taskA, 'emphasizer'])->after('b-name', [$taskB, 'emphasizer'])->after('b-name', [$taskB, 'parenthesizer'])->after('b-name', [$taskB, 'parenthesizer'], 'special-name');
     $result = $collection->run();
     // verify(var_export($result->getData(), true))->equals('');
     // Ensure that the results have the correct key values
     verify(implode(',', array_keys($result->getData())))->equals('a-name,b-name,special-name');
     // Verify that all of the after tasks ran in
     // the correct order.
     verify($result['a-name']['a'])->equals('*(value-a)*');
     verify($result['b-name']['b'])->equals('(*value-b*)');
     // Note that the last after task is added with a special name;
     // its results therefore show up under the name given, rather
     // than being stored under the name of the task it was added after.
     verify($result['special-name']['b'])->equals('((*value-b*))');
 }
Example #6
0
 /**
  * Return task collection for this task.
  *
  * @return \Robo\Collection\Collection
  *   The task collection.
  */
 public function collection()
 {
     $collection = new Collection();
     $dump = PathResolver::databaseDump();
     // No database dump file present -> perform initial installation, export
     // configuration and create database dump file.
     if (!file_exists($dump)) {
         $collection->add(['Install.siteInstall' => new SiteInstall()]);
         // Set up file system.
         $collection->add((new SetupFileSystem($this->environment))->collection());
         $collection->add(['Install.enableExtensions' => new EnableExtension(['config', 'locale']), 'Install.localeUpdate' => new LocaleUpdate(), 'Install.cacheRebuild' => new CacheRebuild(), 'Install.configExport' => new ConfigExport(), 'Install.databaseDumpExport' => new Export($dump)]);
     } else {
         $collection->add(['Install.sqlDrop' => new SqlDrop(), 'Install.databaseDumpImport' => new Import($dump)]);
         // Perform site update tasks
         $collection->add((new Update($this->environment))->collection());
     }
     return $collection;
 }
Example #7
0
 /**
  * Return task collection for this task.
  *
  * @return \Robo\Collection\Collection
  *   The task collection.
  */
 public function collection()
 {
     $collection = new Collection();
     $collection->add(['Setup.ensurePrivateFilesDirectory' => new EnsurePrivateFilesDirectory($this->environment), 'Setup.ensurePublicFilesDirectory' => new EnsurePublicFilesDirectory($this->environment), 'Setup.ensureTemporaryFilesDirectory' => new EnsureTemporaryFilesDirectory($this->environment), 'Setup.ensureTranslationFilesDirectory' => new EnsureTranslationFilesDirectory($this->environment)]);
     return $collection;
 }