本文整理汇总了PHP中GrumPHP\Task\Context\ContextInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ContextInterface类的具体用法?PHP ContextInterface怎么用?PHP ContextInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContextInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* {@inheritdoc}
*/
public function run(ContextInterface $context)
{
$files = $context->getFiles()->name('*.php');
if (0 === count($files)) {
return;
}
// We don't care about changed files here, we want to run the entire suit every time
$config = $this->getConfiguration();
$this->processBuilder->setArguments(array($this->getCommandLocation()));
if ($config['config']) {
$this->processBuilder->add('--config=' . $config['config']);
}
if ($config['format']) {
$this->processBuilder->add('--format=' . $config['format']);
}
if ($config['suite']) {
$this->processBuilder->add('--suite=' . $config['suite']);
}
if ($config['stop_on_failure']) {
$this->processBuilder->add('--stop-on-failure');
}
$process = $this->processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new RuntimeException($process->getOutput());
}
}
示例2: run
/**
* @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);
}
示例3: run
/**
* {@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));
}
if ($config['no_local_repository'] && $this->hasLocalRepository($files->first())) {
return TaskResult::createFailed($this, $context, 'You have at least one local repository declared.');
}
return TaskResult::createPassed($this, $context);
}
示例4: run
/**
* {@inheritdoc}
*/
public function run(ContextInterface $context)
{
$files = $context->getFiles()->name('*.php');
if (0 === count($files)) {
return;
}
$config = $this->getConfiguration();
$this->processBuilder->setArguments(array($this->getCommandLocation(), '--standard=' . $config['standard']));
if (!$config['show_warnings']) {
$this->processBuilder->add('--warning-severity=0');
}
if ($config['tab_width']) {
$this->processBuilder->add('--tab-width=' . $config['tab_width']);
}
if (count($config['sniffs'])) {
$this->processBuilder->add('--sniffs=' . implode(',', $config['sniffs']));
}
if (count($config['ignore_patterns'])) {
$this->processBuilder->add('--ignore=' . implode(',', $config['ignore_patterns']));
}
foreach ($files as $file) {
$this->processBuilder->add($file);
}
$process = $this->processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new RuntimeException($process->getOutput());
}
}
示例5: LintErrorsCollection
function it_throws_exception_if_the_process_fails(JsonLinter $linter, ContextInterface $context)
{
$linter->isInstalled()->willReturn(true);
$linter->setDetectKeyConflicts(false)->shouldBeCalled();
$linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection(array(new JsonLintError(LintError::TYPE_ERROR, 0, 'error', 'file.json', 1, 1))));
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file.json', '.', 'file.json'))));
$this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
}
示例6:
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);
}
示例7: LintErrorsCollection
function it_throws_exception_if_the_process_fails(JsonLinter $linter, ContextInterface $context)
{
$linter->isInstalled()->willReturn(true);
$linter->setDetectKeyConflicts(false)->shouldBeCalled();
$linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection([new JsonLintError(LintError::TYPE_ERROR, 0, 'error', 'file.json', 1, 1)]));
$context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file.json', '.', 'file.json')]));
$result = $this->run($context);
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
$result->isPassed()->shouldBe(false);
}
示例8: FilesCollection
function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$processBuilder->setArguments(Argument::type('array'))->shouldBeCalled();
$processBuilder->getProcess()->willReturn($process);
$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(false);
$process->getOutput()->shouldBeCalled();
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('test.php'))));
$this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
}
示例9: ProcessArgumentsCollection
function it_lists_files_with_merge_conflicts(ProcessBuilder $processBuilder, ContextInterface $context, Process $process)
{
$arguments = new ProcessArgumentsCollection();
$processBuilder->createArgumentsForCommand('git')->willReturn($arguments);
$processBuilder->buildProcess($arguments)->willReturn($process);
$context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file1.php', '.', 'file1.php')]));
$result = $this->run($context);
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
$result->isPassed()->shouldBe(true);
}
示例10: array
function it_throws_exception_if_the_process_is_successfull(GrumPHP $grumPHP, LocatorInterface $externalCommandLocator, ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$this->beConstructedWith($grumPHP, array('keywords' => array('var_dump(')), $externalCommandLocator, $processBuilder);
$processBuilder->setArguments(Argument::type('array'))->shouldBeCalled();
$processBuilder->getProcess()->willReturn($process);
$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(true);
$process->getOutput()->shouldBeCalled();
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file1.php'))));
$this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
}
示例11: LintErrorsCollection
function it_throws_exception_if_the_process_fails(YamlLinter $linter, ContextInterface $context)
{
$linter->isInstalled()->willReturn(true);
$linter->setObjectSupport(false)->shouldBeCalled();
$linter->setExceptionOnInvalidType(false)->shouldBeCalled();
$linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection(array(new YamlLintError(LintError::TYPE_ERROR, 0, 'error', 'file.yaml', 1, 1))));
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file.yaml', '.', 'file.yaml'))));
$result = $this->run($context);
$result->shouldBeAnInstanceOf('GrumPHP\\Runner\\TaskResultInterface');
$result->isPassed()->shouldBe(false);
}
示例12: LintErrorsCollection
function it_throws_exception_if_the_process_fails(XmlLinter $linter, ContextInterface $context)
{
$linter->isInstalled()->willReturn(true);
$linter->setLoadFromNet(false)->shouldBeCalled();
$linter->setXInclude(false)->shouldBeCalled();
$linter->setDtdValidation(false)->shouldBeCalled();
$linter->setSchemeValidation(false)->shouldBeCalled();
$linter->lint(Argument::type('SplFileInfo'))->willReturn(new LintErrorsCollection(array(new XmlLintError(LintError::TYPE_ERROR, 0, 'error', 'file.xml', 1, 1))));
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file.xml', '.', 'file.xml'))));
$this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
}
示例13: ProcessArgumentsCollection
function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$arguments = new ProcessArgumentsCollection();
$processBuilder->createArgumentsForCommand('behat')->willReturn($arguments);
$processBuilder->buildProcess($arguments)->willReturn($process);
$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(false);
$process->getOutput()->shouldBeCalled();
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('test.php', '.', 'test.php'))));
$this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
}
示例14: ProcessArgumentsCollection
function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$arguments = new ProcessArgumentsCollection();
$processBuilder->createArgumentsForCommand('composer')->willReturn($arguments);
$processBuilder->buildProcess($arguments)->willReturn($process);
$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(false);
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('composer.json', '.', 'composer.json'))));
$result = $this->run($context);
$result->shouldBeAnInstanceOf('GrumPHP\\Runner\\TaskResultInterface');
$result->isPassed()->shouldBe(false);
}
示例15: array
function it_throws_exception_if_the_process_is_successfull(GrumPHP $grumPHP, ProcessBuilder $processBuilder, Process $process, ContextInterface $context)
{
$grumPHP->getTaskConfiguration('git_blacklist')->willReturn(array('keywords' => array('var_dump(')));
$arguments = new ProcessArgumentsCollection();
$processBuilder->createArgumentsForCommand('git')->willReturn($arguments);
$processBuilder->buildProcess($arguments)->willReturn($process);
$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(true);
$process->getOutput()->shouldBeCalled();
$context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file1.php', '.', 'file1.php'))));
$this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context);
}