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