Skip to content

Commit

Permalink
Merge pull request #609 from veewee/fix-php-cs-fixer-type-error
Browse files Browse the repository at this point in the history
Bugfix: convert splFileInfo to string
  • Loading branch information
veewee authored Mar 8, 2019
2 parents 878219f + eee1fc9 commit 7a0ec3e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
10 changes: 10 additions & 0 deletions spec/Collection/ProcessArgumentsCollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ function it_should_be_able_to_add_required_argument()
$this->getValues()->shouldBe(['--argument=value']);
}

function it_should_be_able_to_add_file()
{
$file = new SplFileInfo('file1.txt');
$this->addFile($file);

$this->getValues()->shouldBe([
'file1.txt',
]);
}

function it_should_be_able_to_add_files()
{
$files = new FilesCollection([
Expand Down
2 changes: 1 addition & 1 deletion spec/Task/PhpCsFixerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function it_runs_the_suite_for_changed_files(

$processBuilder->createArgumentsForCommand('php-cs-fixer')->willReturn(new ProcessArgumentsCollection());
$processBuilder->buildProcess(Argument::that(function (ProcessArgumentsCollection $args) use ($file1, $file2) {
return $args->contains($file1) || $args->contains($file2);
return $args->contains($file1->getPathname()) || $args->contains($file2->getPathname());
}))->willReturn($process);

$processRunner->run(Argument::type('array'))->shouldBeCalled();
Expand Down
7 changes: 6 additions & 1 deletion src/Collection/ProcessArgumentsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ public function addRequiredArgument(string $argument, string $value)
public function addFiles(FilesCollection $files)
{
foreach ($files as $file) {
$this->add($file->getPathname());
$this->addFile($file);
}
}

public function addFile(\SplFileInfo $file)
{
$this->add($file->getPathname());
}

public function addCommaSeparatedFiles(FilesCollection $files)
{
$paths = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function fromArguments(ProcessArgumentsCollection $arguments): Pro
// @todo Remove backward compatibility layer as soon as Symfony Process accepts an array (3.3+).
// From then on, you can simply pass `$arguments->getValues()` directly as the first constructor argument.
$commandlineArgs = array_map(function ($argument) {
return ProcessUtils::escapeArgument($argument);
return ProcessUtils::escapeArgument((string) $argument);
}, $arguments->getValues());

$commandline = implode(' ', $commandlineArgs);
Expand Down
2 changes: 1 addition & 1 deletion src/Task/AbstractPhpCsFixerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function runOnChangedFiles(

foreach ($files as $file) {
$fileArguments = new ProcessArgumentsCollection($arguments->getValues());
$fileArguments->add($file);
$fileArguments->addFile($file);
$processes[] = $this->processBuilder->buildProcess($fileArguments);
}

Expand Down

0 comments on commit 7a0ec3e

Please sign in to comment.