Ejemplo n.º 1
0
 /**
  * @test
  */
 public function canBatchProcessCommandCollections()
 {
     $a = new CommandCollection();
     $a->add(new Command('wget', ['http://google.com']));
     $b = new CommandCollection();
     $b->add(new Command('yum install php'));
     $b->add(new Command('php', ['-v']));
     $batch = new Batch();
     $batch->addCommandCollection($a);
     $batch->addCommandCollection($b);
     $this->assertNotEmpty($batch->getCommandCollections(), 'Batch should return command collections that were added');
     $this->assertCount(2, $batch->getCommandCollections(), 'Batch should have two command collections');
     $compiled = $batch->getCompiled();
     $this->assertEquals('wget http://google.com; yum install php; php -v;', $compiled, 'Compiled batch is invalid');
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * @return string
  */
 public function compile(Batch $batch)
 {
     $response = [];
     #   Inject the compiler header for reference.
     $response[] = static::COMPILE_HEADER;
     $response[] = '';
     foreach ($batch->getCommandCollections() as $collection) {
         /** @var Command[] $commands */
         $commands = $collection->toArray();
         foreach ($commands as $command) {
             $response[] = $command->getCommand();
         }
         # Always end the collection with a new line.
         $response[] = '';
     }
     return implode(PHP_EOL, $response);
 }