Skip to content

Commit

Permalink
test(parametervalidator): add tests for value extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
aegypius committed Jan 7, 2024
1 parent b70b5b6 commit 8ec5dcb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ParameterValidator/ParameterValueExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function getSeparator(string $collectionFormat): string
return match ($collectionFormat) {
'csv' => ',',
'ssv' => ' ',
'tsv' => '\t',
'tsv' => "\t",
'pipes' => '|',
default => throw new \InvalidArgumentException(sprintf('Unknown collection format %s', $collectionFormat)),
};

Check warning on line 52 in src/ParameterValidator/ParameterValueExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/ParameterValidator/ParameterValueExtractor.php#L46-L52

Added lines #L46 - L52 were not covered by tests
Expand Down
41 changes: 41 additions & 0 deletions src/ParameterValidator/Tests/ParameterValueExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,45 @@ public function provideGetSeparatorCases(): iterable
];
}
}

/**
* @dataProvider provideGetValueCases
*
* @param int[]|string[] $expectedValue
* @param int|int[]|string|string[] $value
*/
public function testGetValue(array $expectedValue, int|string|array $value, string $collectionFormat): void
{
self::assertSame($expectedValue, ParameterValueExtractor::getValue($value, $collectionFormat));
}

/**
* @return iterable<array{int[]|string[], int|string|int[]|string[], string}>
*/
public function provideGetValueCases(): iterable
{
yield 'empty input' => [
[], [], 'csv',
];

yield 'comma separated value' => [
['foo', 'bar'], 'foo,bar', 'csv',
];

yield 'space separated value' => [
['foo', 'bar'], 'foo bar', 'ssv',
];

yield 'tab separated value' => [
['foo', 'bar'], "foo\tbar", 'tsv',
];

yield 'pipe separated value' => [
['foo', 'bar'], 'foo|bar', 'pipes',
];

yield 'array values' => [
['foo', 'bar'], ['foo', 'bar'], 'csv',
];
}
}

0 comments on commit 8ec5dcb

Please sign in to comment.