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 a8da9af
Showing 1 changed file with 41 additions and 0 deletions.
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 a8da9af

Please sign in to comment.