Skip to content

Commit

Permalink
Added some shitty tests for PHP-CS-Fixer 2 rule parameter composition.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Feb 16, 2017
1 parent 7edb59c commit 3e830a1
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions spec/Task/PhpCsFixerV2Spec.php
Expand Up @@ -126,7 +126,7 @@ function it_runs_the_suite_for_changed_files(
}))->willReturn($process);

$processRunner->run(Argument::type('array'))->shouldBeCalled();
$process->isSuccessful()->willReturn(true);
$process->isSuccessful()->willReturn(true);

$result = $this->run($context);
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
Expand All @@ -147,7 +147,7 @@ function it_throws_exception_if_the_process_fails(
$processBuilder->buildProcess(Argument::type(ProcessArgumentsCollection::class))->willReturn($process);

$processRunner->run(Argument::type('array'))->shouldBeCalled();
$process->isSuccessful()->willReturn(false);
$process->isSuccessful()->willReturn(false);

$context->getFiles()->willReturn(new FilesCollection([
new SplFileInfo('file1.php', '.', 'file1.php'),
Expand All @@ -157,4 +157,64 @@ function it_throws_exception_if_the_process_fails(
$result->shouldBeAnInstanceOf(TaskResultInterface::class);
$result->isPassed()->shouldBe(false);
}

function it_composes_a_rule_list(
GrumPHP $grumPHP,
ProcessBuilder $processBuilder,
Process $process,
RunContext $context,
PhpCsFixerFormatter $formatter
)
{
$formatter->resetCounter()->shouldBeCalled();
$grumPHP->getTaskConfiguration('phpcsfixer2')->willReturn([
'config' => 'foo',
'rules' => ['foo', 'bar'],
]);
$context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file1.php', '.', 'file1.php')]));

$processBuilder->createArgumentsForCommand('php-cs-fixer')->willReturn(new ProcessArgumentsCollection);
$processBuilder->buildProcess(Argument::that(
function (ProcessArgumentsCollection $args) {
return $args->contains('--rules=foo,bar');
}
))->willReturn($process);

$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(true);

$this->run($context)->isPassed()->shouldBe(true);
}

function it_composes_a_rule_dictionary(
GrumPHP $grumPHP,
ProcessBuilder $processBuilder,
Process $process,
RunContext $context,
PhpCsFixerFormatter $formatter
)
{
$formatter->resetCounter()->shouldBeCalled();
$grumPHP->getTaskConfiguration('phpcsfixer2')->willReturn([
'config' => 'foo',
'rules' => $rules = [
'foo' => [
'bar',
],
],
]);
$context->getFiles()->willReturn(new FilesCollection([new SplFileInfo('file1.php', '.', 'file1.php')]));

$processBuilder->createArgumentsForCommand('php-cs-fixer')->willReturn(new ProcessArgumentsCollection);
$processBuilder->buildProcess(Argument::that(
function (ProcessArgumentsCollection $args) use ($rules) {
return $args->contains('--rules={"foo":["bar"]}');
}
))->willReturn($process);

$process->run()->shouldBeCalled();
$process->isSuccessful()->willReturn(true);

$this->run($context)->isPassed()->shouldBe(true);
}
}

0 comments on commit 3e830a1

Please sign in to comment.