From ce6611e533a79f2b34bdc33e270eea8e04f18933 Mon Sep 17 00:00:00 2001 From: Thomas Klein Date: Sun, 5 Mar 2023 21:11:14 +0100 Subject: [PATCH 1/2] Use output mode configured in ValueGenerator instance Signed-off-by: Thomas Klein --- src/Generator/ValueGenerator.php | 2 +- test/Generator/ValueGeneratorTest.php | 52 ++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Generator/ValueGenerator.php b/src/Generator/ValueGenerator.php index 2d12a1f6..eb389474 100644 --- a/src/Generator/ValueGenerator.php +++ b/src/Generator/ValueGenerator.php @@ -371,7 +371,7 @@ public function generate() $newType = self::TYPE_AUTO; } - $curValue = new self($curValue, $newType, self::OUTPUT_MULTIPLE_LINE, $this->getConstants()); + $curValue = new self($curValue, $newType, $this->outputMode, $this->getConstants()); $curValue->setIndentation($this->indentation); } } diff --git a/test/Generator/ValueGeneratorTest.php b/test/Generator/ValueGeneratorTest.php index 2486c8ec..2b0d9a9f 100644 --- a/test/Generator/ValueGeneratorTest.php +++ b/test/Generator/ValueGeneratorTest.php @@ -19,7 +19,6 @@ use PHPUnit\Framework\TestCase; use function fopen; -use function sprintf; use function str_replace; #[CoversClass(ValueGenerator::class)] @@ -498,4 +497,55 @@ public function testExceptionInvalidValue(mixed $value, string $type): void $this->expectExceptionMessage('Type "' . $type . '" is unknown or cannot be used'); $valueGenerator->generate(); } + + /** + * @param ValueGenerator::OUTPUT_* $outputMode + */ + #[DataProvider('multipleOutputArray')] + public function testArrayWithOutputMode( + array $array, + string $type, + string $outputMode, + string $output + ): void { + $valueGenerator = new ValueGenerator($array, $type, $outputMode); + + self::assertSame($valueGenerator->generate(), $output); + } + + /** + * Data provider for testArrayWithOutputMode test + */ + public static function multipleOutputArray(): array + { + $array = [ + 'foo' => [ + 'bar', + ], + ]; + + $singleLine = '[\'foo\' => [\'bar\']]'; + $multipleLine = << [ + 'bar', + ], +] +EOS; + + return [ + 'singleLine' => [ + $array, + ValueGenerator::TYPE_ARRAY_SHORT, + ValueGenerator::OUTPUT_SINGLE_LINE, + $singleLine, + ], + 'multipleLine' => [ + $array, + ValueGenerator::TYPE_ARRAY_SHORT, + ValueGenerator::OUTPUT_MULTIPLE_LINE, + $multipleLine, + ], + ]; + } } From 65c0584bc1eaaf3658da2b917536a2fe0d74807d Mon Sep 17 00:00:00 2001 From: Thomas Klein Date: Wed, 8 Mar 2023 12:44:40 +0100 Subject: [PATCH 2/2] Fix psalm warning Signed-off-by: Thomas Klein --- psalm-baseline.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e7d42e5b..8c7a5ab4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1874,6 +1874,7 @@ simpleArray unsortedKeysArray validConstantTypes + multipleOutputArray