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');
 }