From a8da9afe6685119335e01845f2f3d08df9a8ae46 Mon Sep 17 00:00:00 2001 From: aegypius Date: Sun, 7 Jan 2024 07:28:29 +0000 Subject: [PATCH] test(parametervalidator): add tests for value extractor --- .../Tests/ParameterValueExtractorTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/ParameterValidator/Tests/ParameterValueExtractorTest.php b/src/ParameterValidator/Tests/ParameterValueExtractorTest.php index 310c80c432..a2e22e7b9b 100644 --- a/src/ParameterValidator/Tests/ParameterValueExtractorTest.php +++ b/src/ParameterValidator/Tests/ParameterValueExtractorTest.php @@ -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 + */ + 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', + ]; + } }