Permalink
Browse files

Added some shitty tests for PHP-CS-Fixer 2 rule parameter composition.

  • Loading branch information...
1 parent 7edb59c commit 3e830a18b376d1a2614da9c137e7003ab9f0db9e @Bilge committed Feb 16, 2017
Showing with 62 additions and 2 deletions.
  1. +62 −2 spec/Task/PhpCsFixerV2Spec.php
@@ -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);
@@ -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'),
@@ -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.