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
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,
+ ],
+ ];
+ }
}