/**
  * Test run with project
  */
 public function testRuntWithprojectOption()
 {
     $composeFiles = new ComposeFileCollection(['/var/www/docker-compose-test.yml']);
     $composeFiles->setProjectName('unittest');
     $this->mockedManager->method('execute')->willReturn(array('output' => 'test', 'code' => 0));
     $this->assertEquals($this->mockedManager->run('test', 'echo test', $composeFiles), "test");
 }
 /**
  * Test restart with project option
  */
 public function testRestartWithprojectOption()
 {
     $composeFiles = new ComposeFileCollection(['docker-compose.test.yml']);
     $composeFiles->setProjectName('unittest');
     $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
     $this->assertEquals($this->mockedManager->restart($composeFiles), 'ok');
 }
 /**
  * Test create file success from array
  */
 public function testCreateCompseFileCollectionSuccess()
 {
     $file = new ComposeFile('docker-compose.yml');
     $composeFiles = new ComposeFileCollection([$file, 'docker-compose.test.yml']);
     $this->assertEquals('docker-compose.yml', $composeFiles->getAll()[0]->getFileName());
     $this->assertEquals('docker-compose.test.yml', $composeFiles->getAll()[1]->getFileName());
 }
 /**
  * Format the command to execute
  *
  * @param string                $subcommand   The subcommand to pass to docker-compose command
  * @param ComposeFileCollection $composeFiles The compose files to precise in the command
  */
 private function formatCommand($subcommand, ComposeFileCollection $composeFiles)
 {
     $project = '';
     $networking = '';
     $networkDriver = '';
     # Add project name, and network options
     if ($composeFiles->getProjectName() != null) {
         $project = ' --project-name ' . $composeFiles->getProjectName();
         if ($composeFiles->isNetworking()) {
             $networking = ' --x-networking';
             if ($composeFiles->getNetworkDriver() != null) {
                 $networkDriver = ' --x-network-driver ' . $composeFiles->getNetworkDriver();
             }
         }
     }
     # Add files names
     $preciseFiles = '';
     foreach ($composeFiles->getAll() as $composeFile) {
         $preciseFiles .= ' -f ' . $composeFile->getFileName();
     }
     $command = 'docker-compose' . $preciseFiles . $networking . $networkDriver . $project . ' ' . $subcommand;
     return $command;
 }
 /**
  * Test run with project, networking and network driver option
  */
 public function testRuntWithprojectAndNetworkingWithDriverOption()
 {
     $composeFiles = new ComposeFileCollection(['docker-compose.test.yml']);
     $composeFiles->setProjectName('unittest')->setIsNetworking(true)->setNetworkDriver('overlay');
     $this->manager->method('execute')->with('docker-compose -f docker-compose.test.yml --x-networking --x-network-driver overlay --project-name unittest run --rm test mycommand')->willReturn(array('output' => 'ok', 'code' => 0));
     $this->assertEquals($this->manager->run('test', 'mycommand', $composeFiles), 'ok');
 }
 /**
  * Format the command to execute
  *
  * @param string                $subcommand   The subcommand to pass to docker-compose command
  * @param ComposeFileCollection $composeFiles The compose files to precise in the command
  */
 private function formatCommand($subcommand, ComposeFileCollection $composeFiles)
 {
     $command = new Command("docker-compose");
     $project = '';
     # Add files names
     $preciseFiles = '';
     foreach ($composeFiles->getAll() as $composeFile) {
         $command->addArg('-f', $composeFile->getFileName());
         #$preciseFiles .= ' -f ' . $composeFile->getFileName();
     }
     # Add project name
     if ($composeFiles->getProjectName() != null) {
         $command->addArg('--project-name', $composeFiles->getProjectName());
         #$project = ' --project-name ' . $composeFiles->getProjectName();
     }
     $command->addArg($subcommand);
     return $command;
 }
 /**
  * Test run
  * @expectedException \DockerCompose\Exception\NoSuchServiceException
  */
 public function testrunThrowNoSuchServiceException()
 {
     $composeFiles = new ComposeFileCollection(['/var/www/docker-compose-test.yml']);
     $composeFiles->setProjectName('unittest');
     $this->manager->run('failedservice', 'echo test', $composeFiles);
 }