Skip to content

Commit

Permalink
Use output mode configured in ValueGenerator instance
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Klein <thomasklein876@gmail.com>
  • Loading branch information
thomas-kl1 committed Mar 7, 2023
1 parent c1706ec commit ce6611e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
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 ce6611e

Please sign in to comment.