/**
  * Ensures that the user enters a valid directory or agrees that the entered directory
  * is created for them
  *
  * @param string $path
  * @return string
  * @throws \Exception
  */
 public function validateArtifactWritePath($path)
 {
     if (is_dir($this->settings->getBaseDir() . '/' . $path)) {
         return $path;
     }
     $confirmed = $this->dialog->askConfirmation($this->output, '  - Are you sure? The path does not exist and will be created.', true);
     if (!$confirmed) {
         throw new \Exception(sprintf('Chosen not to use path "%s", trying again..."', $path));
     }
     return $path;
 }
 /**
  * @inheritdoc
  * @codeCoverageIgnore
  */
 public function writeConfig()
 {
     $filesystem = new Filesystem();
     try {
         $filesystem->dumpFile($this->settings->getBaseDir() . '/phpmd.xml', $this->twig->render('phpmd.xml.dist', $this->settings->getArrayCopy()));
         $filesystem->dumpFile($this->settings->getBaseDir() . '/phpmd-pre-commit.xml', $this->twig->render('phpmd-pre-commit.xml.dist', $this->settings->getArrayCopy()));
     } catch (IOException $e) {
         $this->output->writeln(sprintf('<error>Could not write phpmd.xml, error: "%s"</error>', $e->getMessage()));
         return;
     }
     $this->output->writeln("\n<info>Config file for PHP Mess Detector written</info>");
 }
 public function writeConfig()
 {
     $filesystem = new Filesystem();
     try {
         $filesystem->dumpFile($this->settings->getBaseDir() . '/.travis.yml', $this->twig->render('.travis.yml.dist', $this->settings['travis']));
         $filesystem->dumpFile($this->settings->getBaseDir() . '/.travis.php.ini', $this->twig->render('.travis.php.ini.dist'));
     } catch (IOException $e) {
         $this->output->writeln(sprintf('<error>Could not write a config file in Travis Configurator, error: "%s"</error>', $e->getMessage()));
         return;
     }
     $this->output->writeln("\n<info>Files for Travis integration have been written</info>");
 }
 /**
  * Asks user what the path to javascript source is.
  */
 public function configure()
 {
     if (!$this->settings['enableJsHint']) {
         return;
     }
     $baseDir = $this->settings->getBaseDir();
     $default = $this->settings->getDefaultValueFor('javaScriptSrcPath', 'src');
     $this->settings['javaScriptSrcPath'] = $this->dialog->askAndValidate($this->output, "What is the path to the JavaScript source code? [{$default}] ", function ($data) use($baseDir) {
         if (is_dir($baseDir . '/' . $data)) {
             return $data;
         }
         throw new \Exception("That path doesn't exist");
     }, false, $default);
 }
 /**
  * @param ConfiguratorInterface $configurator
  * @throws \RuntimeException
  */
 public function register(ConfiguratorInterface $configurator)
 {
     if (!$configurator instanceof ConfigurationWriterInterface) {
         parent::register($configurator);
         return;
     }
     // This really ought to be done differently... with proper DI and consistent usage of SF/Filesystem component
     // we could just write to tmp dirs and test it properly (see FilesystemTestCase in File component)
     $className = explode('\\', get_class($configurator));
     $className = end($className);
     $mockClass = "Ibuildings\\QA\\tests\\mock\\Configurator\\" . $className;
     if (!class_exists($mockClass)) {
         throw new \RuntimeException(sprintf('Configurator "%s" implements ConfigurationWriterInterface. A mock of this configurator should be' . 'made so that the writeConfig method does not write to disk but stores the contents', get_class($configurator)));
     }
     $requiresMultiplePathHelper = array('PhpMessDetectorConfigurator', 'PhpCodeSnifferConfigurator', 'PhpUnitConfigurator');
     if (in_array($className, $requiresMultiplePathHelper)) {
         $multiplePathHelper = new MultiplePathHelper($this->outputInterface, $this->dialogHelper, $this->settings->getBaseDir());
         $writingMockedConfigurator = new $mockClass($this->outputInterface, $this->dialogHelper, $multiplePathHelper, $this->settings, $this->twig);
     } elseif ($className === 'JsHintConfigurator') {
         $writingMockedConfigurator = new $mockClass($this->inputInterface, $this->outputInterface, $this->dialogHelper, $this->settings, $this->twig, $this->installJsHintCommand);
     } else {
         $writingMockedConfigurator = new $mockClass($this->outputInterface, $this->dialogHelper, $this->settings, $this->twig);
     }
     // should be resolved asap
     $this->configurators[get_class($configurator)] = $writingMockedConfigurator;
 }
Exemple #6
0
 /**
  * @throws \Exception
  * @return array
  */
 protected function parseComposerConfig()
 {
     if (!file_exists($this->settings->getBaseDir() . DIRECTORY_SEPARATOR . 'composer.json')) {
         throw new \Exception("Could not find composer.json in project root dir '" . $this->settings->getBaseDir() . "'");
     }
     $file = file_get_contents($this->settings->getBaseDir() . DIRECTORY_SEPARATOR . 'composer.json');
     $parsedFile = json_decode($file, true);
     if ($parsedFile === null) {
         throw new \Exception("Could not read composer.json. Is it valid JSON?");
     }
     $this->composerConfig = array();
     if (array_key_exists('config', $parsedFile)) {
         $this->composerConfig = $parsedFile['config'];
     }
     if (array_key_exists('bin-dir', $this->composerConfig)) {
         $this->settings['composerBinDir'] = $this->composerConfig['bin-dir'];
     } else {
         $this->settings['composerBinDir'] = 'vendor/bin';
     }
 }
 /**
  * Writes config file
  * @codeCoverageIgnore
  */
 public function writeConfig()
 {
     $filesystem = new Filesystem();
     try {
         $filesystem->dumpFile($this->settings->getBaseDir() . '/.jshintrc', $this->twig->render('.jshintrc.dist', $this->settings->getArrayCopy()));
     } catch (IOException $e) {
         $this->output->writeln(sprintf('<error>Could not write .jshintrc, error: "%s"</error>', $e->getMessage()));
         return;
     }
     $this->output->writeln("\n<info>Config file for JSHint written</info>");
 }
 /**
  * Install Behat yaml files.
  *
  * @codeCoverageIgnore
  */
 protected function writeBehatYamlFiles()
 {
     $filesystem = new FileSystem();
     try {
         $filesystem->dumpFile($this->settings->getBaseDir() . '/behat.yml', $this->twig->render('behat.yml.dist', $this->settings->getArrayCopy()));
         $filesystem->dumpFile($this->settings->getBaseDir() . '/behat.dev.yml', $this->twig->render('behat.dev.yml.dist', $this->settings->getArrayCopy()));
     } catch (IOException $e) {
         $this->output->writeln(sprintf('<error>Could not write behat config file, error: "%s"</error>', $e->getMessage()));
         return;
     }
     $this->output->writeln('Behat configuration files are written');
 }