function it_should_contain_the_error_messages(TasksCollection $tasks, ContextInterface $context, TaskResult $passedTaskResult, TaskResult $failedTaskResult) { $taskResults = new TaskResultCollection(); $taskResults->add($passedTaskResult->getWrappedObject()); $failedTaskResult->getMessage()->willReturn('message 1'); $taskResults->add($failedTaskResult->getWrappedObject()); $this->beConstructedWith($tasks, $context, $taskResults); $this->getMessages()->shouldReturn(array('message 1')); }
/** * @param ContextInterface $context * @return TaskResult */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } if (is_file('./vendor/bin/fixbom')) { $fixCommand = './vendor/bin/fixbom'; } elseif (is_file('./bin/fixbom')) { $fixCommand = './bin/fixbom'; } else { $fixCommand = 'fixbom'; } $shouldGetFixedLog = []; /** @var \Symfony\Component\Finder\SplFileInfo $file */ foreach ($files as $file) { $execFile = $file->getPathname(); $debugLog[] = $execFile; if ($this->isFileWithBOM($execFile)) { $shouldGetFixedLog[] = $execFile . " has BOM and should be fixed"; $fixCommand .= " '" . $execFile . "'"; } } if (count($shouldGetFixedLog) > 0) { return TaskResult::createFailed($this, $context, implode(PHP_EOL, $shouldGetFixedLog) . PHP_EOL . "you can use this to fix them:" . PHP_EOL . $fixCommand); } return TaskResult::createPassed($this, $context); }
function it_should_display_warning_of_non_blocking_failed_tasks(OutputInterface $output, TaskRunner $taskRunner, TaskInterface $task, ContextInterface $context) { $aTask = $task->getWrappedObject(); $aContext = $context->getWrappedObject(); $nonBlockingFailedTaskResult = TaskResult::createNonBlockingFailed($aTask, $aContext, 'non blocking task message'); $taskResults = new TaskResultCollection(); $taskResults->add($nonBlockingFailedTaskResult); $taskRunner->run($context)->willReturn($taskResults); $output->isDecorated()->willReturn(false); $output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_NORMAL); $output->writeln(Argument::containingString('non blocking task message'))->shouldBeCalled(); $output->writeln(Argument::any())->shouldBeCalled(); $this->run($output, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles(false)->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $this->parser->setParserOptions($config); $parseErrors = $this->parse($files); if ($parseErrors->count()) { return TaskResult::createFailed($this, $context, sprintf("Some errors occured while parsing your PHP files:\n%s", $parseErrors->__toString())); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $arguments = $this->processBuilder->createArgumentsForCommand('phpunit'); $arguments->addOptionalArgument('--configuration=%s', $config['config_file']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); $arguments = $this->processBuilder->createArgumentsForCommand('parallel-lint'); $arguments->add('--no-colors'); $arguments->addOptionalArgumentWithSeparatedValue('-j', $config['jobs']); $arguments->addArgumentArrayWithSeparatedValue('--exclude', $config['exclude']); $arguments->addFiles($files); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * @param ContextInterface|GitCommitMsgContext $context */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $commitMessage = $context->getCommitMessage(); $exceptions = []; foreach ($config['matchers'] as $rule) { try { $this->runMatcher($config, $commitMessage, $rule); } catch (RuntimeException $e) { $exceptions[] = $e->getMessage(); } } if (count($exceptions)) { return TaskResult::createFailed($this, $context, implode(PHP_EOL, $exceptions)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('npm'); $arguments->addRequiredArgument('%s', $config['script']); $process = $this->processBuilder->buildProcess($arguments); $process->setWorkingDirectory(realpath($config['working_directory'])); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('grunt'); $arguments->addOptionalArgument('--gruntfile=%s', $config['grunt_file']); $arguments->addOptionalArgument('%s', $config['task']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.json'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $this->linter->setDetectKeyConflicts($config['detect_key_conflicts']); try { $lintErrors = $this->lint($files); } catch (RuntimeException $e) { return TaskResult::createFailed($this, $context, $e->getMessage()); } if ($lintErrors->count()) { return TaskResult::createFailed($this, $context, (string) $lintErrors); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions(array('feature')); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('kawaii'); $arguments->add('gherkin:check'); $arguments->addOptionalArgument('--align=%s', $config['align']); $arguments->add($config['directory']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('doctrine'); $arguments->add('orm:validate-schema'); $arguments->addOptionalArgument('--skip-mapping', $config['skip_mapping']); $arguments->addOptionalArgument('--skip-sync', $config['skip_sync']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('php7cc'); $arguments->addOptionalArgument('--level=%s', $config['level']); $arguments->addArgumentArrayWithSeparatedValue('--except', $config['exclude']); $arguments->addFiles($files); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles(); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('git'); $arguments->add('diff'); $arguments->add('--name-only'); $arguments->add('--diff-filter=U'); $arguments->addFiles($files); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if ($process->isSuccessful()) { return TaskResult::createFailed($this, $context, sprintf('You have merge conflicts in the following files, please resolve them before you can continue%s%s', PHP_EOL, $this->formatter->format($process))); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('/\\.(yaml|yml)$/i'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $this->linter->setObjectSupport($config['object_support']); $this->linter->setExceptionOnInvalidType($config['exception_on_invalid_type']); try { $lintErrors = $this->lint($files); } catch (RuntimeException $e) { return TaskResult::createFailed($this, $context, $e->getMessage()); } if ($lintErrors->count()) { return TaskResult::createFailed($this, $context, (string) $lintErrors); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $exceptions = array(); foreach ($config['scripts'] as $script) { try { $this->runShell($script); } catch (RuntimeException $e) { $exceptions[] = $e->getMessage(); } } if (count($exceptions)) { return TaskResult::createFailed($this, $context, implode(PHP_EOL, $exceptions)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files) || empty($config['keywords'])) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('git'); $arguments->add('grep'); $arguments->add('--cached'); $arguments->add('-n'); $arguments->addArgumentArrayWithSeparatedValue('-e', $config['keywords']); $arguments->addFiles($files); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if ($process->isSuccessful()) { return TaskResult::createFailed($this, $context, sprintf('You have blacklisted keywords in your commit:%s%s', PHP_EOL, $this->formatter->format($process))); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->path(pathinfo($config['lockfile'], PATHINFO_DIRNAME))->name(pathinfo($config['lockfile'], PATHINFO_BASENAME)); if (0 === count($files) && !$config['run_always']) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('security-checker'); $arguments->add('security:check'); $arguments->addOptionalArgument('%s', $config['lockfile']); $arguments->addOptionalArgument('--format=%s', $config['format']); $arguments->addOptionalArgument('--end-point=%s', $config['end_point']); $arguments->addOptionalArgument('--timeout=%s', $config['timeout']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $arguments = $this->processBuilder->createArgumentsForCommand('phpmd'); $arguments->addCommaSeparatedFiles($files); $arguments->add('text'); $arguments->addOptionalCommaSeparatedArgument('%s', $config['ruleset']); $arguments->addOptionalArgument('--exclude', !empty($config['exclude'])); $arguments->addOptionalCommaSeparatedArgument('%s', $config['exclude']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $this->linter->setLoadFromNet($config['load_from_net']); $this->linter->setXInclude($config['x_include']); $this->linter->setDtdValidation($config['dtd_validation']); $this->linter->setSchemeValidation($config['scheme_validation']); try { $lintErrors = $this->lint($files); } catch (RuntimeException $e) { return TaskResult::createFailed($this, $context, $e->getMessage()); } if ($lintErrors->count()) { return TaskResult::createFailed($this, $context, (string) $lintErrors); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $this->formatter->resetCounter(); $arguments = $this->processBuilder->createArgumentsForCommand('php-cs-fixer'); $arguments->add('--format=json'); $arguments->addOptionalArgument('--level=%s', $config['level']); $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--config-file=%s', $config['config_file']); $arguments->addOptionalArgument('--verbose', $config['verbose']); $arguments->addOptionalCommaSeparatedArgument('--fixers=%s', $config['fixers']); $arguments->add('fix'); if ($context instanceof RunContext && $config['config_file'] !== null) { return $this->runOnAllFiles($context, $arguments); } return $this->runOnChangedFiles($context, $arguments, $files); }
/** * @param ContextInterface $context * @param ProcessArgumentsCollection $arguments * @param FilesCollection $files * * @return TaskResult */ protected function runOnChangedFiles(ContextInterface $context, ProcessArgumentsCollection $arguments, FilesCollection $files) { $hasErrors = false; $messages = array(); $suggestions = array(); foreach ($files as $file) { $fileArguments = new ProcessArgumentsCollection($arguments->getValues()); $fileArguments->add($file); $process = $this->processBuilder->buildProcess($fileArguments); $process->run(); if (!$process->isSuccessful()) { $hasErrors = true; $messages[] = $this->formatter->format($process); $suggestions[] = $this->formatter->formatSuggestion($process); } } if ($hasErrors) { $errorMessage = $this->formatter->formatErrorMessage($messages, $suggestions); return TaskResult::createFailed($this, $context, $errorMessage); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->path(pathinfo($config['file'], PATHINFO_DIRNAME))->name(pathinfo($config['file'], PATHINFO_BASENAME)); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('composer'); $arguments->add('validate'); $arguments->addOptionalArgument('--no-check-all', $config['no_check_all']); $arguments->addOptionalArgument('--no-check-lock', $config['no_check_lock']); $arguments->addOptionalArgument('--no-check-publish', $config['no_check_publish']); $arguments->addOptionalArgument('--with-dependencies', $config['with_dependencies']); $arguments->addOptionalArgument('--strict', $config['strict']); $arguments->addOptionalArgument('%s', $config['file']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $arguments = $this->processBuilder->createArgumentsForCommand('atoum'); $arguments->addOptionalArgumentWithSeparatedValue('-c', $config['config_file']); $arguments->addOptionalArgumentWithSeparatedValue('--bootstrap-file', $config['bootstrap_file']); $arguments->addSeparatedArgumentArray('--directories', $config['directories']); $arguments->addSeparatedArgumentArray('--files', $config['files']); $arguments->addSeparatedArgumentArray('--namespaces', $config['namespaces']); $arguments->addSeparatedArgumentArray('--methods', $config['methods']); $arguments->addSeparatedArgumentArray('--tags', $config['tags']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $arguments = $this->processBuilder->createArgumentsForCommand('phpcs'); $arguments->addOptionalArgument('--standard=%s', $config['standard']); $arguments->addOptionalArgument('--warning-severity=0', !$config['show_warnings']); $arguments->addOptionalArgument('--tab-width=%s', $config['tab_width']); $arguments->addOptionalArgument('--encoding=%s', $config['encoding']); $arguments->addOptionalCommaSeparatedArgument('--sniffs=%s', $config['sniffs']); $arguments->addOptionalCommaSeparatedArgument('--ignore=%s', $config['ignore_patterns']); $arguments->addFiles($files); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $config = $this->getConfiguration(); $files = $context->getFiles()->extensions($config['triggered_by']); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('phpcpd'); $extensions = array_map(function ($extension) { return sprintf('*.%s', $extension); }, $config['triggered_by']); $arguments->addArgumentArray('--exclude=%s', $config['exclude']); $arguments->addRequiredArgument('--min-lines=%u', $config['min_lines']); $arguments->addRequiredArgument('--min-tokens=%u', $config['min_tokens']); $arguments->addOptionalCommaSeparatedArgument('--names=%s', $extensions); $arguments->addOptionalArgument('--fuzzy', $config['fuzzy']); $arguments->add($config['directory']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { return TaskResult::createFailed($this, $context, $this->formatter->format($process)); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $config = $this->getConfiguration(); $this->formatter->resetCounter(); $arguments = $this->processBuilder->createArgumentsForCommand('php-cs-fixer'); $arguments->add('--format=json'); $arguments->add('--dry-run'); $arguments->addOptionalArgument('--allow-risky=%s', $config['allow_risky']); $arguments->addOptionalArgument('--cache-file=%s', $config['cache_file']); $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--rules=%s', $config['rules']); $arguments->addOptionalArgument('--using-cache=%s', $config['using_cache']); $arguments->addOptionalArgument('--path-mode=%s', $config['path_mode']); $arguments->addOptionalArgument('--verbose', $config['verbose']); $arguments->add('fix'); if ($context instanceof RunContext && $config['config'] !== null) { return $this->runOnAllFiles($context, $arguments); } return $this->runOnChangedFiles($context, $arguments, $files); }
function it_has_failed_if_it_contains_failed_task_result(TaskInterface $task, ContextInterface $context) { $aTask = $task->getWrappedObject(); $aContext = $context->getWrappedObject(); $this->add(TaskResult::createPassed($aTask, $aContext)); $this->add(TaskResult::createNonBlockingFailed($aTask, $aContext, 'non blocking')); $this->isFailed()->shouldReturn(false); $this->add(TaskResult::createFailed($aTask, $aContext, 'failed message')); $this->isFailed()->shouldReturn(true); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $configuration = $this->getConfiguration(); $percentage = round(min(100, max(0, (double) $configuration['level'])), 2); $cloverFile = $configuration['clover_file']; if (!$this->filesystem->exists($cloverFile)) { return TaskResult::createFailed($this, $context, 'Invalid input file provided'); } if (!$percentage) { return TaskResult::createFailed($this, $context, 'An integer checked percentage must be given as second parameter'); } $xml = new SimpleXMLElement($this->filesystem->readFromFileInfo(new SplFileInfo($cloverFile))); $totalElements = (string) current($xml->xpath('/coverage/project/metrics/@elements')); $checkedElements = (string) current($xml->xpath('/coverage/project/metrics/@coveredelements')); $coverage = round($checkedElements / $totalElements * 100, 2); if ($coverage < $percentage) { $message = sprintf('Code coverage is %1$d%%, which is below the accepted %2$d%%' . PHP_EOL, $coverage, $percentage); return TaskResult::createFailed($this, $context, $message); } return TaskResult::createPassed($this, $context); }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { /** @var array $config */ $config = $this->getConfiguration(); /** @var array $whitelistPatterns */ $whitelistPatterns = $config['whitelist_patterns']; /** @var array $extensions */ $extensions = $config['triggered_by']; /** @var \GrumPHP\Collection\FilesCollection $files */ $files = $context->getFiles(); if (0 !== count($whitelistPatterns)) { $files = $files->paths($whitelistPatterns); } $files = $files->extensions($extensions); if (0 === count($files)) { return TaskResult::createSkipped($this, $context); } $arguments = $this->processBuilder->createArgumentsForCommand('phpcs'); $arguments = $this->addArgumentsFromConfig($arguments, $config); $arguments->add('--report-full'); $arguments->add('--report-json'); $arguments->addFiles($files); $process = $this->processBuilder->buildProcess($arguments); $process->run(); if (!$process->isSuccessful()) { $output = $this->formatter->format($process); try { $arguments = $this->processBuilder->createArgumentsForCommand('phpcbf'); $arguments = $this->addArgumentsFromConfig($arguments, $config); $output .= $this->formatter->formatErrorMessage($arguments, $this->processBuilder); } catch (RuntimeException $exception) { // phpcbf could not get found. $output .= PHP_EOL . 'Info: phpcbf could not get found. Please consider to install it for suggestions.'; } return TaskResult::createFailed($this, $context, $output); } return TaskResult::createPassed($this, $context); }