Skip to content

Commit ad8b360

Browse files
authored
Merge pull request #174 from thomas-kl1/patch-1
Use output mode configured in `ValueGenerator` instance
2 parents 37757c6 + 65c0584 commit ad8b360

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,7 @@
18741874
<code>simpleArray</code>
18751875
<code>unsortedKeysArray</code>
18761876
<code>validConstantTypes</code>
1877+
<code>multipleOutputArray</code>
18771878
</PossiblyUnusedMethod>
18781879
</file>
18791880
<file src="test/Generic/Prototype/PrototypeClassFactoryTest.php">

src/Generator/ValueGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public function generate()
371371
$newType = self::TYPE_AUTO;
372372
}
373373

374-
$curValue = new self($curValue, $newType, self::OUTPUT_MULTIPLE_LINE, $this->getConstants());
374+
$curValue = new self($curValue, $newType, $this->outputMode, $this->getConstants());
375375
$curValue->setIndentation($this->indentation);
376376
}
377377
}

test/Generator/ValueGeneratorTest.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use PHPUnit\Framework\TestCase;
2020

2121
use function fopen;
22-
use function sprintf;
2322
use function str_replace;
2423

2524
#[CoversClass(ValueGenerator::class)]
@@ -498,4 +497,55 @@ public function testExceptionInvalidValue(mixed $value, string $type): void
498497
$this->expectExceptionMessage('Type "' . $type . '" is unknown or cannot be used');
499498
$valueGenerator->generate();
500499
}
500+
501+
/**
502+
* @param ValueGenerator::OUTPUT_* $outputMode
503+
*/
504+
#[DataProvider('multipleOutputArray')]
505+
public function testArrayWithOutputMode(
506+
array $array,
507+
string $type,
508+
string $outputMode,
509+
string $output
510+
): void {
511+
$valueGenerator = new ValueGenerator($array, $type, $outputMode);
512+
513+
self::assertSame($valueGenerator->generate(), $output);
514+
}
515+
516+
/**
517+
* Data provider for testArrayWithOutputMode test
518+
*/
519+
public static function multipleOutputArray(): array
520+
{
521+
$array = [
522+
'foo' => [
523+
'bar',
524+
],
525+
];
526+
527+
$singleLine = '[\'foo\' => [\'bar\']]';
528+
$multipleLine = <<<EOS
529+
[
530+
'foo' => [
531+
'bar',
532+
],
533+
]
534+
EOS;
535+
536+
return [
537+
'singleLine' => [
538+
$array,
539+
ValueGenerator::TYPE_ARRAY_SHORT,
540+
ValueGenerator::OUTPUT_SINGLE_LINE,
541+
$singleLine,
542+
],
543+
'multipleLine' => [
544+
$array,
545+
ValueGenerator::TYPE_ARRAY_SHORT,
546+
ValueGenerator::OUTPUT_MULTIPLE_LINE,
547+
$multipleLine,
548+
],
549+
];
550+
}
501551
}

0 commit comments

Comments
 (0)