Skip to content

Commit

Permalink
Wrap array_unique() with array_values() to ensure keys are always fro…
Browse files Browse the repository at this point in the history
…m zero and incremented, to not break JSON (#714)
  • Loading branch information
maks-rafalko committed Jun 24, 2019
1 parent f521704 commit 2bc4a53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Config/ValueProvider/ExcludeDirsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static function (string $dir) use ($sourceDirs) {
}
}

return array_unique($excludedDirs);
return array_values(array_unique($excludedDirs));
}

private function getValidator(Locator $locator)
Expand Down
24 changes: 24 additions & 0 deletions tests/Config/ValueProvider/ExcludeDirsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ public function test_passes_when_correct_dir_typed(): void
$this->assertContains('foo', $excludeDirs);
}

public function test_returns_an_array_with_incremented_keys_started_from_zero(): void
{
if (!$this->hasSttyAvailable()) {
$this->markTestSkipped('Stty is not available');
}

$dirA = $this->workspace . \DIRECTORY_SEPARATOR . 'a' . \DIRECTORY_SEPARATOR;
$dirB = $this->workspace . \DIRECTORY_SEPARATOR . 'b' . \DIRECTORY_SEPARATOR;
$dirC = $this->workspace . \DIRECTORY_SEPARATOR . 'c' . \DIRECTORY_SEPARATOR;

\mkdir($dirA);
\mkdir($dirB);
\mkdir($dirC);

$excludeDirs = $this->provider->get(
$this->createStreamableInputInterfaceMock($this->getInputStream("$dirA\n$dirA\n$dirC\n")),
$this->createOutputInterface(),
[$dirA, $dirB, $dirC],
['.']
);

$this->assertSame([0 => $dirA, 1 => $dirC], $excludeDirs);
}

public function excludeDirsProvider()
{
return array_map(
Expand Down

0 comments on commit 2bc4a53

Please sign in to comment.