Skip to content

Commit

Permalink
Merge pull request #174 from thomas-kl1/patch-1
Browse files Browse the repository at this point in the history
Use output mode configured in `ValueGenerator` instance
  • Loading branch information
Ocramius authored Mar 8, 2023
2 parents 37757c6 + 65c0584 commit ad8b360
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@
<code>simpleArray</code>
<code>unsortedKeysArray</code>
<code>validConstantTypes</code>
<code>multipleOutputArray</code>
</PossiblyUnusedMethod>
</file>
<file src="test/Generic/Prototype/PrototypeClassFactoryTest.php">
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/ValueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
52 changes: 51 additions & 1 deletion test/Generator/ValueGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use PHPUnit\Framework\TestCase;

use function fopen;
use function sprintf;
use function str_replace;

#[CoversClass(ValueGenerator::class)]
Expand Down Expand Up @@ -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 = <<<EOS
[
'foo' => [
'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,
],
];
}
}

0 comments on commit ad8b360

Please sign in to comment.