Example #1
0
 public function testBeforeFilters()
 {
     $collection = new Collection();
     $taskA = new CollectionTestTask('a', 'value-a');
     $taskB = new CollectionTestTask('b', 'value-b');
     $collection->add($taskA, 'a-name')->add($taskB, 'b-name');
     // 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->before('b-name', [$taskA, 'parenthesizer'])->before('b-name', [$taskA, 'emphasizer'], 'special-before-name');
     $result = $collection->run();
     // Ensure that the results have the correct key values
     verify(implode(',', array_keys($result->getData())))->equals('a-name,b-name,special-before-name,time');
     // The result from the 'before' task is attached
     // to 'b-name', since it was called as before('b-name', ...)
     verify($result['b-name']['a'])->equals('(value-a)');
     // When a 'before' task is given its own name, then
     // its results are attached under that name.
     verify($result['special-before-name']['a'])->equals('*(value-a)*');
 }