Ejemplo n.º 1
0
 /**
  * Using the config item "behat_path", run composer update and bin/behat in the behat path.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function executeBehatTests(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Running Behat Tests...');
     $environment_factory = new EnvironmentFactory($this->environment, $this->app);
     $environment_factory->getConfig();
     // 1. Look for behat.yml
     $behat_path = $this->environment->path . '/' . $environment_factory->config['behat_path'];
     $behat_yml_path = $behat_path . '/behat.yml';
     if (!file_exists($behat_path)) {
         throw new \Exception("Path {$behat_path} not found. Check your app's .terra.yml file.");
     } elseif (!file_exists($behat_yml_path)) {
         throw new \Exception("Behat.yml file not found at {$behat_yml_path}. Check your app's .terra.yml file.");
     }
     $output->writeln('Found behat.yml file at ' . $behat_yml_path);
     // 2. Load it, replace necessary items, and clone it to a temporary file.
     $behat_yml = Yaml::parse(file_get_contents($behat_yml_path));
     // Set Base URL
     $behat_yml['default']['extensions']['Behat\\MinkExtension']['base_url'] = "http://{$environment_factory->getHost()}:{$environment_factory->getPort()}";
     $behat_yml['default']['extensions']['Drupal\\DrupalExtension']['drush']['alias'] = $environment_factory->getDrushAlias();
     // If driver is drupal, add root.
     if ($behat_yml['default']['extensions']['Drupal\\DrupalExtension']['api_driver'] == 'drupal') {
         $behat_yml['default']['extensions']['Drupal\\DrupalExtension']['drupal']['root'] = $environment_factory->getDocumentRoot();
     }
     $behat_yml_new = Yaml::dump($behat_yml, 5, 2);
     $behat_path_new = 'behat.terra.yml';
     $fs = new Filesystem();
     $fs->dumpFile($behat_path_new, $behat_yml_new);
     $output->writeln('Generated new behat.yml file at ' . $behat_path_new);
     // 3. Run `composer install` in behat_path.
     $output->writeln('');
     $output->writeln('<fg=cyan>TERRA</> | <comment>Running: composer install</comment>');
     $process = new Process('composer install', $behat_path);
     $process->setTimeout(NULL);
     $process->run(function ($type, $buffer) {
         if (Process::ERR === $type) {
             echo $buffer;
         } else {
             echo $buffer;
         }
     });
     $output->writeln('');
     $output->writeln('<fg=cyan>TERRA</> | <comment>Behat Tests: Start</comment>');
     // 4. Run `bin/behat --colors --config=$PATH` in behat_path.
     // "expand:true" expands scenario outlines, making them readable.
     $cmd = 'bin/behat --colors --format-settings=\'{"expand": true}\' --config=' . $behat_path_new;
     if ($input->getOption('name')) {
         $cmd .= ' --name=' . $input->getOption('name');
     }
     $output->writeln("Running: {$cmd}");
     $output->writeln("in: {$behat_path}");
     $output->writeln('');
     $process = new Process($cmd, $behat_path);
     $process->setTimeout(NULL);
     $process->run(function ($type, $buffer) {
         if (Process::ERR === $type) {
             echo $buffer;
         } else {
             echo $buffer;
         }
     });
     $output->writeln('');
     if (!$process->isSuccessful()) {
         $output->writeln('<fg=cyan>TERRA</> | <fg=red>Test Failed</> ');
         return 1;
     } else {
         $output->writeln('<fg=cyan>TERRA</> | <info>Test Passed!</info> ');
         return 0;
     }
 }